有33人阅读过
腾讯天气API
发布于2024/05/17 更新于2024/05/17
[ 教程仅保证更新时有效,请自行测试。]
发布于2024/05/17 更新于2024/05/17
[ 教程仅保证更新时有效,请自行测试。]
[ 教程仅保证更新时有效,请自行测试。]
腾讯官方未提供天气api,官方网站:腾讯天气 (qq.com)
看网页代码,可以看到主要用到一个js文件获取 天气网 (weather.com.cn) 的数据,这个文件居然是明文的!
var HOST = "wis.qq.com"; function getWeatherInof(province, city, district, option) { var interface = "//" + HOST + "/weather/common?source=pc&weather_type=observe|forecast_1h|forecast_24h|index|alarm|limit|tips|rise"; var interface2 = "//" + HOST + "/weather/common?source=pc&weather_type=air|rise"; var tasks = []; var result = {}; tasks.push(new Promise(function(resolve, reject) { getData(encodeURI(interface + "&province=" + province + "&city=" + city + "&county=" + district), function(data) { if (data.status == "200") { result["weather"] = data.data; getData(encodeURI(interface2 + "&province=" + province + "&city=" + city), function(data) { if (data.status == "200") { result["weather"]["air"] = data.data.air; resolve(data.data); } }) } }) })); // tasks.push(new Promise(function(resolve,reject) { // getData("//pacaio.match.qq.com/area/recommend?site=" + geoKeys[province.replace("省","")], function(data){ // if(data.code == 0) { // result["news"] = data.data; // resolve(data.data); // } // }) // })); // tasks.push(new Promise(function(resolve,reject) { // getData("//pacaio.match.qq.com/area/rcdVideo?num=6&page=1&site=" + geoKeys[province.replace("省","")], function(data){ // if(data.code == 0) { // result["videos"] = data.data; // resolve(data.data); // } // }) // })); return Promise.all(tasks).then(function(data) { return new Promise(function(resolve, reject) { resolve(result); }) }, function(err) { }); }
提取其中的接口如下:
api接口:
https://wis.qq.com/weather/common?
参数表:
source 请求类型: pc/wx 必填
province 省份:广东 必填
city 城市:深圳 必填
county 县区:龙岗区
callback 回调函数 不传直接返回json
weather_type 查询类型,多个|分隔 必填
observe 当前天气
forecast_1h
forecast_24h
index 穿衣,舒适度等
alarm 预警
tips 天气介绍
air 空气质量
rise 日出
实例:
https://wis.qq.com/weather/common?&source=pc&weather_type=observe&province=广东&city=深圳 返回值: { "data": { "observe": { "degree": "27", "humidity": "67", "precipitation": "0", "pressure": "1003", "update_time": "202405171620", "weather": "多云", "weather_bg_pag": "", "weather_code": "01", "weather_color": null, "weather_first": "", "weather_pag": "", "weather_short": "多云", "weather_url": "", "wind_direction": "5", "wind_direction_name": "西南风", "wind_power": "4-5" } }, "message": "OK", "status": 200 }
如果你只有城市名称,可用下面的接口查询省份归属:
https://wis.qq.com/city/like?city=
实例:
https://wis.qq.com/city/like?source=pc&city=深圳 返回值: { "data":{ "101280601":"广东, 深圳" }, "message":"OK", "status":200 }
文章对你有帮助吗?
- 一般[0]
- 很赞[0]
- 没用[0]
- 垃圾[0]
- 无语[0]