大家好,我们是中国科学院资源与环境信息系统国家重点实验室的人员(学生)。在软件开发过程中,我们发现,传统获取天气信息的接口大多是基于所谓的天气码,数据源大多来自中国国家气象局;随着移动互联网的快速发展,大家都希望通过经纬度查询天气信息。
最开始我们搜寻全网,发现谷歌提供了利用经纬度获取天气信息的接口,然而一测试发现,由于“你懂的”原因,它已经无法使用了。国内IT三哥——百度貌似也提供了这么一个接口,但是又是需要神马key啊,验证文件啊等等一堆手续;而且它还限制每天的单个IP的访问次数,更让人讨厌的是,它只提供3天的天气预报信息。其他的接口大多数是通过令人深恶痛绝的天气码获取,基本都不好用。
我们本着逢山开路,遇水叠桥的精神,痛下决心,利用了点我们实验室所谓的强项——GIS技术,自己制作了天气预报,天气查询接口。天气查询接口支持全国任何地区的天气信息查询,数据精确到区县级别。天气预报接口提供5天之内的天气预报信息。
下面介绍一下天气接口以及其使用方法。天气查询接口为:http://www.missfeng.com/iserver/services/GetOverallWeatherComponent/restjsr/GetOverallWeather/"longitude"/"latitude".rjson。这个接口的访问方式为HttpGet,接口中只有两个参数"longitude"和"latitude",替换成你定位获得的经纬度即可。例如:http://www.missfeng.com/iserver/services/GetOverallWeatherComponent/restjsr/GetOverallWeather/116.3/40.rjson获取的是北京海淀区的天气信息。这个接口请求返回的是一个json,json的格式为:{"weatherinfo":{"city":"海淀","cityid":"101010200","temp1":"14℃","temp2":"9℃","weather":"小雨转阴","img1":"d7.gif","img2":"n2.gif","ptime":"08:00","temp":"12","WD":"北风","WS":"0级","SD":"86%","WSE":"0","time":"09:35","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB","njd":"暂无实况","qy":"1018"}}
其中:weatherinfo代表天气信息,city代表所在地,cityid是中国气象局给全国县市的编码,temp1代表当地当日最高气温,temp2代表当日当地最低气温,weather代表当日天气状况,img1代表白天天气状况的图标,img2代表夜晚天气状况的图标,图片资源的访问地址为http://m.weather.com.cn/img/d7.gif,其中d7.gif为获取的img;ptime为天气信息发布的时间,temp为发布时的气温,WD为风向,WS为风级,SD为湿度,WSE为风力,time代表雷达图更新时间,isRadar代表是否有雷达图,Radar代表雷达图的访问地址,njd为能见度信息,qy为当前气压信息。
天气预报接口为:http://www.missfeng.com/iserver/services/GetDetailedWeatherComponent/restjsr/GetDetailedWeather/"longitude"/"latitude".rjson,其中"longitude"/"latitude"分别为经度、纬度参数。例如:http://www.missfeng.com/iserver/services/GetDetailedWeatherComponent/restjsr/GetDetailedWeather/118.3/37.1.rjson。返回的json为:
({"time":1414719933,"area":[["山东","12"],["滨州","1211"],["博兴","101121102"]],"weather":[{"date":"2014-10-31","info":{"day":["7","小雨","18","东北风","微风"],"night":["7","小雨","11","东风","微风"]}},{"date":"2014-11-01","info":{"dawn":["7","小雨","11","东风","微风"],"day":["7","小雨","16","西北风","微风"],"night":["7","小雨","9","西北风","3-4 级"]}},{"date":"2014-11-02","info":{"dawn":["7","小雨","9","西北风","3-4 级"],"day":["1","多云","14","西北风","3-4 级"],"night":["0","晴","5","西北风","微风"]}},{"date":"2014-11-03","info":{"dawn":["0","晴","5","西北风","微风"],"day":["0","晴","17","无持续风向","微风"],"night":["0","晴","5","无持续风向","微风"]}},{"date":"2014-11-04","info":{"dawn":["0","晴","5","无持续风向","微风"],"day":["0","晴","18","无持续风向","微风"],"night":["1","多云","8","无持续风向","微风"]}}],"pm25":[]});
其中area代表当前的区域,weather代表当前的天气信息,天气信息由day 白天;night 夜晚;以及dawn傍晚信息组成,单个信息块里是最低温度,天气,风向,风级的格式,譬如["7","小雨","11","东风","微风"]分别是最低温度为7度,天气为小雨,风向为东风,风级为微风。
以上就是我们提供的天气查询和天气预报接口的介绍以及使用方法。如果您有任何疑问欢迎向czgbjy@yeah.net邮箱询问,也可以通过QQ:2649615105询问。
由于我们的服务器是架设在阿里云上,每年服务器的使用费用都比较高,而我们是一群科研屌丝加学生。如果您觉得我们的天气接口好用,并希望我们能一直提供这项服务,请您在使用接口时向支付宝账号:czgbjy@yeah.net(*祖刚)或者向中国建设银行账号:6217 0000 1002 8704 941(*祖刚)捐赠50元(多的不限噢O(∩_∩)O),并备注您单位或者个人的姓名,我们将为您提供更为个性化的服务。我们在此基础上提供永久免费的服务。