常用天氣預報API接口整理(轉)


文章轉自:http://www.nohacks.cn/post-35.html

 

 

自序:

由nohacks.cn 收集整理,來源於網絡,版權歸原作者所有,基本收集了網絡上能使用的大部分天氣API接口,作者水平精力有限,難免有遺漏或錯誤的地方,歡迎反饋,作者網站:http://nohacks.cn

 

更新記錄:

         2015.3.2    更新雲聚,增加天氣網接口。

         2015.2.28  增加百度天氣圖片,感謝網友彬子的反饋。

         2015. 2.19 增加百度天氣接口,更新中國天氣網API。

 

目錄:

1.  中國天氣網

     1.1  實時天氣 API 接口(失效)

     1.2  當天天氣 API接口(失效)

     1.3 生活指數 API接口(失效)

     1.4 未來五天天氣 API 接口(有效,不穩定)

2.   開放數據網天氣

      2.1 簡介

      2.2. 一天天氣 API 接口

      2.3 未來五天天氣 API 接口
      

3.   中國天氣&開放數據 綜合版

    3.1  實時天氣

   3.2  當天天氣

   3.3 未來五天

   3.4 生活指數

4.  隨身雲天氣API (推薦)

    4.1 簡介

    4.1  簡化版 未來6天天氣 API接口

     4.2   詳細版 未來6天 天氣API接口

5. 新浪天氣(推薦

     5. 1  簡介

     5.2   使用方法

     5.3   天氣標志

6. 微雲

7. 百度 API

   7.1 獲取天氣

   7.2 獲取城市列表

 8. 天氣網 (網頁插件型)

      8.1  簡介

      8.2 智能未來五天天氣

 

 前言:

 1. 城市代碼

現在網絡上流傳的天氣API實際上大多最終調用的是中國天氣網的數據,而中國天氣網是把每個地方分配了一個代碼,這個代碼就是城市代碼,要獲取天氣,我們需要知道城市代碼,有2種方法:

   1.1 手動查詢  

       進入 http://www.weather.com.cn

       在搜索框上輸入你要需要獲得天氣的城市,點擊查詢,即可在地址欄獲得相應城市編號,示范:北京的地方代碼:101010100

 

   1.2 自動查詢

         1.2.1  通過百度API

           http://apistore.baidu.com/microservice/cityinfo?cityname=%e5%8c%97%e4%ba%ac

 

            注意:  "%e5%8c%97%e4%ba%ac"是"北京"的URL編碼(UniCode)

 返回格式(UniCode):

{
    "errNum": 0,
    "retMsg": "success",
    "retData": {
        "cityName": "北京",
        "provinceName": "北京",
        "cityCode": "101010100",
        "zipCode": "100000",
        "telAreaCode": "010"
    }
 }

 

 很明顯,cityCode的值 "101010100"就是城市代碼。

 

2. 天氣標志圖片

    網絡上流傳的一些很好用的免費API卻沒有提供天氣標志圖片,對有此需求的人里說,不得不說是個遺憾,為了彌補這個遺憾,不得不借助第三方平台配合使用,目前作者使用的是新浪天氣平台的數據:

 把天氣API獲取到的天氣標志轉換為拼音,比如“多雲”,轉換為拼音“duoyun“,然后根據下面的規則轉換為圖片地址:

 

2.1 新浪圖片

小圖(78*78):  

白天: http://php.weather.sina.com.cn/images/yb3/78_78/duoyun_0.png

 

夜間: http://php.weather.sina.com.cn/images/yb3/78_78/duoyun_1.png

大圖180*180

白天:http://php.weather.sina.com.cn/images/yb3/180_180/duoyun_0.png

 夜間:http://php.weather.sina.com.cn/images/yb3/180_180/duoyun_1.png 正文:

 

 2.2 百度天氣圖片

 

   目前知道的小圖,感謝網友彬子的反饋

                    

     多雲(白天)          多雲(夜間)

白天: http://api.map.baidu.com/images/weather/day/duoyun.png
夜間: http://api.map.baidu.com/images/weather/night/duoyun.png

 

 

第一節: 中國天氣網

1.1 簡介

 

中國最權威的天氣預報網絡平台,很多平台實際上也是用的他們的數據。

官方網站:http://www.weather.com.cn

 

1.2  地方代碼獲取方法

        前文已經提過

 

1.3  實時天氣接口


         接口示例:  http://www.weather.com.cn/data/sk/101010100.html  失效

 

     返回格式:

 

    {"weatherinfo":{"city":"北京","cityid":"101010100","temp":"23","WD":"東風","WS":"2級","SD":"92%","WSE":"2","time":"09:55","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB"}}

   

      說明:其中 city 是地方名稱,cityid是地方代碼,temp是當前溫度,"WD"是風向,“WS"是風速”,“SD"是濕度,time是更新時間。

 

    1.4 獲取當天天氣:

        http://www.weather.com.cn/data/cityinfo/101010100.html  失效

 

   返回格式:

 

      weatherinfo":{"city":"北京","cityid":"101010100","temp1":"29℃","temp2":"24℃","weather":"陰轉晴","img1":"d2.gif","img2":"n0.gif","ptime":"08:00"}}

  

       注意:其中 img1和img2是天氣標志圖片,接口格式如下:

                 http://m.weather.com.cn/img/c0.gif
                 http://m.weather.com.cn/img/b0.gif
          這個圖就是天氣現象0(晴)的圖片,其他天氣現象的圖片依此類推。c打頭的圖片是20*20像素的,b打頭的是50*46像素的,d打頭的是反白的圖標,  29*20像素,n打頭的是夜間反白圖標,29*20像素,注意這里的文件名是兩位數字!

 

 

  1.5  生活指數:

        http://www.weather.com.cn/data/zs/101010100.html  失效

      返回格式: 文字較多,這里省略,請點擊訪問。

 

   1.6 獲取未來幾天天氣(有效,不保證穩定)

      http://m.weather.com.cn/atad/101010100.html

 

   圖片路徑:

    http://i.tq121.com.cn/i/mobile/images/d00.png

    替換方法同上

返回示例:

{"weatherinfo":{"city":"北京","city_en":"beijing","date_y":"2015年2月19日","date":"","week":"星期四","fchh":"18","cityid":"101010100","temp1":"-2℃~4℃","temp2":"-1℃~8℃","temp3":"-3℃~5℃","temp4":"-4℃~6℃","temp5":"-3℃~7℃","temp6":"-1℃~6℃","tempF1":"28.4℉~39.2℉","tempF2":"30.2℉~46.4℉","tempF3":"26.6℉~41℉","tempF4":"24.8℉~42.8℉","tempF5":"26.6℉~44.6℉","tempF6":"30.2℉~42.8℉","weather1":"小雪轉雨夾雪","weather2":"小雪轉陰","weather3":"晴","weather4":"晴","weather5":"晴","weather6":"陰","img1":"14","img2":"6","img3":"14","img4":"2","img5":"0","img6":"99","img7":"0","img8":"99","img9":"0","img10":"99","img11":"2","img12":"99","img_single":"6","img_title1":"小雪","img_title2":"雨夾雪","img_title3":"小雪","img_title4":"陰","img_title5":"晴","img_title6":"晴","img_title7":"晴","img_title8":"晴","img_title9":"晴","img_title10":"晴","img_title11":"陰","img_title12":"陰","img_title_single":"雨夾雪","wind1":"微風","wind2":"微風轉北風4-5級","wind3":"北風4-5級轉3-4級","wind4":"北風3-4級轉微風","wind5":"微風","wind6":"微風轉北風3-4級","fx1":"微風","fx2":"微風","fl1":"小於3級","fl2":"小於3級轉4-5級","fl3":"4-5級轉3-4級","fl4":"3-4級轉小於3級","fl5":"小於3級","fl6":"小於3級轉3-4級","index":"冷","index_d":"天氣冷,建議着棉服、羽絨服、皮夾克加羊毛衫等冬季服裝。年老體弱者宜着厚棉衣、冬大衣或厚羽絨服。","index48":"","index48_d":"","index_uv":"最弱","index48_uv":"","index_xc":"不宜","index_tr":"適宜","index_co":"較不舒適","st1":"4","st2":"-4","st3":"8","st4":"-2","st5":"5","st6":"-3","index_cl":"較不宜","index_ls":"不宜","index_ag":"極不易發"}}

 

 

2. 開放數據 - k780數據

    2.1 簡介

       官方網站:http://www.k780.com

       說明: 數據來自國家氣象局天氣網,每小時更新一次    

       免費版有每小時點擊次數的限制(免費版最多每小時720次查詢)

 

     2.2   獲取今日天氣

             詳細說明:  http://www.k780.com/api/weather.today

 

返回實例:

 

 <?xml version="1.0" encoding="utf-8" ?>

-  <root>
  <success>1</success>
-  <result>
  <weaid>1</weaid>
  <days>2014-07-30</days>
  <week>星期三</week>
  <cityno>beijing</cityno>
  <citynm>北京</citynm>
  <cityid>101010100</cityid>
  <temperature>29℃/24℃</temperature>
  <humidity>84.2℉/75.2℉</humidity>
  <weather>陰轉晴</weather>
  <weather_icon>http://api.k780.com:88/upload/weather/d/2.gif</weather_icon>
  <weather_icon1>http://api.k780.com:88/upload/weather/d/0.gif</weather_icon1>
  <wind>微風</wind>
  <winp>小於3級</winp>
  <temp_high>29</temp_high>
  <temp_low>24</temp_low>
  <humi_high>84.2</humi_high>
  <humi_low>75.2</humi_low>
  <weatid>3</weatid>
  <weatid1>1</weatid1>
  <windid>1</windid>
  <winpid>2</winpid>
  </result>
  </root>

 

         參數說明:其中 ,wedid 是城市氣象編號,與中國天氣網編號一致,key和sign是身份驗證,注冊一個可以換成自己的,上例中的10003是公眾帳號,formt是返回格式,支持 json,xml,除了formt不是必須的以外,其他參數都是必須提供的。

 

  比如 我想獲得深圳的今日數據:

  第一步: 首先查詢深圳的城市代碼

           方法1:通過 http://api.k780.com:88/?app=weather.city&format=xml 查詢

           方法2:通過 http://www.weather.com.cn 查詢,前面已經提到過。

   經查詢,深圳的地方代碼是 101280601

 

 第二步: 通過地方代碼獲取今日天氣

          深圳的今天天氣數據就是:

        http://api.k780.com:88/?app=weather.today&weaid=101280601&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=xml

 

  2.3  獲取未來五天

      請求示例(Xml)
 

 返回示例:

 

 <?xml version="1.0" encoding="utf-8" ?>

-  <root>
  <success>1</success>
-  <result>
-  <item_0>
  <weaid>1</weaid>
  <days>2014-07-30</days>
  <week>星期三</week>
  <cityno>beijing</cityno>
  <citynm>北京</citynm>
  <cityid>101010100</cityid>
  <temperature>29℃/24℃</temperature>
  <humidity>84.2℉/75.2℉</humidity>
  <weather>陰轉晴</weather>
  <weather_icon>http://api.k780.com:88/upload/weather/d/2.gif</weather_icon>
  <weather_icon1>http://api.k780.com:88/upload/weather/d/0.gif</weather_icon1>
  <wind>微風</wind>
  <winp>小於3級</winp>
  <temp_high>29</temp_high>
  <temp_low>24</temp_low>
  <humi_high>84.2</humi_high>
  <humi_low>75.2</humi_low>
  <weatid>3</weatid>
  <weatid1>1</weatid1>
  <windid>1</windid>
  <winpid>2</winpid>
  </item_0>
-  <item_1>
  <weaid>1</weaid>
  <days>2014-07-31</days>
  <week>星期四</week>
  <cityno>beijing</cityno>
  <citynm>北京</citynm>
  <cityid>101010100</cityid>
  <temperature>31℃/24℃</temperature>
  <humidity>87.8℉/75.2℉</humidity>
  <weather></weather>
  <weather_icon>http://api.k780.com:88/upload/weather/d/0.gif</weather_icon>
  <weather_icon1>http://api.k780.com:88/upload/weather/d/0.gif</weather_icon1>
  <wind>微風</wind>
  <winp>小於3級</winp>
  <temp_high>31</temp_high>
  <temp_low>24</temp_low>
  <humi_high>87.8</humi_high>
  <humi_low>75.2</humi_low>
  <weatid>1</weatid>
  <weatid1>1</weatid1>
  <windid>1</windid>
  <winpid>2</winpid>
  </item_1>
-  <item_2>
  <weaid>1</weaid>
  <days>2014-08-01</days>
  <week>星期五</week>
  <cityno>beijing</cityno>
  <citynm>北京</citynm>
  <cityid>101010100</cityid>
  <temperature>33℃/25℃</temperature>
  <humidity>91.4℉/77℉</humidity>
  <weather></weather>
  <weather_icon>http://api.k780.com:88/upload/weather/d/0.gif</weather_icon>
  <weather_icon1>http://api.k780.com:88/upload/weather/d/0.gif</weather_icon1>
  <wind>微風</wind>
  <winp>小於3級</winp>
  <temp_high>33</temp_high>
  <temp_low>25</temp_low>
  <humi_high>91.4</humi_high>
  <humi_low>77</humi_low>
  <weatid>1</weatid>
  <weatid1>1</weatid1>
  <windid>1</windid>
  <winpid>2</winpid>
  </item_2>
-  <item_3>
  <weaid>1</weaid>
  <days>2014-08-02</days>
  <week>星期六</week>
  <cityno>beijing</cityno>
  <citynm>北京</citynm>
  <cityid>101010100</cityid>
  <temperature>34℃/24℃</temperature>
  <humidity>93.2℉/75.2℉</humidity>
  <weather></weather>
  <weather_icon>http://api.k780.com:88/upload/weather/d/0.gif</weather_icon>
  <weather_icon1>http://api.k780.com:88/upload/weather/d/0.gif</weather_icon1>
  <wind>微風</wind>
  <winp>小於3級</winp>
  <temp_high>34</temp_high>
  <temp_low>24</temp_low>
  <humi_high>93.2</humi_high>
  <humi_low>75.2</humi_low>
  <weatid>1</weatid>
  <weatid1>1</weatid1>
  <windid>1</windid>
  <winpid>2</winpid>
  </item_3>
-  <item_4>
  <weaid>1</weaid>
  <days>2014-08-03</days>
  <week>星期日</week>
  <cityno>beijing</cityno>
  <citynm>北京</citynm>
  <cityid>101010100</cityid>
  <temperature>33℃/25℃</temperature>
  <humidity>91.4℉/77℉</humidity>
  <weather>晴轉多雲</weather>
  <weather_icon>http://api.k780.com:88/upload/weather/d/0.gif</weather_icon>
  <weather_icon1>http://api.k780.com:88/upload/weather/d/1.gif</weather_icon1>
  <wind>微風</wind>
  <winp>小於3級</winp>
  <temp_high>33</temp_high>
  <temp_low>25</temp_low>
  <humi_high>91.4</humi_high>
  <humi_low>77</humi_low>
  <weatid>1</weatid>
  <weatid1>2</weatid1>
  <windid>1</windid>
  <winpid>2</winpid>
  </item_4>
-  <item_5>
  <weaid>1</weaid>
  <days>2014-08-04</days>
  <week>星期一</week>
  <cityno>beijing</cityno>
  <citynm>北京</citynm>
  <cityid>101010100</cityid>
  <temperature>33℃/25℃</temperature>
  <humidity>91.4℉/77℉</humidity>
  <weather>多雲</weather>
  <weather_icon>http://api.k780.com:88/upload/weather/d/1.gif</weather_icon>
  <weather_icon1>http://api.k780.com:88/upload/weather/d/1.gif</weather_icon1>
  <wind>微風</wind>
  <winp>小於3級</winp>
  <temp_high>33</temp_high>
  <temp_low>25</temp_low>
  <humi_high>91.4</humi_high>
  <humi_low>77</humi_low>
  <weatid>2</weatid>
  <weatid1>2</weatid1>
  <windid>1</windid>
  <winpid>2</winpid>
  </item_5>
  </result>
  </root>

 

   轉換方法與前面類似,這里就不需要重復了。

 

3. 綜合方案

    3. 1 實時天氣

          我們用 :  http://www.weather.com.cn/data/sk/101010100.html

    3.2  今天天氣

         2個選擇: 

         1.   http://www.weather.com.cn/data/cityinfo/101010100.html 

   

         2.   http://api.k780.com:88/?app=weather.today&weaid=101010100&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=xml

 

     3.3  未來幾天天氣

           今天天氣及未來五天天氣 :

         http://api.k780.com:88/?app=weather.future&weaid=101010100&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=xml

   

    3.4    生活指數

             http://www.weather.com.cn/data/zs/101010100.html

           

 

 4. 隨身雲 天氣API接口

     4.1 簡介

         APP "中華萬年歷"使用的API接口,查詢速度很快,唯一的缺點是沒有天氣標志圖片,提供2個接口,一個簡化版,一個詳細版,詳細說明如下:

      

    4.2 簡化版接口

          接口示例(北京): http://wthrcdn.etouch.cn/weather_mini?citykey=101010100

         參數citykey就是設置地方代碼,和中國天氣網的地方代碼一樣,替換要查詢的地方代碼即可,下同。

 

返回示例:

     {"desc":"OK","status":1000,"data":{"wendu":"28","ganmao":"相對今天出現了較大幅度降溫,較易發生感冒,體質較弱的朋友請注意適當防護。","forecast":[{"fengxiang":"微風","fengli":"小於3級","high":"高溫 29℃","type":"陰","low":"低溫 24℃","date":"30日星期三"},{"fengxiang":"微風","fengli":"小於3級","high":"高溫 31℃","type":"晴","low":"低溫 24℃","date":"31日星期四"},{"fengxiang":"微風","fengli":"小於3級","high":"高溫 33℃","type":"晴","low":"低溫 25℃","date":"1日星期五"},{"fengxiang":"微風","fengli":"小於3級","high":"高溫 34℃","type":"晴","low":"低溫 24℃","date":"2日星期六"},{"fengxiang":"微風","fengli":"小於3級","high":"高溫 33℃","type":"晴","low":"低溫 25℃","date":"3日星期天"},{"fengxiang":"微風","fengli":"小於3級","high":"高溫 33℃","type":"多雲","low":"低溫 25℃","date":"4日星期一"},{"fengxiang":"微風","fengli":"小於3級","high":"高溫 33℃","type":"多雲","low":"低溫 25℃","date":"5日星期二"}],"yesterday":{"fl":"小於3級","fx":"微風","high":"高溫 29℃","type":"中雨","low":"低溫 22℃","date":"29日星期二"},"aqi":"186","city":"北京"}}

     4.3. 詳細版接口

 
        

      接口示例: http://wthrcdn.etouch.cn/WeatherApi?citykey=101010100

返回示例:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. - <resp>
  3. <city>北京</city>
  4. <updatetime>16:05</updatetime>
  5. <wendu>28</wendu>
  6. <fengli>2級</fengli>
  7. <shidu>66%</shidu>
  8. <fengxiang>東風</fengxiang>
  9. <sunrise_1>05:10</sunrise_1>
  10. <sunset_1>19:31</sunset_1>
  11. <sunrise_2 />
  12. <sunset_2 />
  13. - <environment>
  14. <aqi>186</aqi>
  15. <pm25>140</pm25>
  16. <suggest>...適量減少戶外運動</suggest>
  17. <quality>中度污染</quality>
  18. <MajorPollutants>顆粒物(PM2.5)</MajorPollutants>
  19. <o3>142</o3>
  20. <co>2</co>
  21. <pm10>0</pm10>
  22. <so2>4</so2>
  23. <no2>24</no2>
  24. <time>15:00:00</time>
  25. </environment>
  26. - <yesterday>
  27. <date_1>29日星期二</date_1>
  28. <high_1>高溫 29℃</high_1>
  29. <low_1>低溫 22℃</low_1>
  30. - <day_1>
  31. <type_1>中雨</type_1>
  32. <fx_1>微風</fx_1>
  33. <fl_1>小於3級</fl_1>
  34. </day_1>
  35. - <night_1>
  36. <type_1>中雨</type_1>
  37. <fx_1>微風</fx_1>
  38. <fl_1>小於3級</fl_1>
  39. </night_1>
  40. </yesterday>
  41. - <forecast>
  42. - <weather>
  43. <date>30日星期三</date>
  44. <high>高溫 29℃</high>
  45. <low>低溫 24℃</low>
  46. - <day>
  47. <type></type>
  48. <fengxiang>微風</fengxiang>
  49. <fengli>小於3級</fengli>
  50. </day>
  51. - <night>
  52. <type></type>
  53. <fengxiang>微風</fengxiang>
  54. <fengli>小於3級</fengli>
  55. </night>
  56. </weather>
  57. - <weather>
  58. <date>31日星期四</date>
  59. <high>高溫 31℃</high>
  60. <low>低溫 24℃</low>
  61. - <day>
  62. <type></type>
  63. <fengxiang>微風</fengxiang>
  64. <fengli>小於3級</fengli>
  65. </day>
  66. - <night>
  67. <type></type>
  68. <fengxiang>微風</fengxiang>
  69. <fengli>小於3級</fengli>
  70. </night>
  71. </weather>
  72. - <weather>
  73. <date>1日星期五</date>
  74. <high>高溫 33℃</high>
  75. <low>低溫 25℃</low>
  76. - <day>
  77. <type></type>
  78. <fengxiang>微風</fengxiang>
  79. <fengli>小於3級</fengli>
  80. </day>
  81. - <night>
  82. <type></type>
  83. <fengxiang>微風</fengxiang>
  84. <fengli>小於3級</fengli>
  85. </night>
  86. </weather>
  87. - <weather>
  88. <date>2日星期六</date>
  89. <high>高溫 34℃</high>
  90. <low>低溫 24℃</low>
  91. - <day>
  92. <type></type>
  93. <fengxiang>微風</fengxiang>
  94. <fengli>小於3級</fengli>
  95. </day>
  96. - <night>
  97. <type></type>
  98. <fengxiang>微風</fengxiang>
  99. <fengli>小於3級</fengli>
  100. </night>
  101. </weather>
  102. - <weather>
  103. <date>3日星期天</date>
  104. <high>高溫 33℃</high>
  105. <low>低溫 25℃</low>
  106. - <day>
  107. <type></type>
  108. <fengxiang>微風</fengxiang>
  109. <fengli>小於3級</fengli>
  110. </day>
  111. - <night>
  112. <type>多雲</type>
  113. <fengxiang>微風</fengxiang>
  114. <fengli>小於3級</fengli>
  115. </night>
  116. </weather>
  117. - <weather>
  118. <date>4日星期一</date>
  119. <high>高溫 33℃</high>
  120. <low>低溫 25℃</low>
  121. - <day>
  122. <type>多雲</type>
  123. <fengxiang>微風</fengxiang>
  124. <fengli>小於3級</fengli>
  125. </day>
  126. - <night>
  127. <type>多雲</type>
  128. <fengxiang>微風</fengxiang>
  129. <fengli>小於3級</fengli>
  130. </night>
  131. </weather>
  132. - <weather>
  133. <date>5日星期二</date>
  134. <high>高溫 33℃</high>
  135. <low>低溫 25℃</low>
  136. - <day>
  137. <type>多雲</type>
  138. <fengxiang>微風</fengxiang>
  139. <fengli>小於3級</fengli>
  140. </day>
  141. - <night>
  142. <type>多雲</type>
  143. <fengxiang>微風</fengxiang>
  144. <fengli>小於3級</fengli>
  145. </night>
  146. </weather>
  147. </forecast>
  148. - <zhishus>
  149. - <zhishu>
  150. <name>感冒指數</name>
  151. <value>較易發</value>
  152. <detail>較易發生感冒,體質較弱的朋友請注意適當防護。</detail>
  153. </zhishu>
  154. - <zhishu>
  155. <name>紫外線指數</name>
  156. <value></value>
  157. <detail>紫外線強度較弱。</detail>
  158. </zhishu>
  159. - <zhishu>
  160. <name>穿衣指數</name>
  161. <value></value>
  162. <detail>天氣熱,建議着短裙、短褲、短薄外套、T恤等夏季服裝。</detail>
  163. </zhishu>
  164. - <zhishu>
  165. <name>舒適度</name>
  166. <value>較舒適</value>
  167. <detail>白天以陰或多雲天氣為主。</detail>
  168. </zhishu>
  169. - <zhishu>
  170. <name>洗車指數</name>
  171. <value>不宜</value>
  172. <detail>不宜洗車,路面積水較多,不宜擦洗汽車...</detail>
  173. </zhishu>
  174. - <zhishu>
  175. <name>旅游指數</name>
  176. <value>適宜</value>
  177. <detail>天氣較好,溫度適宜,總體來說還是好天氣哦...</detail>
  178. </zhishu>
  179. - <zhishu>
  180. <name>運動指數</name>
  181. <value>較不宜</value>
  182. <detail>陰天,且天氣較熱,請減少運動時間並降低運動強度。</detail>
  183. </zhishu>
  184. - <zhishu>
  185. <name>晨練指數</name>
  186. <value>較適宜</value>
  187. <detail>早晨氣象條件較適宜晨練...</detail>
  188. </zhishu>
  189. - <zhishu>
  190. <name>約會指數</name>
  191. <value>較適宜</value>
  192. <detail>雖然天空有些陰沉,但情侶們可以放心外出...</detail>
  193. </zhishu>
  194. - <zhishu>
  195. <name>逛街指數</name>
  196. <value>適宜</value>
  197. <detail>陰天,在這種天氣里去逛街,省去了塗防曬霜...</detail>
  198. </zhishu>
  199. - <zhishu>
  200. <name>晾曬指數</name>
  201. <value>不太適宜</value>
  202. <detail>天氣陰沉,請盡量選擇通風的地點。</detail>
  203. </zhishu>
  204. - <zhishu>
  205. <name>雨傘指數</name>
  206. <value>不帶傘</value>
  207. <detail>陰天,但降水概率很低,無須帶雨傘。</detail>
  208. </zhishu>
  209. </zhishus>
  210. </resp>
  211. - <!-- 127.0.0.1(127.0.0.1):48457 ; 127.0.0.1:8080
  212. -->

5. 新浪天氣接口

    接口示例:

        http://php.weather.sina.com.cn/xml.php?city=深圳&password=DJOYnieT8234jlsK&day=0

   

      其中,city后是城市名稱,Password固定,Day為0表示當天天氣,1表示第二天的天氣,2表示第三天的天氣,以此類推,最大為4

 

返回示例:

 

 
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2.  
  3. - <!--
  4. published at 2014-07-30 15:18:36
  5. --> f%28clean%29%3B
  6. - <Profiles>
  7. - <Weather>
  8. <city>深圳</city>
  9. <status1>多雲</status1>
  10. <status2>多雲</status2>
  11. <figure1>duoyun</figure1>
  12. <figure2>duoyun</figure2>
  13. <direction1>無持續風向</direction1>
  14. <direction2>無持續風向</direction2>
  15. <power1>≤3</power1>
  16. <power2>≤3</power2>
  17. <temperature1>34</temperature1>
  18. <temperature2>27</temperature2>
  19. <ssd>8</ssd>
  20. <tgd1>31</tgd1>
  21. <tgd2>31</tgd2>
  22. <zwx>1</zwx>
  23. <ktk>2</ktk>
  24. <pollution>3</pollution>
  25. <xcz>4</xcz>
  26. <zho />
  27. <diy />
  28. <fas />
  29. <chy>1</chy>
  30. <zho_shuoming>暫無</zho_shuoming>
  31. <diy_shuoming>暫無</diy_shuoming>
  32. <fas_shuoming>暫無</fas_shuoming>
  33. <chy_shuoming>短袖衫、短裙、短褲、薄型T恤衫、敞領短袖棉衫</chy_shuoming>
  34. <pollution_l>輕度</pollution_l>
  35. <zwx_l>最弱</zwx_l>
  36. <ssd_l>較熱</ssd_l>
  37. <fas_l>暫無</fas_l>
  38. <zho_l>暫無</zho_l>
  39. <chy_l>薄短袖類</chy_l>
  40. <ktk_l>適宜開啟(制冷)</ktk_l>
  41. <xcz_l>不太適宜</xcz_l>
  42. <diy_l>暫無</diy_l>
  43. <pollution_s>對空氣污染物擴散無明顯影響</pollution_s>
  44. <zwx_s>紫外線最弱</zwx_s>
  45. <ssd_s>戶外活動不適宜在中午前后展開。</ssd_s>
  46. <ktk_s>適宜開啟空調</ktk_s>
  47. <xcz_s>洗車后未來1-2天內有降水、大風或沙塵天氣,不太適宜洗車</xcz_s>
  48. <gm>2</gm>
  49. <gm_l>易發期</gm_l>
  50. <gm_s>天氣悶熱,注意預防熱傷風;</gm_s>
  51. <yd>5</yd>
  52. <yd_l>不適宜</yd_l>
  53. <yd_s>天氣悶熱,不適宜戶外運動;</yd_s>
  54. <savedate_weather>2014-07-30</savedate_weather>
  55. <savedate_life>2014-07-30</savedate_life>
  56. <savedate_zhishu>2014-07-30</savedate_zhishu>
  57. </Weather>
  58. </Profiles>

 

 圖片格式:

         figure1和figure2標簽分別代表天氣的白天和夜間標志,根據下面的規則轉換為具體的路徑:

   

 多雲的78*78 小圖:

         白天: http://php.weather.sina.com.cn/images/yb3/78_78/duoyun_0.png 

         夜間: http://php.weather.sina.com.cn/images/yb3/78_78/duoyun_1.png

  多雲的 180*180 大圖:
          白天:http://php.weather.sina.com.cn/images/yb3/180_180/duoyun_0.png
          夜間:http://php.weather.sina.com.cn/images/yb3/180_180/duoyun_1.png

 

6.雲聚 (功能很多,需收費)

 

    官方文檔: http://www.36wu.com/Service/Details/1

 

6.1 實時氣象

 
 
 
 
參數名 數據類型 是否必須 默認值 描述 備注
district string     是 城市名稱(必須編碼)或城市ID 中文字符需編碼
output string     否 json 輸出格式,json或xml,默認json  
authkey string     否 商用或試用的authkey,無authkey參數情況下每小時訪問僅限20次,點擊申請authkey  
 

6.2  IP智能地區實時氣象

      示 例:http://api.36wu.com/Weather/GetWeatherByIp?output=xml

 

參數名 數據類型 是否必須 默認值 描述 備注
iP string 客戶端IP 根據ip返回相應地區氣象,如果被省略,表示使用客戶端IP  
output string json 輸出格式,json或xml,默認json  
authkey string 商用或試用的authkey,無authkey參數情況下每小時訪問僅限20次,點擊申請authkey  

 

 6.3  未來一周氣象

 

       示 例: http://api.36wu.com/Weather/GetMoreWeather?district=%E5%8C%97%E4%BA%AC&output=xml 

 

6.4  IP智能地區未來一周氣象

 

     示 例:http://api.36wu.com/Weather/GetMoreWeatherByIp?output=xml

 
        

6.5 生活氣象指數

 

     示 例:http://api.36wu.com/Weather/GetWeatherIndex?district=%E5%8C%97%E4%BA%AC&output=xml

 

6.6  城市列表查詢

     示 例:http://api.36wu.com/Weather/GetAreaList?&output=xml

 

  

7. 百度API Store (當天天氣)

  官方文檔: http://apistore.baidu.com/astore/serviceinfo/1798.html

   7.1 天氣查詢

      接口地址:http://apistore.baidu.com/microservice/weather

      請求方法:GET

 

 

參數名 描述 請求示例 備注
cityid 城市代碼 http://apistore.baidu.com/microservice/weather?cityid=101010100  
cityname 城市名稱 http://apistore.baidu.com/microservice/weather?cityname=北京 中文字符需編碼
citypinyin 城市拼音 http://apistore.baidu.com/microservice/weather?citypinyin=beijing  

 

 

JSON返回示例:

{
errNum: 0,
errMsg: "success",
retData: {
   city: "北京", //城市
   pinyin: "beijing", //城市拼音
   citycode: "101010100",  //城市編碼	
   date: "15-02-11", //日期
   time: "11:00", //發布時間
   postCode: "100000", //郵編
   longitude: 116.391, //經度
   latitude: 39.904, //維度
   altitude: "33", //海拔	
   weather: "晴",  //天氣情況
   temp: "10", //氣溫
   l_tmp: "-4", //最低氣溫
   h_tmp: "10", //最高氣溫
   WD: "無持續風向",	 //風向
   WS: "微風(<10m/h)", //風力
   sunrise: "07:12", //日出時間
   sunset: "17:44" //日落時間
  }    
}

    7.2 城市信息列表

            接口地址:http://apistore.baidu.com/microservice/cityinfo

            請求方法:GET

 

參數名 描述 請求示例 備注
cityname 城市名稱 http://apistore.baidu.com/microservice/cityinfo?cityname=北京 可以用來通過名稱獲取代碼,需編碼

JSON返回示例:

 

{
errNum: 0,
retMsg: "success",
retData: {
cityName: "北京",
provinceName: "北京",
cityCode: "101010100",  //天氣預報城市代碼
zipCode: "100000",      //郵編
telAreaCode: "010"     //電話區號
}
}

注意: 提交含有中文字符的URL時需要進行URL編碼不然無法正常獲取數據,並且返回數據是UniCode編碼的,注意轉換。百度雖然穩定,遺憾的是沒有天氣符號,不過我們可以通過上面提到過新浪的接口獲取。 

 

8. 中國天氣網 (網頁插件型)

    8.1  簡介

        官方文檔: http://www.tianqi.com/plugin/

        示例: http://i.tianqi.com/index.php?c=code&id=12&icon=1&py=guangzhou&num=5

      天氣網(www.tianqi.com )天氣插件接口      服務地址:http://i.tianqi.com/index.php      
 參數名  類型 是否必須 默認值  描述  備注
 c  string 獲取方式,設置為"code",表示獲取代碼。  
 id  dword 模板樣式,建議設置為19  
 icon  dword 1 圖標樣式,范圍1-5  
 py  string 客戶 地方名全拼,默認為客戶地方。  
 num  dword 5  預報天數  

 

  8.2  智能未來五天天氣預報:http://i.tianqi.com/index.php?c=code&id=19

 

返回數據:

 

 

不定時更新中。。。。

 

 

 @2014-2015 nohacks.cn 版權所有,轉載請注明出處


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM