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?
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:
- Previous article:Writing background of climbing Mount Tai
- Next article:Who knows the weather in Chengdu every day in August?
- Related articles
- Weather forecast in Wuzhen, Zhejiang Province
- What is the basic state of the environment in China?
- Say goodbye to the past and welcome the future.
- Why is colored paper coated with salt water, when the color is light, the weather is sunny, and when the color is dark, the weather is cloudy?
- Write some sentences about the weather and mood.
- What is the difference between Shandong Coal Industry Bureau and Shandong Coal Mine Safety Supervision Bureau?
- Which travel agency is best for traveling to Yunnan?
- How to pronounce Phoenix Danzong?
- Chinese in the sixth grade of primary school
- It is said that Cancer's mood is like the weather, sunny and cloudy with occasional rain. Is it true?/You don't say.