已掉线,重新登录

首页 > 绿虎论坛 > 历史版块 > 编程 > PHP > 教程

标题: 提供中国天气预报接口,需要的进

作者: @Ta

时间: 2013-12-19

点击: 2707

接口如下:

一:http://www.mplogs.com/api/weather/

二:http://www.mplogs.com/api/weather/data1/?id=xx

三:http://www.mplogs.com/api/weather/data2/?id=xxxx

四:http://www.mplogs.com/api/weather/data3/?id=xxxxxx

五:http://www.mplogs.com/api/weather/data/?id=xxxxxxxxx




说明:

上面5个接口返回的都是json数据,统一使用的utf-8编码,支持get和post请求!



第一个:返回支持此天气预报的省份,包括香港、台湾和澳门。
请求示例:http://www.mplogs.com/api/weather
返回数据部分预览:{"type":0, "city":[{"id":"01", "name":"北京"}, {"id":"02", "name":"上海"}...
返回结果说明:无



第二个:根据第一个接口返回的行省id获取此行省的下级城市
请求示例:http://www.mplogs.com/api/weather/data1/?id=01(北京)
返回数据预览:{"type":1, "city":[{"id":"0101", "name":"北京"}]}
返回结果说明:无



第三个:根据第二个接口返回的城市id获取此城市的下级地域
请求示例:http://www.mplogs.com/api/weather/data2/?id=0101(北京)
返回数据部分预览:{"type":2, "city":[{"id":"010101", "name":"北京"}, {"id":"010102", "name":"海淀"}
返回结果说明:无



第四个:根据第三个接口返回的地域id获取此地域的下级地域
请求示例:http://www.mplogs.com/api/weather/data3/?id=010101(北京)
返回数据预览:{"type":3, "city":[{"id":"010101", "name":"101010100"}]}
返回结果说明:无



第五个:根据第四个接口返回的地域name获取此地域的详细天气预报数据
请求示例:http://www.mplogs.com/api/weather/data/?id=101010100(北京)
返回数据部分预览:"cityid":"101010100","temp1":"1℃~-7℃"
返回结果说明:
temp1、temp2...temp6分别为今天、明天...第六天的摄氏度
tempF1、tempF2...tempF6分别为今天、明天...第六天的华氏度
weather1、weather2...weather6为今天、明天...第六天的天气状态
img1、img2...img12为天气状态的图标,每两个对应一天的天气状态,关于图标会在后面说明
wind1、wind2...wind6和fx1、fx2...fl5、fl6为对风速的描述(请容许我偷懒下,嘿嘿)
index为24小时的气候,index_d为24小时穿衣指数(也可以是温馨提示语)
index48和index48_d请参照上面的index和index_d(嘿嘿)
index_uv为当天(24个小时)紫外线强度
index48_uv为48小时的紫外线强度
index_xc为洗车指数
index_tr为旅游指数
index_co为舒适指数
index_cl为晨练指数
index_ls为晾晒指数
index_ag为过敏指数




关于天气图标(也做成了api)



图标api说明:type表示图片类型,number就是上面获取的天气图片的数据
有四种图片类型(返回的是图片哦):
①:http://www.mplogs.com/api/weather/img/?type=1&number=1
②:http://www.mplogs.com/api/weather/img/?type=2&number=1
③:http://www.mplogs.com/api/weather/img/?type=3&number=1
④:http://www.mplogs.com/api/weather/img/?type=4&number=1




还有,最后附上演示页面地址http://www.mplogs.com/api/weather/example/,可以查看源代码看实现方式,有注释说明,写得不好的地方也请见谅!
好了,差不多了,不知道写了几页,蛋碎了!不清楚的留言,有bug希望能提出来,谢谢!

[隐藏样式|查看源码]


『回复列表(2|隐藏机器人聊天)』

1. 另外:数据来源中国天气网
(/@Ta/2013-12-19 15:56//)

2. @xggz,【我想说>>>注册一下又不会怀孕是不是>>> K1905.Com】
(/@Ta/2013-12-19 16:08//)

回复需要登录

7月3日 23:13 星期四

本站由hu60wap6驱动

备案号: 京ICP备18041936号-1