php WeChat public account development php implements custom keyword reply

高洛峰
Release: 2017-02-20 14:57:13
Original
2496 people have browsed it

This article mainly introduces the fourth lesson of php WeChat public account development. PHP implements simple WeChat text communication, which has certain reference value. Interested friends can refer to it

We know that WeChat The development of public accounts is divided into subscription accounts and service accounts, and individuals can only apply for subscription accounts. Subscription accounts cannot set menus and can only be implemented through keyword replies. For example, if I reply to help, help information will be returned. If I reply to the movie Huo Yuan A, just return the detailed link to Fearless's movie. These are keyword replies and are implemented in a specific format.

Create a new table, such as the t_type table, to input keywords and return specific text. Here, select the development mode. In order not to change the code every time, we write the keywords and return values ​​into the data table. , set the three fields of table fields id, type, and value.

We got the text input value $keyword in the previous section. Now we use this keyword to go to the database table t_type and query the input value. We can implement some simple and specific return functions such as keywords and return values.

For example, enter help to return help information, enter translation I love you, and it will be translated. Enter mobile phone 18200000000 to return the home address. For text that can be returned directly, store the value, such as help information. If you translate this What needs to be processed is that the database stores the fanyi value and the mobile phone 1820000000 stores the shouji. So how to process it? Look at these codes

$str2 = mb_substr($keyword,0,2,'utf-8');//前两个字符
$sql = "select value from t_type where type='$keyword' or type='$str2' limit 1";
  $res = mysql_query($sql);
  $rs = mysql_fetch_array($res);
if(!empty($rs)){
  switch($rs[0]){
    case "shouji":
//查询功能
break;

}
}else{
//数据库没有查到进行处理
}
Copy after login

This way you can enter the mobile phone + number Querying the location and translation are similar to the implementation. To add functions, you only need to set keywords and values ​​​​through the database.

In this way, basically all functions can be classified and implemented, such as common inquiries about ID card ownership, IP address inquiries, movies, etc., which can be implemented. We will talk about it after class.

The above is the entire content of this article. I hope it will be helpful to everyone's learning. I also hope that everyone will support the PHP Chinese website.

For more php WeChat public account development and php implementation of custom keyword reply related articles, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!