Home >WeChat Applet >WeChat Development >php WeChat public account development (4) php implements custom keyword reply
We know that WeChat public accounts are developed 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 Fearless, I will return detailed links to the Fearless 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 deal with 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{ //数据库没有查到进行处理 }
This way you can enter the mobile phone + number to query the location. The translation is similar to the implementation. You need to add functions. You only need to set keywords and values through the database to achieve it.
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 PHP WeChat public account development (4) PHP implements custom keyword reply content. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!