对接免 Key 的 Open-Meteo 开源气象 API:city 先经地理编码(支持中文与全球地名,结果缓存一天),再取当前温度/体感/湿度/风/降水与 WMO 天气现象中文描述,daily 返回 0-7 天最高最低温与降水量。三类参数都省略时自动定位访客——优先使用 EdgeOne 边缘 GeoIP 直接得出精确经纬度(located_by=eo-geo,免地理编码往返),无该信息时退回访客 IP 查离线属地库再地理编码(located_by=ip:访客IP)。同坐标预报缓存 10 分钟。
http://rainapi.top/api/weather在本站内直接写 /api/weather 就能调用;从别处调用请复制上方完整地址。 浏览器网页代码可以直接跨域请求,无需额外配置。响应头包含Access-Control-Allow-Origin: *,浏览器可 fetch。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| city 例: 杭州 | string | 可选 | 城市名(中英文均可);与 lat/lon 二选一,全部省略时按访客 IP 属地自动定位 |
| lat / lon 例: 30.29/120.16 | number | 可选 | 纬度 -90~90 / 经度 -180~180 |
| days 例: 5 | number | 可选 | 预报天数 0-7,默认 3;0 为仅当前天气 |
| 字段 | 类型 | 说明 |
|---|---|---|
| location | object | 地点名、行政区、国家与坐标 |
| current.temp / feels_like / humidity / wind_speed / precipitation | number | ℃ / ℃ / % / km·h⁻¹ / mm |
| current.weather_text / weather_icon | string | WMO 现象的中文描述与图标 |
| daily[] | array | date、天气、temp_max/min、precip_mm、wind_max |
| located_by | string | 仅 IP 自动定位时出现:eo-geo(EdgeOne 边缘定位,含精确经纬度)或 ip:访客IP(离线库退回) |
GET /api/weather?city=杭州{
"code": 200,
"location": {
"name": "杭州",
"admin1": "浙江省",
"country": "中国",
"lat": 30.29,
"lon": 120.16
},
"timezone": "Asia/Shanghai",
"current": {
"temp": 8.2,
"feels_like": 5.1,
"humidity": 64,
"wind_speed": 11.3,
"precipitation": 0,
"weather_code": 1,
"weather_text": "基本晴朗",
"weather_icon": "🌤️"
},
"daily": [
{
"date": "2026-12-03",
"weather_text": "局部多云",
"temp_max": 11.4,
"temp_min": 4.2,
"precip_mm": 0
}
],
"source": "Open-Meteo"
}| HTTP | code | 含义 |
|---|---|---|
| 400 | 400 | 参数非法、坐标越界,或 IP 属地无法定位且未提供替代参数 |
| 404 | 404 | 地点未找到 |
| 502 | 502 | 上游 Open-Meteo 不可达 |
| 429 | 429 | 超出频率限制 |
Retry-After: 30公开服务面向零散调用与轻量场景。批量任务请自行加入退避(收到 429 后等待 Retry-After 秒再重试), 或先本地缓存已查询过的结果。持续高频使用建议申请独立配额(未来提供)。
curl -s 'http://rainapi.top/api/weather?city=杭州'