天气信息查询
根据 IP 查询对应城市的天气信息(支持未来 1-3 天预报)。key 可省略,默认使用临时测试 Key。
接口路径
/api/weather
◆ 接口信息
接口地址
/api/weather
请求方式
GET
返回格式
JSON
请求示例
https://api.kabule.cn/api/weather?ip=39.159.31.255&days=3
◆ 请求参数
| 参数名 | 参数值 | 参数类型 | 是否必填 | 默认值 | 取值范围 | 参数描述 |
|---|---|---|---|---|---|---|
key |
YOUR_API_KEY | string | 可选 | 临时测试Key | 32位大写字母数字 | API Key(可省略,默认使用临时测试Key,无需登录即可体验) |
ip |
39.159.31.255 | string | 可选 | 自动获取 | 合法IPv4或IPv6地址 | 请求IP,缺省自动获取调用者IP |
day |
3 | number | 可选 | 1 | 1-3 | 获取几天的天气,默认 1 天(也兼容 days 参数) |
◆ 返回参数
| 参数名 | 参数类型 | 参数描述 |
|---|---|---|
ip |
string | 查询的IP |
city |
string | 城市 |
path |
string | 具体位置 |
country |
string | 国家 |
weather |
array | 天气信息列表(温度/降水/湿度等) |
last_update |
string | 最后更新天气的时间 |
◆ 返回示例
查询 IP 39.159.31.255 未来 3 天天气(key可省略)
curl
curl "https://api.kabule.cn/api/weather?ip=39.159.31.255&days=3"JSON
{
"code": 200,
"msg": "获取成功",
"data": {
"ip": "39.159.31.255",
"city": "吉安",
"path": "吉安,吉安,江西,中国",
"country": "CN",
"weather": [
{ "temp": "中雨", "high": "24℃", "low": "21℃", "rainfall": "20.28mm", "humidity": "97%", "wind_scale": "2" },
{ "temp": "小雨", "high": "25℃", "low": "22℃", "rainfall": "9.41mm", "humidity": "99%", "wind_scale": "2" }
],
"last_update": "2024-06-25T08:00:00+08:00"
}
}◆ 错误示例
以下为常见请求错误时的返回结果:
API Key 无效
code 40002
curl
curl "https://api.kabule.cn/api/weather?key=WRONG_KEY"返回
{"code":40002,"msg":"API Key无效","data":null}
服务器内部错误
code 500
curl
curl "https://api.kabule.cn/api/weather?ip=39.159.31.255"返回
{"code":500,"msg":"服务器内部错误","data":null}