The previous articles have briefly explained the opening and simple use of the WeChat public platform Introduction, but they do not involve problems in actual use, such as weather query, bus query, express delivery query, etc. The next few articles will develop and explain some functions that are often used in real life for readers' reference.
This article will develop weather queries that everyone cares about every day. For example, if a user sends a message "Suzhou Weather", the real-time weather conditions in Suzhou will be returned, as well as the next two days or even the next five days. weather conditions.
First of all, we need to judge the message sent by the user to determine whether the message contains the "weather" key If it contains, you need to continue to extract regional information, and then query the relevant regional weather through the open API provided by China Weather Network (http://www.weather.com.cn).
The format of the message sent by the user to inquire about the weather is fixed, that is, “ Region + weather", so first intercept the last two words to determine whether they are the "weather" keyword.
Use the PHP function mb_substr() to intercept. About the usage of this function:
43df332982bc0a7cac7e19691df54232Regarding the city correspondence file weather_cityId.php, it has been updated to more than 400 cities and will continue to be added in the future. Please go to QQ group 213260412 to download it.
Please followZhuojin Suzhou WeChat public account, < span Zhuojin Suzhou is developed based on the SAE platform and is developed and tested for mainstream WeChat functions.
You can follow the Zhuojin Suzhou public account to conduct functional testing and obtain new application development.
1. Log in to the WeChat client, friends -> Add friends -> Search number -> zhuojinsz, find and follow.
2. Scan the QR code:
Zhuojin Suzhou Function list.
The above is the content of WeChat public platform development (5) Weather forecast function development_PHP tutorial. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!