项目需求:
每天实时更新城市天气,结果找到的接口要么是收费才能使用,要么是每天限制频率。
但这不能让我放弃,本着将抠门进行到底的想法,不断的寻找,终于找到了这个接口,实时更新气象,包含天气,气压,风力,温度,湿度,空气质量等等一系列数据,关键是它免费,仔细一看居然是腾讯的,不敢相信,我以为腾讯就会骗我在王者里氪金呢,可把我激动坏了。
接口介绍
以下是接口里面的参数介绍
网址 | https://wis.qq.com/weather/common |
---|---|
source | pc |
weather_type | observe |
province | 安徽 |
city | 芜湖 |
county | 无为 |
source参数代表请求类型,可以填写pc或者wx,默认填写pc即可
weather_type这个参数可以填写多个数值,用|分割开来,可以查询到填写每个数值对应的数据,
observe 当前天气
alarm 预警
tips 天气介绍
index 穿衣,舒适度等
air 空气质量
rise 日出
province参数填写省份,必填项
city参数填写市,必填项
county填写县区,非必填项
实际操作
好了,现在直接上代码给大家CV
$.ajax({
url: 'https://wis.qq.com/weather/common?source=pc&weather_type=observe|forecast_24h|air&province=安徽&city=芜湖&county=无为',
dataType: 'jsonp',
success: function(res){}
});
是不是很简单,这个接口设置的是get请求,我偷懒就直接把参数填写在url里面,这里面中重要的是要设置dataType为jsonp,否则就会出现跨域问题,感兴趣的小伙伴可以自行百度。
结果展示
{
"data": {
"air": {
"aqi": 38,
"aqi_level": 1,
"aqi_name": "优",
"co": "?",
"no2": "?",
"o3": "?",
"pm10": "?",
"pm2.5": "?",
"so2": "?",
"update_time": "202108081900"
},
"forecast_24h": {
"0": {
"day_weather": "阴",
"day_weather_code": "02",
"day_weather_short": "阴",
"day_wind_direction": "东风",
"day_wind_direction_code": "2",
"day_wind_power": "4",
"day_wind_power_code": "1",
"max_degree": "34",
"min_degree": "24",
"night_weather": "晴",
"night_weather_code": "00",
"night_weather_short": "晴",
"night_wind_direction": "东北风",
"night_wind_direction_code": "1",
"night_wind_power": "3",
"night_wind_power_code": "0",
"time": "2021-08-07"
},
"1": {
"day_weather": "多云",
"day_weather_code": "01",
"day_weather_short": "多云",
"day_wind_direction": "东风",
"day_wind_direction_code": "2",
"day_wind_power": "3",
"day_wind_power_code": "0",
"max_degree": "34",
"min_degree": "24",
"night_weather": "多云",
"night_weather_code": "01",
"night_weather_short": "多云",
"night_wind_direction": "东风",
"night_wind_direction_code": "2",
"night_wind_power": "3",
"night_wind_power_code": "0",
"time": "2021-08-08"
},
"2": {
"day_weather": "阴",
"day_weather_code": "02",
"day_weather_short": "阴",
"day_wind_direction": "东北风",
"day_wind_direction_code": "1",
"day_wind_power": "3",
"day_wind_power_code": "0",
"max_degree": "31",
"min_degree": "25",
"night_weather": "雷阵雨",
"night_weather_code": "04",
"night_weather_short": "雷阵雨",
"night_wind_direction": "东北风",
"night_wind_direction_code": "1",
"night_wind_power": "3",
"night_wind_power_code": "0",
"time": "2021-08-09"
},
"3": {
"day_weather": "雷阵雨",
"day_weather_code": "04",
"day_weather_short": "雷阵雨",
"day_wind_direction": "东风",
"day_wind_direction_code": "2",
"day_wind_power": "3",
"day_wind_power_code": "0",
"max_degree": "31",
"min_degree": "24",
"night_weather": "中雨",
"night_weather_code": "08",
"night_weather_short": "中雨",
"night_wind_direction": "东风",
"night_wind_direction_code": "2",
"night_wind_power": "3",
"night_wind_power_code": "0",
"time": "2021-08-10"
},
"4": {
"day_weather": "大雨",
"day_weather_code": "09",
"day_weather_short": "大雨",
"day_wind_direction": "东风",
"day_wind_direction_code": "2",
"day_wind_power": "3",
"day_wind_power_code": "0",
"max_degree": "30",
"min_degree": "24",
"night_weather": "大雨",
"night_weather_code": "09",
"night_weather_short": "大雨",
"night_wind_direction": "东风",
"night_wind_direction_code": "2",
"night_wind_power": "4",
"night_wind_power_code": "1",
"time": "2021-08-11"
},
"5": {
"day_weather": "大雨",
"day_weather_code": "09",
"day_weather_short": "大雨",
"day_wind_direction": "东北风",
"day_wind_direction_code": "1",
"day_wind_power": "4",
"day_wind_power_code": "1",
"max_degree": "26",
"min_degree": "23",
"night_weather": "小雨",
"night_weather_code": "07",
"night_weather_short": "小雨",
"night_wind_direction": "东北风",
"night_wind_direction_code": "1",
"night_wind_power": "4",
"night_wind_power_code": "1",
"time": "2021-08-12"
},
"6": {
"day_weather": "小雨",
"day_weather_code": "07",
"day_weather_short": "小雨",
"day_wind_direction": "东北风",
"day_wind_direction_code": "1",
"day_wind_power": "4",
"day_wind_power_code": "1",
"max_degree": "26",
"min_degree": "23",
"night_weather": "小雨",
"night_weather_code": "07",
"night_weather_short": "小雨",
"night_wind_direction": "东北风",
"night_wind_direction_code": "1",
"night_wind_power": "4",
"night_wind_power_code": "1",
"time": "2021-08-13"
},
"7": {
"day_weather": "小雨",
"day_weather_code": "07",
"day_weather_short": "小雨",
"day_wind_direction": "东北风",
"day_wind_direction_code": "1",
"day_wind_power": "4",
"day_wind_power_code": "1",
"max_degree": "27",
"min_degree": "22",
"night_weather": "多云",
"night_weather_code": "01",
"night_weather_short": "多云",
"night_wind_direction": "东北风",
"night_wind_direction_code": "1",
"night_wind_power": "4",
"night_wind_power_code": "1",
"time": "2021-08-14"
}
},
"observe": {
"degree": "29",
"humidity": "65",
"precipitation": "0",
"pressure": "1003",
"update_time": "202108082050",
"weather": "多云",
"weather_code": "01",
"weather_short": "多云",
"wind_direction": "2",
"wind_power": "2"
}
},
"message": "OK",
"status": 200
}
如果存在问题请大家批评指正!!!