Traditional Culture Encyclopedia - Weather inquiry - How to set up automatic reply of weather forecast on WeChat public platform in development mode?

How to set up automatic reply of weather forecast on WeChat public platform in development mode?

Automatic reply mode of weather forecast under the development mode of WeChat public platform setting;

1, API address of weather interface, there are many on the Internet. The following introduces a product above Baidu map API to realize weather query function. First, you need to register a Baidu account, and then log in to Baidu's LBS development platform to find the car networking API. The address is as follows:

2. After entering the car networking page, you can see many API interfaces.

3. Next, click "Get Key" to copy and save your own access key, which is ak.

4. Then click "Interface Description" and select "Weather Query".

5. You can read the interface description document. Through the document, we can know that it can return the weather forecast according to the keywords and latitude and longitude sent by the user. Therefore, local WeChat can set users to reply to the weather forecast directly when sending keywords including cities.

6, more geographical location and keywords return to query the code of today's weather is as follows:

Case "location";

$ weather URL = "/telematics/v2/weather? Location = {$ longitude}, {$ latitude} & ampak =1A3CDE429F38434f181A75e1A903/kloc ";

$ API str = file _ get _ contents($ weather URL);

$ API obj = SimpleXML _ load _ string($ API str);

$ place obj = $ API obj-& gt; CurrentCity// Read the city

$ todayobj = $ API obj-& gt; Results-> Results [0]-> Date; //Read the week

$ weather obj = $ API obj-& gt; Results-> Results [0]-> Weather; //Read the weather forecast

$ wind obj = $ API obj-& gt; Results-> Results [0]-> Wind; //Read the wind force

$ tem obj = $ API obj-& gt; Results-> Results [0]-> Temperature; //Read temperature

$ contentstr = "{$ placeobj} {$ todayobj} weather {$weatherobj}, wind {$windobj}, temperature {$ temobj} ";;

Break;

Case "text";

$ weather URL = "/telematics/v2/weather? location = { $ keyword } & ampAK = 1 a3 CDE 429 f 38434 f 18 1 1a 75 e 1a 903 10c ";

$ API str = file _ get _ contents($ weather URL);

$ API obj = SimpleXML _ load _ string($ API str);

$ place obj = $ API obj-& gt; CurrentCity// Read the city

$ todayobj = $ API obj-& gt; Results-> Results [0]-> Date; //Read the week

$ weather obj = $ API obj-& gt; Results-> Results [0]-> Weather; //Read the weather forecast

$ wind obj = $ API obj-& gt; Results-> Results [0]-> Wind; //Read the wind force

$ tem obj = $ API obj-& gt; Results-> Results [0]-> Temperature; //Read temperature

$ contentstr = "{$ placeobj} {$ todayobj} weather {$weatherobj}, wind {$windobj}, temperature {$ temobj} ";;

? Break;

7. After the mobile phone logs in to WeChat, the results of replying the geographic location and city information are as follows: