中国气象局天气API

基于腾讯云EdgeOne Pages的天气数据代理服务,提供高效的缓存机制,减少对国家气象局服务器的请求压力

⚡ 边缘计算加速 🔄 智能缓存 🌍 全球可用 🔓 完全免费
7
API接口
5min~24h
缓存策略
<50ms
响应时间
99.9%
可用性

🧪 API 在线测试

选择接口,填写参数,直接发送请求测试API

请先选择接口

响应结果

200 OK 0ms
JSON Response
{}
GET

全国天气预报

🕐 缓存 30 分钟
GET /api/weather/:days

路径参数

参数名 类型 必填 说明
days integer 天数,1为今天,2为明天,范围 [1-7]

请求示例

cURL
curl -X GET "https://your-domain.pages.dev/api/weather/1" \
  -H "Accept: application/json"

响应示例

JSON
{
  "msg": "success",
  "code": 0,
  "data": {
    "lastUpdate": "2025/08/31 12:00",
    "date": "2025/09/01",
    "city": [
      [
        "59279",           // 监测站ID
        "三水",            // 城市
        "中国",            // 国家
        3,                 // 天气图标 code
        23.2,              // 纬度
        112.88,            // 经度
        34.0,              // 日间温度
        "阴",              // 日间天气
        2,                 // 日间天气图标
        "无持续风向",      // 日间风向
        "微风",            // 日间风速
        27.0,              // 夜间温度
        "小雨",            // 夜间天气
        7,                 // 夜间天气图标
        "无持续风向",      // 夜间风向
        "微风",            // 夜间风速
        "AGD",             // 省份代码
        "440607"           // 行政区划代码
      ]
    ]
  }
}
GET

根据GPS坐标查询天气

🔥 新功能

根据经纬度坐标获取最近监测站的天气预报。系统会自动查找距离坐标最近的站。

请求地址 /api/weather/geo?lat={lat}&lng={lng}

请求参数

参数 类型 必填 说明
lat number 纬度(如 23.13)
lng number 经度(如 113.26)

请求示例

bash
curl "https://your-domain/api/weather/geo?lat=23.13&lng=113.26"

响应示例

JSON
{
  "msg": "success",
  "code": 0,
  "data": {
    "location": {
      "id": "59280",
      "name": "广州",
      "path": "中国,广东,广州",
      "longitude": 113.26,
      "latitude": 23.13,
      "timezone": 8
    },
    "daily": [               // 7天预报
      { "date": "2026/07/04", "high": 33, "dayText": "多云", "low": 27, "dayWindDirection": "南风", "dayWindScale": "3级" },
      { "date": "2026/07/05", "high": 32, "dayText": "阵雨", "low": 26, ... },
      ...
    ],
    "hourly": [              // 24小时逐时预报
      { "hour": "16:00", "temp": 32, "text": "多云", "humidity": 65, "pop": 30 },
      { "hour": "17:00", "temp": 31, "text": "多云", "humidity": 68, "pop": 20 },
      ...
    ],
    "now": {
      "temperature": 31,
      "humidity": 65,
      "windDirection": "东南风",
      "windScale": "3级",
      "pressure": 1008,
      "feelst": 34
    },
    "indexes": [             // 环境指数
      { "name": "紫外线指数", "level": 3, "desc": "中等", "advice": "建议涂擦防晒护肤品" },
      { "name": "空气质量指数", "level": 1, "desc": "优", "advice": "适宜户外活动" },
      { "name": "舒适度指数", "level": 2, "desc": "较舒适", "advice": "注意防暑降温" },
      { "name": "穿衣指数", "level": 1, "desc": "炎热", "advice": "穿着清凉衣物" },
      { "name": "洗车指数", "level": 2, "desc": "较适宜", "advice": "未来24小时无雨" },
      { "name": "晨练指数", "level": 1, "desc": "适宜", "advice": "天气较好" }
    ],
    "alarm": []
  }
}
GET

搜索监测站

🕐 缓存 24 小时
GET /api/search?q=:query&limit=:limit

查询参数

参数名 类型 必填 说明
q string 搜索关键词(需要URL编码)
limit integer 返回数量,默认10

请求示例

cURL
curl -X GET "https://your-domain.pages.dev/api/search?q=三水&limit=5" \
  -H "Accept: application/json"

响应示例

JSON
{
  "msg": "success",
  "code": 0,
  "data": [
    "59279|三水|Sanshui|中国",
    "M1068|三亚|Sanya|中国"
  ]
}
GET

省份/国家列表

🕐 缓存 24 小时
GET /api/province/:id?

GET /api/country/:id?

路径参数

参数名 类型 必填 说明
id string 省份/国家ID,留空则返回列表

请求示例

cURL
# 获取省份列表
curl "https://your-domain.pages.dev/api/province"

# 获取指定省份的监测站
curl "https://your-domain.pages.dev/api/province/44"

# 获取国家列表
curl "https://your-domain.pages.dev/api/country"

# 获取指定国家的监测站
curl "https://your-domain.pages.dev/api/country/003772"

响应示例

JSON
{
  "msg": "success",
  "code": 0,
  "data": "003772,伦敦|003334,曼彻斯特|440607,三水"
}
GET

城市天气预报

🕐 缓存 15 分钟
GET /api/city/:stationId?view=:view

参数

参数名 类型 必填 说明
stationId string 监测站ID
view boolean 设为true返回完整数据(含节气、预警)

请求示例

cURL
# 基础天气数据
curl "https://your-domain.pages.dev/api/city/59279"

# 完整数据(含节气、预警)
curl "https://your-domain.pages.dev/api/city/59279?view=true"

响应示例

JSON
{
  "msg": "success",
  "code": 0,
  "data": {
    "location": {
      "id": "59279",
      "name": "三水",
      "path": "中国, 广东, 三水",
      "longitude": 112.88,
      "latitude": 23.2,
      "timezone": 8
    },
    "daily": [
      {
        "date": "2025/08/31",
        "high": 33.0,
        "dayText": "阵雨",
        "dayCode": 3,
        "dayWindDirection": "无持续风向",
        "dayWindScale": "微风",
        "low": 26.0,
        "nightText": "多云",
        "nightCode": 1,
        "nightWindDirection": "无持续风向",
        "nightWindScale": "微风"
      }
    ],
    "now": {
      "precipitation": 0.0,
      "temperature": 31.7,
      "pressure": 1008.0,
      "humidity": 60.0,
      "windDirection": "东北风",
      "windDirectionDegree": 21.0,
      "windSpeed": 3.1,
      "windScale": "微风",
      "feelst": 34.8
    },
    "alarm": [],
    "lastUpdate": "2025/08/31 11:15"
  }
}
GET

实时气象数据

🕐 缓存 5 分钟
GET /api/now/:stationId

路径参数

参数名 类型 必填 说明
stationId string 监测站ID

请求示例

cURL
curl "https://your-domain.pages.dev/api/now/59279"

响应示例

JSON
{
  "msg": "success",
  "code": 0,
  "data": {
    "location": {
      "id": "59279",
      "name": "三水",
      "path": "中国, 广东, 三水"
    },
    "now": {
      "precipitation": 0.0,
      "temperature": 31.9,
      "pressure": 1008.0,
      "humidity": 60.0,
      "windDirection": "东北风",
      "windDirectionDegree": 7.0,
      "windSpeed": 3.6,
      "windScale": "3级",
      "feelst": 34.7
    },
    "alarm": [],
    "lastUpdate": "2025/08/31 11:35"
  }
}
GET

气象预警信息

🕐 缓存 5 分钟
GET /api/alarm?adcode=:code

查询参数

参数名 类型 必填 说明
adcode string 省份行政区划代码(两位),留空查询全国

请求示例

cURL
# 全国预警
curl "https://your-domain.pages.dev/api/alarm"

# 广东省预警(44)
curl "https://your-domain.pages.dev/api/alarm?adcode=44"

响应示例

JSON
{
  "msg": "success",
  "code": 0,
  "data": [
    {
      "id": "44082541600000_20250831115755",
      "headline": "徐闻县气象台发布雷雨大风黄色预警[III级/较重]",
      "effective": "2025/08/31 11:54",
      "description": "受雷雨云团影响...",
      "longitude": 110.1757,
      "latitude": 20.3261,
      "type": "p0015003",
      "title": "广东省湛江市徐闻县发布雷雨大风黄色预警"
    }
  ]
}

💡 行政区划代码说明

  • 可到民政部网站查询完整代码
  • 身份证前两位即为所在省份代码
  • 例如:广东=44,北京=11,上海=31
📋

重要说明

📌 使用须知

  • 本服务为国家气象局公开数据的代理缓存,不做任何商业用途
  • 所有数据版权归中国气象局所有
  • 气象信息一般十几分钟更新一次,请勿频繁请求
  • 监测站ID包含字母,请使用字符串类型存储
  • 图片链接域名均为 https://weather.cma.cn

JavaScript 调用示例

JavaScript
// 获取今日天气
async function getTodayWeather() {
  const res = await fetch('https://your-domain.pages.dev/api/weather/1');
  const data = await res.json();
  console.log(data.data.city);
}

// 搜索城市
async function searchStation(name) {
  const res = await fetch(
    `https://your-domain.pages.dev/api/search?q=${encodeURIComponent(name)}`
  );
  const data = await res.json();
  console.log(data.data);
}

// 获取城市实时天气
async function getCityWeather(stationId) {
  const res = await fetch(
    `https://your-domain.pages.dev/api/now/${stationId}`
  );
  const data = await res.json();
  console.log(data.data.now);
}