加载中...
API 封面图片

获取天气

QPS:50次 / 需要KEY免费正常GET

基于城市ID获取实时天气信息,包含当前温度、湿度、空气质量、PM2.5/PM10、感冒指数以及昨天和未来4天的天气预报数据。接口免费使用,每8小时CDN缓存更新一次。

更新时间:2026-05-15 20:41:11

天气 API 接口文档

接口概述

基于公开天气 API 封装的 PHP 代理接口,提供标准 JSON 格式天气数据,支持当前天气、空气质量、未来 5 天预报查询。

接口地址


GET https://api.xunjinlu.fun/api/weather/index.php?cityId={cityId}

请求参数

参数名 类型 必填 说明
cityId string ✅ 是 9 位城市 ID,如 101030100(天津)
format string ❌ 否 返回格式,默认 json

城市 ID 获取

完整城市列表下载: https://api.xunjinlu.fun/api/weather/csid.json

常用城市 ID:

城市 ID
北京 101010100
上海 101020100
天津 101030100
重庆 101040100
广州 101280101
深圳 101280601

响应参数

基础字段

字段 类型 说明
code int 状态码
message string 状态描述
time string 响应时间
data object 天气数据

data 对象

字段 类型 说明
update_time string 系统更新时间
city_info object 城市基本信息
current object 当前实时天气
yesterday object 昨日天气回顾
forecast array 今天 + 未来 4 天预报

city_info 对象

字段 类型 说明
city string 城市名称
city_id string 城市 ID
parent string 上级行政区
weather_update_time string 天气更新时间

current 对象

字段 类型 说明
date string 日期(YYYYMMDD)
temperature string 当前温度(℃)
humidity string 相对湿度
pm25 int PM2.5 指数
pm10 int PM10 指数
quality string 空气质量等级
cold_index string 感冒指数提示

yesterday / forecast 对象

字段 类型 说明
date string 日期(日)
ymd string 年月日
week string 星期
sunrise string 日出时间
sunset string 日落时间
high string 最高温度
low string 最低温度
type string 天气类型
fx string 风向
fl string 风力等级
aqi int 空气质量指数
notice string 天气提示语

错误码

code 说明
200 请求成功
400 参数错误(缺少 cityId 或格式错误)
500 服务器错误或上游 API 故障

使用限制

限制项 说明
请求间隔 ≥ 3 秒
每分钟阈值 300 次(超过封禁 3600 秒)
缓存更新 每 8 小时 CDN 缓存更新
建议 自行做本地缓存减少 API 调用

调用示例

cURL

curl "https://api.xunjinlu.fun/api/weather/index.php?cityId=101030100"

PHP

<?php
$response = file_get_contents('https://api.xunjinlu.fun/api/weather/index.php?cityId=101030100');
$data = json_decode($response, true);

if ($data['code'] === 200) {
    echo "当前温度: " . $data['data']['current']['temperature'] . "℃\n";
    echo "空气质量: " . $data['data']['current']['quality'] . "\n";
}
?>

JavaScript

fetch('https://api.xunjinlu.fun/api/weather/index.php?cityId=101030100')
  .then(res => res.json())
  .then(data => {
    if (data.code === 200) {
      console.log('当前温度:', data.data.current.temperature);
      console.log('空气质量:', data.data.current.quality);
    }
  });

Query

1

请根据API文档填写参数,二选一参数组只能启用其中一个
启用参数名参数值数据类型参数说明操作

Body

Body 类型说明

none:不发送任何Body数据,适用于GET请求或不需要Body的API

from-data:使用multipart/form-data格式发送数据,适用于上传文件或包含多种数据类型的请求

x-www-form-urlencoded:使用application/x-www-form-urlencoded格式发送数据,适用于简单的键值对数据

json:使用application/json格式发送数据,适用于复杂数据结构

xml:使用application/xml格式发送数据,适用于XML格式的API

raw:发送原始文本数据,可自定义Content-Type

请根据API要求选择合适的Body类型,并在下方输入对应格式的数据

接口响应

等待发起...

Node.js

cURL

PHP

Java

Go

Python

Fetch

C#

商户头像

尋鯨錄

每次崩溃的理由,在别人看来可能是小题大做,只有自己心里清楚这根稻草,到底压垮了多少千斤重的难过···wyy《人质》
24接口数
2.2k+调用次数
查看作者主页
ACE Banner
接口不存在,说不定被小渡喂狗了