1、首先进入和风天气开发平台,点击右上角的注册进行注册
和风天气开发平台
2、填写注册用的邮箱和密码完成注册,可能还需要手机号,按提示注册完成即可。
3、从和风天气开发平台右上角进入控制台,输入你刚刚注册用的邮箱和密码按登录进入控制台
4、点击应用管理——创建应用
5、选择免费开发版,然后下一步
6、应用名称随便写
7、API要选择WebApi
API要选择WebApi
API要选择WebApi
(如果开发安卓或者IOS请无视本条)
8、key的名字,随便写
9、创建完成后就是这样,key下面那一串数字就是你的key,请求其他api时都需要用到这个key,请妥善保存。
官方api文档地址:api文档地址,可以在里面查阅所有api的信息,包括请求方式、参数、响应参数等。
所有api返回信息均为json格式。
以下举例两个常用的Api:
GeoApi的使用,用于查询城市的id等信息(这里使用POSTMAN进行测试),每天50000次限制
https://geoapi.qweather.com/v2/city/lookup?key=这里填你的key&location=要查询的城市名字
参数中key为上面的那个key,location为要查询的城市信息,以福州市为例
在body中就是api返回的福州市及其下属行政区域的信息,通常来说,我们只需要location中的第一个城市信息,此处为福州市,记下它的id 101230101
"code": "200",
"location": [
{
"name": "福州",
"id": "101230101",
"lat": "26.07530",
"lon": "119.30623",
"adm2": "福州",
"adm1": "福建省",
"country": "中国",
"tz": "Asia/Shanghai",
"utcOffset": "+08:00",
"isDst": "0",
"type": "city",
"rank": "11",
"fxLink": "http://hfx.link/34w1"
},...(其余信息省略)
三日天气api的使用:https://devapi.qweather.com/v7/weather/3d?key=这里填你的key&location=要查询的城市的id
id可以通过上面的GeoApi来查询,免费用户每天可以查询1000次
查询效果:
daily中包含三日内的城市的天气信息
{
"code": "200",
"updateTime": "2021-12-13T17:35+08:00",
"fxLink": "http://hfx.link/34w1",
"daily": [
{
"fxDate": "2021-12-13",
"sunrise": "06:41",
"sunset": "17:13",
"moonrise": "13:36",
"moonset": "02:13",
"moonPhase": "盈凸月",
"moonPhaseIcon": "803",
"tempMax": "16",
"tempMin": "11",
"iconDay": "101",
"textDay": "多云",
"iconNight": "151",
"textNight": "多云",
"wind360Day": "45",
"windDirDay": "东北风",
"windScaleDay": "3-4",
"windSpeedDay": "16",
"wind360Night": "0",
"windDirNight": "北风",
"windScaleNight": "1-2",
"windSpeedNight": "3",
"humidity": "89",
"precip": "0.0",
"pressure": "996",
"vis": "24",
"cloud": "13",
"uvIndex": "2"
},
{
"fxDate": "2021-12-14",
"sunrise": "06:41",
"sunset": "17:13",
"moonrise": "14:06",
"moonset": "03:05",
"moonPhase": "盈凸月",
"moonPhaseIcon": "803",
"tempMax": "20",
"tempMin": "13",
"iconDay": "101",
"textDay": "多云",
"iconNight": "104",
"textNight": "阴",
"wind360Day": "0",
"windDirDay": "北风",
"windScaleDay": "1-2",
"windSpeedDay": "3",
"wind360Night": "0",
"windDirNight": "北风",
"windScaleNight": "1-2",
"windSpeedNight": "3",
"humidity": "90",
"precip": "0.0",
"pressure": "992",
"vis": "25",
"cloud": "8",
"uvIndex": "2"
},
{
"fxDate": "2021-12-15",
"sunrise": "06:42",
"sunset": "17:13",
"moonrise": "14:37",
"moonset": "03:58",
"moonPhase": "盈凸月",
"moonPhaseIcon": "803",
"tempMax": "24",
"tempMin": "16",
"iconDay": "101",
"textDay": "多云",
"iconNight": "151",
"textNight": "多云",
"wind360Day": "0",
"windDirDay": "北风",
"windScaleDay": "1-2",
"windSpeedDay": "3",
"wind360Night": "0",
"windDirNight": "北风",
"windScaleNight": "1-2",
"windSpeedNight": "3",
"humidity": "89",
"precip": "0.0",
"pressure": "990",
"vis": "25",
"cloud": "6",
"uvIndex": "3"
}
],
"refer": {
"sources": [
"QWeather",
"NMC",
"ECMWF"
],
"license": [
"no commercial use"
]
}
}