功能说明

免费天气接口,返回指定坐标的当前天气及逐日预报。

请求

GET /api/weather

查询参数

参数 类型 必填 默认值 说明
city string 二选一 城市名,如 上海北京西安Tokyo
lat float 二选一 纬度,范围 -90 ~ 90
lon float 经度,范围 -180 ~ 180(与 lat 同时使用)
days int 1 预报天数,范围 1-16
timezone string auto 时区,如 Asia/Shanghai,默认自动检测

citylat+lon 二选一,city 优先。

响应

{
  "data": {
    "location": {
      "latitude": 31.22222,
      "longitude": 121.45806,
      "timezone": "Asia/Shanghai",
      "timezone_abbreviation": "CST",
      "elevation": 7.0,
      "name": "上海市",
      "country": "中国",
      "country_code": "CN",
      "admin1": "上海市"
    },
    "current": {
      "time": "2024-03-30T14:00",
      "temperature": 18.5,
      "temperature_unit": "°C",
      "apparent_temperature": 16.2,
      "humidity": 42,
      "weather_code": 1,
      "description": "基本晴朗",
      "wind_speed": 12.4,
      "wind_speed_unit": "km/h",
      "wind_direction": 225,
      "precipitation": 0.0,
      "is_day": true
    },
    "daily": [
      {
        "date": "2024-03-30",
        "weather_code": 3,
        "description": "阴天",
        "temp_max": 21.0,
        "temp_min": 10.5,
        "precipitation_sum": 0.0,
        "wind_speed_max": 18.2,
        "sunrise": "2024-03-30T06:07",
        "sunset": "2024-03-30T18:29"
      }
    ]
  }
}

weather_code 说明(WMO 编码)

代码 说明
0 晴天
1 基本晴朗
2 局部多云
3 阴天
45/48
51-55 毛毛雨
61-65
71-77
80-82 阵雨
95 雷暴
96/99 雷暴伴冰雹

示例

GET /api/weather?city=上海
GET /api/weather?city=北京&days=7
GET /api/weather?city=西安&days=3
GET /api/weather?city=Tokyo&timezone=Asia/Tokyo
GET /api/weather?lat=39.9042&lon=116.4074
GET /api/weather?lat=31.2304&lon=121.4737&days=7

错误码