天气API接口大全(nohacks.cn 收集整理)

自序:

由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

返回示例:


  
  
<?xml version="1.0" encoding="UTF-8" ?> - <resp> <city>北京</city> <updatetime>16:05</updatetime> <wendu>28</wendu> <fengli>2级</fengli> <shidu>66%</shidu> <fengxiang>东风</fengxiang> <sunrise_1>05:10</sunrise_1> <sunset_1>19:31</sunset_1> <sunrise_2 /> <sunset_2 /> - <environment> <aqi>186</aqi> <pm25>140</pm25> <suggest>...适量减少户外运动</suggest> <quality>中度污染</quality> <MajorPollutants>颗粒物(PM2.5)</MajorPollutants> <o3>142</o3> <co>2</co> <pm10>0</pm10> <so2>4</so2> <no2>24</no2> <time>15:00:00</time> </environment> - <yesterday> <date_1>29日星期二</date_1> <high_1>高温 29℃</high_1> <low_1>低温 22℃</low_1> - <day_1> <type_1>中雨</type_1> <fx_1>微风</fx_1> <fl_1>小于3级</fl_1> </day_1> - <night_1> <type_1>中雨</type_1> <fx_1>微风</fx_1> <fl_1>小于3级</fl_1> </night_1> </yesterday> - <forecast> - <weather> <date>30日星期三</date> <high>高温 29℃</high> <low>低温 24℃</low> - <day> <type></type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </day> - <night> <type></type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </night> </weather> - <weather> <date>31日星期四</date> <high>高温 31℃</high> <low>低温 24℃</low> - <day> <type></type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </day> - <night> <type></type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </night> </weather> - <weather> <date>1日星期五</date> <high>高温 33℃</high> <low>低温 25℃</low> - <day> <type></type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </day> - <night> <type></type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </night> </weather> - <weather> <date>2日星期六</date> <high>高温 34℃</high> <low>低温 24℃</low> - <day> <type></type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </day> - <night> <type></type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </night> </weather> - <weather> <date>3日星期天</date> <high>高温 33℃</high> <low>低温 25℃</low> - <day> <type></type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </day> - <night> <type>多云</type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </night> </weather> - <weather> <date>4日星期一</date> <high>高温 33℃</high> <low>低温 25℃</low> - <day> <type>多云</type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </day> - <night> <type>多云</type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </night> </weather> - <weather> <date>5日星期二</date> <high>高温 33℃</high> <low>低温 25℃</low> - <day> <type>多云</type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </day> - <night> <type>多云</type> <fengxiang>微风</fengxiang> <fengli>小于3级</fengli> </night> </weather> </forecast> - <zhishus> - <zhishu> <name>感冒指数</name> <value>较易发</value> <detail>较易发生感冒,体质较弱的朋友请注意适当防护。</detail> </zhishu> - <zhishu> <name>紫外线指数</name> <value></value> <detail>紫外线强度较弱。</detail> </zhishu> - <zhishu> <name>穿衣指数</name> <value></value> <detail>天气热,建议着短裙、短裤、短薄外套、T恤等夏季服装。</detail> </zhishu> - <zhishu> <name>舒适度</name> <value>较舒适</value> <detail>白天以阴或多云天气为主。</detail> </zhishu> - <zhishu> <name>洗车指数</name> <value>不宜</value> <detail>不宜洗车,路面积水较多,不宜擦洗汽车...</detail> </zhishu> - <zhishu> <name>旅游指数</name> <value>适宜</value> <detail>天气较好,温度适宜,总体来说还是好天气哦...</detail> </zhishu> - <zhishu> <name>运动指数</name> <value>较不宜</value> <detail>阴天,且天气较热,请减少运动时间并降低运动强度。</detail> </zhishu> - <zhishu> <name>晨练指数</name> <value>较适宜</value> <detail>早晨气象条件较适宜晨练...</detail> </zhishu> - <zhishu> <name>约会指数</name> <value>较适宜</value> <detail>虽然天空有些阴沉,但情侣们可以放心外出...</detail> </zhishu> - <zhishu> <name>逛街指数</name> <value>适宜</value> <detail>阴天,在这种天气里去逛街,省去了涂防晒霜...</detail> </zhishu> - <zhishu> <name>晾晒指数</name> <value>不太适宜</value> <detail>天气阴沉,请尽量选择通风的地点。</detail> </zhishu> - <zhishu> <name>雨伞指数</name> <value>不带伞</value> <detail>阴天,但降水概率很低,无须带雨伞。</detail> </zhishu> </zhishus> </resp> - <!-- 127.0.0.1(127.0.0.1):48457 ; 127.0.0.1:8080 --> 5. 新浪天气接口

    接口示例:

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

   

      其中,city后是城市名称,Password固定,Day为0表示当天天气,1表示第二天的天气,2表示第三天的天气,以此类推,最大为4

 

返回示例:


  
  
<?xml version="1.0" encoding="UTF-8" ?>   - <!-- published at 2014-07-30 15:18:36 --> f%28clean%29%3B - <Profiles> - <Weather> <city>深圳</city> <status1>多云</status1> <status2>多云</status2> <figure1>duoyun</figure1> <figure2>duoyun</figure2> <direction1>无持续风向</direction1> <direction2>无持续风向</direction2> <power1>≤3</power1> <power2>≤3</power2> <temperature1>34</temperature1> <temperature2>27</temperature2> <ssd>8</ssd> <tgd1>31</tgd1> <tgd2>31</tgd2> <zwx>1</zwx> <ktk>2</ktk> <pollution>3</pollution> <xcz>4</xcz> <zho /> <diy /> <fas /> <chy>1</chy> <zho_shuoming>暂无</zho_shuoming> <diy_shuoming>暂无</diy_shuoming> <fas_shuoming>暂无</fas_shuoming> <chy_shuoming>短袖衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫</chy_shuoming> <pollution_l>轻度</pollution_l> <zwx_l>最弱</zwx_l> <ssd_l>较热</ssd_l> <fas_l>暂无</fas_l> <zho_l>暂无</zho_l> <chy_l>薄短袖类</chy_l> <ktk_l>适宜开启(制冷)</ktk_l> <xcz_l>不太适宜</xcz_l> <diy_l>暂无</diy_l> <pollution_s>对空气污染物扩散无明显影响</pollution_s> <zwx_s>紫外线最弱</zwx_s> <ssd_s>户外活动不适宜在中午前后展开。</ssd_s> <ktk_s>适宜开启空调</ktk_s> <xcz_s>洗车后未来1-2天内有降水、大风或沙尘天气,不太适宜洗车</xcz_s> <gm>2</gm> <gm_l>易发期</gm_l> <gm_s>天气闷热,注意预防热伤风;</gm_s> <yd>5</yd> <yd_l>不适宜</yd_l> <yd_s>天气闷热,不适宜户外运动;</yd_s> <savedate_weather>2014-07-30</savedate_weather> <savedate_life>2014-07-30</savedate_life> <savedate_zhishu>2014-07-30</savedate_zhishu> </Weather> </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 实时气象

 
服务地址: http://api.36wu.com
服务名称: Weather
方法名称: GetWeather
http请求方式: POST|GET
  支持格式: json|xml
 
 
 
参数名 数据类型 是否必须 默认值 描述 备注
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

 

返回数据:

 

 

不定时更新中。。。。

转载于:https://my.oschina.net/hejunbinlan/blog/498379

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值