首先
推荐使用高德,彩云等第三方收费API。
https://kalacloud.com/blog/free-weather-api/
如果个人应用,实在没钱,考虑暂时使用如下方案
ip转位置
纯真数据库
$ curl http(s)://cz88geoaliyun.cz88.net/search/ip/geo?ip=101.230.10.99
{
"code": 200,
"data": {
"ip": "101.230.10.99",
"geocode": "156032005006",
"country": "中国",
"countryCode": "CN",
"province": "江苏",
"city": "苏州",
"districts": "吴中区",
"isp": "中国电信",
"iana": "中国",
"ianaEn": "CN"
},
"success": true
}
官方接口1(2023/10/18更新)
// 所有请求Header需要添加 Referer: http://www.weather.com.cn/
// 1. 获取自身ip对应city id
http://wgeo.weather.com.cn/ip/?_=1671779888882 // 获取 var ip="119.7.18.112";var id="101270101";var addr="四川,成都,成都";
// 2. 获取城市天气数据
http://www.weather.com.cn/weather1d/101190401.shtml // 固定city id的天气web页
http://d1.weather.com.cn/sk_2d/101270101.html?_=1697618731744 // city id的天气JSON数据1
http://d1.weather.com.cn/dingzhi/101270101.html?_=1697618731745 // jsonp 格式2
// 备用
https://j.i8tq.com/weather2020/search/city.js // 城市City Id List
http://toy1.weather.com.cn/search?cityname=suzhou&_=1671779691727 // 搜索city id