天气查询
查询城市当前天气及7天预报,数据源tianqi.com
GET
https://api.tinyaii.cn/v1/weather
请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| city | string | 必填 | 城市名称(中文或拼音),如:北京、上海、guangzhou | 北京 |
返回字段
| 字段 | 类型 | 说明 |
|---|---|---|
| data.city | string | 城市名称 |
| data.current.temp | string | 当前温度(℃) |
| data.current.weather | string | 天气状况 |
| data.current.temp_low | string | 最低温度 |
| data.current.temp_high | string | 最高温度 |
| data.current.humidity | string | 湿度(%) |
| data.current.wind | string | 风向 |
| data.current.wind_level | string | 风力等级 |
| data.current.aqi | string | 空气质量 |
| data.current.pm25 | string | PM2.5 |
| data.current.uv | string | 紫外线强度 |
| data.current.sunrise | string | 日出时间 |
| data.current.sunset | string | 日落时间 |
| data.forecast | array | 7天天气预报 |
| data.forecast[].date | string | 日期 |
| data.forecast[].week | string | 星期 |
| data.forecast[].weather | string | 天气状况 |
| data.forecast[].temp_low | string | 最低温度 |
| data.forecast[].temp_high | string | 最高温度 |
| data.forecast[].wind | string | 风向 |
| data.forecast[].wind_level | string | 风力等级 |
返回示例
{
"code": 200,
"data": {
"city": "北京",
"current": {
"temp": "23",
"weather": "多云",
"temp_low": "22",
"temp_high": "29",
"humidity": "65",
"wind": "东北风",
"wind_level": "1级",
"aqi": "优",
"pm25": "11",
"uv": "很弱",
"sunrise": "04:48",
"sunset": "19:47"
},
"forecast": [
{
"date": "06月30日",
"week": "星期二",
"weather": "多云转小雨",
"temp_low": "21",
"temp_high": "28",
"wind": "东北风",
"wind_level": "1级"
},
{
"date": "07月01日",
"week": "星期三",
"weather": "多云转小雨",
"temp_low": "22",
"temp_high": "28",
"wind": "东风",
"wind_level": "1级"
}
]
},
"message": "success"
}
调用示例
curl "https://api.tinyaii.cn/v1/weather?city=北京" \
-H "Authorization: Bearer YOUR_API_KEY"const res = await fetch("https://api.tinyaii.cn/v1/weather?city=北京", {
headers: { "Authorization": "Bearer YOUR_API_KEY" },
});
console.log(await res.json());import requests
resp = requests.get(
"https://api.tinyaii.cn/v1/weather",
params={"city": "北京"},
headers={"Authorization": "Bearer YOUR_API_KEY"},
timeout=10,
)
print(resp.json())把 YOUR_API_KEY 换成你的密钥即可直接运行。密钥只保存在你自己的设备上。