API详情

天气预报API

免费

提供全球城市的天气预报和历史数据

4.9 (234)
1.2k 人在使用
REST
在线调试 查看文档 获取密钥

基本信息

接口提供商
WeatherService Inc.
更新时间
2023-10-15
版本
v2.1.0
请求限制
1000次/天
数据格式
JSON / XML
认证方式
API Key

接口说明

天气预报API提供全球范围内城市的天气预报数据,包括当前天气、未来预报、历史天气和天气预警等。 该API支持按城市名称、地理坐标、邮政编码等多种方式查询,返回的数据包含温度、湿度、风速、气压等详细信息。

数据每10分钟更新一次,确保您获取的是最新的天气信息。免费用户每天可以调用1000次,付费用户无限制。

接口参数

参数名 必填 类型 说明
key string API密钥
city string 城市名称,如"Beijing"
days integer 预报天数,1-7天,默认3天
lang string 返回语言,支持en/zh/ja等
units string 单位制式,metric(公制)/imperial(英制)

返回示例

{
  "status": "success",
  "city": "Beijing",
  "country": "CN",
  "data": {
    "current": {
      "temp": 23.5,
      "feels_like": 24.1,
      "humidity": 45,
      "wind_speed": 3.6,
      "wind_dir": "NE",
      "pressure": 1012,
      "uv_index": 5,
      "weather": {
        "code": "01d",
        "main": "Clear",
        "description": "晴天"
      },
      "updated_at": "2023-10-15T08:30:00Z"
    },
    "forecast": [
      {
        "date": "2023-10-16",
        "temp_max": 25.8,
        "temp_min": 18.2,
        "humidity": 50,
        "pressure": 1010,
        "wind_speed": 4.1,
        "wind_dir": "NE",
        "weather": {
          "code": "01d",
          "main": "Clear",
          "description": "晴天"
        },
        "precipitation": 0
      },
      {
        "date": "2023-10-17",
        "temp_max": 26.5,
        "temp_min": 19.0,
        "humidity": 48,
        "pressure": 1009,
        "wind_speed": 3.8,
        "wind_dir": "E",
        "weather": {
          "code": "02d",
          "main": "Clouds",
          "description": "少云"
        },
        "precipitation": 0
      },
      {
        "date": "2023-10-18",
        "temp_max": 24.2,
        "temp_min": 17.5,
        "humidity": 62,
        "pressure": 1008,
        "wind_speed": 5.2,
        "wind_dir": "SE",
        "weather": {
          "code": "10d",
          "main": "Rain",
          "description": "小雨"
        },
        "precipitation": 8.2
      }
    ]
  }
}

错误码

错误码 说明
401 API密钥无效或缺失
404 城市未找到
429 超过请求限制
500 服务器内部错误