Weather forecast has been a basic function of the major sites, the recent small series also want to make one on the site, a little bit, in the network search for a long time, finally found the open source free weather API and all regional code (National Weather Bureau), as follows:
Weather interface provided by the National Weather
- Http://www.weather.com.cn/data/sk/101010100.html
- Http://www.weather.com.cn/data/cityinfo/101010100.html
- Http://m.weather.com.cn/data/101010100.html
Number of the city
101010100 indicates the number of each city, number code get get address
- Get Provincial code: http://www.weather.com.cn/data/list3/city.xml?level=1
- Get city code (e.g. Anhui is): http://www.weather.com.cn/data/list3/city22.xml?level=2
- Get area code (e.g. Anqing is 2206): http://www.weather.com.cn/data/list3/city2206.xml?level=3
Get to Anhui province Anqing Wangjiang County code is 220607
- Then add the Chinese code to request url:http://m.weather.com.cn/data/101220607.html to get local weather.
Image interface
The data returned by using the API above contains a picture name that can be accessed through the address
- Http://m.weather.com.cn/img/c0.gif
- Http://m.weather.com.cn/img/b0.gif
- Http://www.weather.com.cn/m/i/weatherpic/29x20/d0.gif
- http://www.weather.com.cn/m2/i/icon_weather/29x20/n00.gif
This is a picture of weather phenomena 0 (clear), pictures of other weather phenomena and so on. c The picture is 20*20 pixels, B starts with 50*46 pixels, D is the anti-white icon, 29*20 pixels, N is the night anti-white icon, 29*20 pixels, note that the filename here is two digits!
Parsing data
The weather report interface provided by the National Weather Service returns JSON data, and if PHP can be converted to an array using Json_decode (), iterate through the arrays to remove the data.
Open source free weather forecast Interface API and all country code (National Weather Bureau provided)