
数据
高德天气数据源
Use when the user asks for weather data — current conditions, temperature, forecast, precipitation, wind (keywords:天气、气温、天气、weather、forecast、温度、降雨). Provides real-time and 3-day forecast weather for Chinese cities. Do NOT use for non-Chinese locations or historical weather data.
Skill 文件
Skill
SKILL.md
SKILL.md
| name | amap-weather-datasource |
|---|---|
| title | 高德天气数据源 |
| description | Use when the user asks for weather data — current conditions, temperature, forecast, precipitation, wind (keywords:天气、气温、天气、weather、forecast、温度、降雨). Provides real-time and 3-day forecast weather for Chinese cities. Do NOT use for non-Chinese locations or historical weather data. |
| tools | curl |
| credentials | AMAP_KEY |
| credential_help | AMAP_KEY: "在 https://console.amap.com/dev/key/app 创建 Web 服务 API 类型的 Key" |
高德天气数据源
通过 curl tool 调用高德开放平台天气查询 API,获取中国城市的实时天气和未来 3 天预报天气。
⚠️ 调用依赖说明
天气 API 只接受城市编码(adcode),不接受城市名称。如果你只有城市名称(如"北京"),必须按以下顺序调用:
- 先用「行政区域查询」接口将城市名转换为 adcode
- 再用 adcode 调用天气查询接口
鉴权
请求 restapi.amap.com 时,在 URL query 中携带 API Key:
key={{secrets.AMAP_KEY}}
占位符由后端在 curl 运行期替换为真实 key,你无需也无法看到明文。
通用约定
- Base URL:
https://restapi.amap.com/v3 - 请求方法:GET
- 响应格式:JSON
- 分页:不分页
- 速率限制:个人开发者 5000 次/日,企业开发者 50000 次/日。超出后将返回
info: " quota exceeded" - 数据范围:仅支持中国大陆及部分港澳台地区(台湾省暂无数据)
- 更新频率:
- 实时天气:每小时更新多次
- 预报天气:每天 8、11、18 点左右更新 3 次
⚠️ 速率限制策略(必须遵守)
- 串行请求:同一时间只发 1 个 curl 请求,等返回后再发下一个。严禁并行发送多个请求
- 请求间隔:每两个请求之间至少间隔 1 秒
- 429 重试:收到 429 错误后等待 60 秒再重试,严禁立即重试
- 数据复用:已获取的 adcode 列表应缓存使用,不要重复查询
常用接口
1. 获取实时天气
GET https://restapi.amap.com/v3/weather/weatherInfo?key={{secrets.AMAP_KEY}}&city={adcode}&extensions=base参数:
| 参数名 | 位置 | 必填 | 说明 |
|---|---|---|---|
| key | query | 是 | Web 服务 API Key |
| city | query | 是 | 城市 adcode(如北京的 110000) |
| extensions | query | 是 | 固定填 base 表示获取实时天气 |
| output | query | 否 | 响应格式,默认 JSON,可选 XML |
关键返回字段:
| JSON Path | 类型 | 说明 |
|---|---|---|
| status | string | "1"表示成功,"0"表示失败 |
| infocode | string | "10000"表示查询成功 |
| lives[0].province | string | 省份名 |
| lives[0].city | string | 城市名 |
| lives[0].weather | string | 天气现象(如"晴"、"小雨") |
| lives[0].temperature | string | 实时气温(°C) |
| lives[0].winddirection | string | 风向描述 |
| lives[0].windpower | string | 风力级别(级) |
| lives[0].humidity | string | 空气湿度(%) |
| lives[0].reporttime | string | 数据发布时间 |
2. 获取未来 3 天预报
GET https://restapi.amap.com/v3/weather/weatherInfo?key={{secrets.AMAP_KEY}}&city={adcode}&extensions=all参数:
| 参数名 | 位置 | 必填 | 说明 |
|---|---|---|---|
| key | query | 是 | Web 服务 API Key |
| city | query | 是 | 城市 adcode(如上海的 310000) |
| extensions | query | 是 | 固定填 all 表示获取预报数据 |
| output | query | 否 | 响应格式,默认 JSON |
关键返回字段:
| JSON Path | 类型 | 说明 |
|---|---|---|
| status | string | "1"表示成功 |
| infocode | string | "10000"表示查询成功 |
| forecasts[0].province | string | 省份名 |
| forecasts[0].city | string | 城市名 |
| forecasts[0].reporttime | string | 预报发布时间 |
| forecasts[0].casts[0].date | string | 当天日期(YYYY-MM-DD) |
| forecasts[0].casts[0].week | string | 星期几(1-7) |
| forecasts[0].casts[0].dayweather | string | 白天天气现象 |
| forecasts[0].casts[0].nightweather | string | 晚间天气现象 |
| forecasts[0].casts[0].daytemp | string | 白天温度(°C) |
| forecasts[0].casts[0].nighttemp | string | 晚间温度(°C) |
| forecasts[0].casts[0].daywind | string | 白天风向 |
| forecasts[0].casts[0].nightwind | string | 晚间风向 |
| forecasts[0].casts[0].daypower | string | 白天风力 |
| forecasts[0].casts[0].nightpower | string | 晚间风力 |
| forecasts[0].casts[1] | object | 第二天预报数据 |
| forecasts[0].casts[2] | object | 第三天预报数据 |
3. 城市名转 adcode(辅助接口)
先调此接口获取城市编码,再查询天气。
GET https://restapi.amap.com/v3/config/district?key={{secrets.AMAP_KEY}}&keywords={城市名}&subdistrict=0参数:
| 参数名 | 位置 | 必填 | 说明 |
|---|---|---|---|
| key | query | 是 | Web 服务 API Key |
| keywords | query | 是 | 城市名称(如"北京"、"上海"、"杭州市") |
| subdistrict | query | 否 | 子级行政区数,默认 1,设为 0 只返回当前级 |
关键返回字段:
| JSON Path | 类型 | 说明 |
|---|---|---|
| status | string | "1"表示成功 |
| infocode | string | "10000"表示查询成功 |
| districts[0].name | string | 地区名称 |
| districts[0].adcode | string | 城市编码(用于天气查询) |
| districts[0].level | string | 行政级别(如"city") |
调用示例
场景:查询北京市今天的天气
步骤 1: 获取北京的城市编码
curl(url = "https://restapi.amap.com/v3/config/district?key={{secrets.AMAP_KEY}}&keywords=北京&subdistrict=0")从返回中提取 districts[0].adcode 得到 "110000"。
步骤 2: 查询实时天气
curl(url = "https://restapi.amap.com/v3/weather/weatherInfo?key={{secrets.AMAP_KEY}}&city=110000&extensions=base")从返回中提取:
lives[0].city→ "北京"lives[0].weather→ "晴"lives[0].temperature→ "25"lives[0].winddirection→ "西南风"lives[0].humidity→ "45"
场景:查询杭州市未来 3 天天气预报
步骤 1: 获取杭州的城市编码
curl(url = "https://restapi.amap.com/v3/config/district?key={{secrets.AMAP_KEY}}&keywords=杭州")提取 districts[0].adcode → "330100"
步骤 2: 查询预报天气
curl(url = "https://restapi.amap.com/v3/weather/weatherInfo?key={{secrets.AMAP_KEY}}&city=330100&extensions=all")从 forecasts[0].casts 数组中遍历 3 天的预报数据:
| 天数 | date | dayweather | nightweather | daytemp | nighttemp |
|---|---|---|---|---|---|
| 今天 | 2025-01-15 | 多云 | 晴 | 18 | 8 |
| 明天 | 2025-01-16 | 小雨 | 阴 | 15 | 6 |
| 后天 | 2025-01-17 | 阴 | 多云 | 12 | 4 |
常用城市 adcode 速查
| 城市 | adcode |
|---|---|
| 北京 | 110000 |
| 上海 | 310000 |
| 广州 | 440100 |
| 深圳 | 440300 |
| 杭州 | 330100 |
| 成都 | 510100 |
| 武汉 | 420100 |
| 西安 | 610100 |
| 南京 | 320100 |
| 重庆 | 500000 |
完整城市编码表:
错误处理
| HTTP 状态码 | info 值 | 含义与应对方式 |
|---|---|---|
| 200 | OK | 请求成功 |
| 200 | "DAILY_QUERY_OVER_LIMIT" | 超出每日额度,明日再试或申请提升额度 |
| 200 | "USERKEY_PLAT_NOMATCH" | Key 类型不匹配,需创建「Web服务API」类型 Key |
| 200 | "INVALID_USER_KEY" | Key 无效或拼写错误,请检查 credential 配置 |
| 200 | "INVALID_PARAMS" | 参数错误,请检查 adcode 格式(纯数字字符串) |
数据边界说明
- 地域限制:仅支持中国地区查询,台湾省暂无数据
- 时间精度:预报数据更新频率约每天 3 次,请以
reporttime字段为准 - 天气现象:返回值为中文(如"晴"、"多云"、"小雨"),非枚举代码
- 温度单位:摄氏度(°C)
- 空值含义:当某个字段返回空字符串时,表示该数据当前不可用或暂未采集
Ln 1, Col 1MarkdownSpaces: 2
No errors