天气查询2
查询城市天气信息,返回当前天气、24小时预报、7天预报。输入中文城市名即可查询。
GET
https://api.tinyaii.cn/v1/weather2
请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| city | string | 必填 | 城市名称,如:北京、上海、广州 | 北京 |
返回字段
| 字段 | 类型 | 说明 |
|---|---|---|
| city | string | 查询的城市名 |
| current.weather | string | 当前天气状况 |
| current.temp | string | 当前温度(摄氏度) |
| current.humidity | string | 湿度百分比 |
| current.pressure | string | 气压(百帕) |
| current.wind | string | 风向风力 |
| current.aqi | string | 空气质量指数 |
| current.aqi_level | string | 空气质量等级 |
| forecast | array | 7天预报列表 |
| forecast[].date | string | 日期 |
| forecast[].day | object | 白天天气 |
| forecast[].night | object | 夜间天气 |
| hourly | array | 24小时预报列表 |
| hourly[].time | string | 时间 |
| hourly[].weather | string | 天气状况 |
| hourly[].temp | string | 温度 |
返回示例
{
"code": 200,
"message": "success",
"data": {
"city": "北京",
"current": {
"weather": "多云",
"temp": "22",
"humidity": "66",
"pressure": "999",
"wind": "东南风 4-5级",
"aqi": "45",
"aqi_level": "优"
},
"forecast": [
{
"date": "06/13",
"day": {
"temp": "29℃",
"weather": "今天",
"wind": "西南风 3-4级"
},
"night": {
"temp": "20℃",
"weather": "雷阵雨",
"wind": "东风 1-3级"
}
}
],
"hourly": [
{
"time": "23:00",
"weather": "多云",
"temp": "22℃"
}
]
}
}
调用示例
curl "https://api.tinyaii.cn/v1/weather2?city=北京" \
-H "Authorization: Bearer YOUR_API_KEY"const res = await fetch("https://api.tinyaii.cn/v1/weather2?city=北京", {
headers: { "Authorization": "Bearer YOUR_API_KEY" },
});
console.log(await res.json());import requests
resp = requests.get(
"https://api.tinyaii.cn/v1/weather2",
params={"city": "北京"},
headers={"Authorization": "Bearer YOUR_API_KEY"},
timeout=10,
)
print(resp.json())把 YOUR_API_KEY 换成你的密钥即可直接运行。密钥只保存在你自己的设备上。