分享一个免费的天气API

API地址:   http://59kuang.com/api2.php?mod=weather

特点:支持http、https,2个模式,根据来访IP自动获取城市天气信息

缺点:暂时只能获取当天天气信息,后续会增加历史天气和未来天气

最主要的是稳定、而且永久免费。

返回格式:script (为什么要返回script?,因为script可以跨域!!!)

(function(){window.SWther={"status":"1","count":"1","info":"OK","infocode":"10000","lives":[{"province":"\u91cd\u5e86","city":"\u91cd\u5e86\u5e02","adcode":"500000","weather":"\u591a\u4e91","temperature":"8","winddirection":"\u5357","windpower":"5","humidity":"68","reporttime":"2018-01-13 18:00:00","fl":8,"icon":"01"}]}})();

lives: 天气信息数组

province:省份

city:城市

adcode:城市代码

weather:实时天气

temperature:温度

winddirection:风向

windpower:风力

humidity:湿度

reporttime:更新时间

icon:天气图标


代码示例:

$.ajax({

url : "//www.59kuang.com/api2.php?mod=weather", 

dataType : "script",

scriptCharset : "gbk",

success : function() {

var _w = window.SWther.lives[0];

console.log('Percentage:',_w);

});


图标下载地址:

百度网盘:  https://pan.baidu.com/s/1pMGtTDD     密码: hfu4

你可能感兴趣的:(分享一个免费的天气API)