😘 天气查询
天气预报 接口
本接口用于查询城市天气预报信息,支持通过城市ID或城市名称查询天气数据,默认返回三天天气数据,并支持 JSON 返回格式。
接口地址
主用接口:https://api.ku.cm/weather/?location=
备用接口:https://api.xk.ee/weather/?location=
请求方式
| 请求方式 | 返回格式 |
|---|---|
| GET | TEXT / JSON |
请求参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| location | string | 否 | 城市ID,例如 101020100 表示上海 |
| city | string | 否 | 城市名称,例如 shanghai |
| days | int | 否 | 查询天气天数(3 或 7),默认3天 |
请求示例
https://api.ku.cm/weather
https://api.ku.cm/weather/?city=shanghai
https://api.ku.cm/weather/?location=101020100
https://api.ku.cm/weather/?city=shanghai&days=7
JSON 返回示例
{
"code": 200,
"msg": "success",
"data": {
"location": "101020100",
"weather": [
{
"date": "2026-03-09",
"weather": "多云",
"temp": "4~12℃",
"wind": "北风 1-3级",
"humidity": "66%"
},
{
"date": "2026-03-10",
"weather": "晴",
"temp": "6~12℃",
"wind": "东风 1-3级",
"humidity": "80%"
},
{
"date": "2026-03-11",
"weather": "多云",
"temp": "6~15℃",
"wind": "南风 1-3级",
"humidity": "77%"
}
]
},
"server_time": "2026-03-09 19:20:00",
"runtime": "0.051233s"
}
返回字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码 |
| msg | string | 状态说明 |
| location | string | 城市ID |
| date | string | 日期 |
| weather | string | 天气情况 |
| temp | string | 温度范围 |
| wind | string | 风向风力 |
| humidity | string | 湿度 |
| server_time | string | 服务器时间 |
| runtime | string | 接口响应时间 |
状态码说明
| 状态码 | 说明 |
|---|---|
| 200 | 请求成功 |
| 400 | 参数错误 |
| 404 | 城市不存在 |
| 429 | 请求过多 |
| 500 | 服务器错误 |
| 502 | 上游接口错误 |
调用示例
HTML 调用
https://api.ku.cm/weather
JSON 调用
https://api.ku.cm/weather/?city=shanghai
效果演示
天气示例:
2026-03-09 - 多云 - 4~12℃ - 北风 1-3级
2026-03-10 - 晴 - 6~12℃ - 东风 1-3级
2026-03-11 - 多云 - 6~15℃ - 南风 1-3级
2026-03-10 - 晴 - 6~12℃ - 东风 1-3级
2026-03-11 - 多云 - 6~15℃ - 南风 1-3级