llms.txt · xianyan.cc
内容与工具 更新于 2026-08-15

天气 API

职责:基于 Apple WeatherKit 的统一天气服务,支持 IP 自动定位、GPS 查询、多语言/单位。

天气 API(Apple WeatherKit 封装)

基础URL: https://tools.wktyl.com/api/weather
数据源: Apple WeatherKit (v1/v2)
维护: Xianyan 团队 | 更新时间: 2026-08-15

职责:基于 Apple WeatherKit 的统一天气服务,支持 IP 自动定位、GPS 查询、多语言/单位。

1. 通用约定

  • 无需登录
  • 频率:60/60s(IP 定位),30/60s(GPS 定位)
  • 响应 {code, msg, time, data}
  • 单位:metric(默认) / imperial
  • 语言:zh-CN(默认) / en-US / ja-JP / 等

2. 接口清单

接口 方法 说明
/api/weather/full GET 全量(当前+逐小时+逐日+分钟降水+预警)
/api/weather/current GET 当前天气
/api/weather/hourly GET 逐小时预报(最多 24 小时)
/api/weather/daily GET 逐日预报(最多 10 天)
/api/weather/minute GET 分钟级降水(未来 1 小时)
/api/weather/alerts GET 天气预警
/api/weather/lookup GET IP 自动定位后查天气

3. 输入参数

参数 类型 必填 说明
lat / lon number 二选一 GPS 坐标
city string 城市名(内部转经纬度)
units string metric / imperial
lang string 语言

4. 响应示例

GET /api/weather/current?city=北京&units=metric&lang=zh-CN

# 响应
{
  "code": 1,
  "data": {
    "city": "北京",
    "temperature": 28,
    "feels_like": 30,
    "humidity": 65,
    "wind_speed": 12,
    "wind_direction": "东南风",
    "description": "多云",
    "icon": "cloudy",
    "updated_at": "2026-08-15T14:00:00+08:00"
  }
}

5. 设计要点

  • WeatherKit 双 v1/v2:v2 提供更多字段(如空气质量、花粉)
  • 缓存策略:当前天气 10 分钟,逐日 1 小时,预警实时
  • 单位/语言服务端切换:减少前端复杂度

6. 关联文档