智能定位天气接口介绍

调用说明 调用示例 在线测试
接口地址: https://ping.4759.cn/api/weather_api.php
请求方式: GET
返回格式: JSON
频率限制: 单IP每分钟最多60次请求,额外按APIKey等级限制日调用量
缓存时效: 同一IP+Key数据缓存3小时
授权要求: 需携带有效的key参数
定位方式: 自动获取访问者IPv4 → 自动匹配城市名称查询气象
报错提示: 接口报错时末尾会自动显示

本API无需传入城市、无需adcode,自动获取访问者IP定位城市,返回完整气象信息(实时温湿度、空气质量、5天逐天预报),数据缓存3小时降低请求消耗。
注意:必须携带有效API Key,未授权无法调用。单IP每分钟最高60次请求,超出返回429限流。

调用说明

1. 请求参数

参数名 必选 类型 说明 示例值
key 是 string API授权码 user_xxxx

2. 返回参数

参数名 类型 说明
code int 200成功,400/401/403/404/429/500错误
msg string 接口状态描述
used_api string 接口标识
client_info object 访客定位信息
client_info.province string 访客所在省份
client_info.city string 访客所在城市
weather_source_data object 原始气象数据
weather_source_data.location object 定位城市经纬度、行政编码、地址
weather_source_data.current object 实时天气、温度、风力、空气质量、AQI
weather_source_data.forecast array 未来5天天气预报,包含日出日落、空气质量
call_stats object 当前授权key当日调用统计
call_stats.used_day int 今日已调用次数
call_stats.remaining_day int 今日剩余可用次数

3. 状态码说明

调用示例

1. GET请求(最简调用)

http://ping.4759.cn/api/weather_api.php?key=你的授权码

2. PHP调用示例

<?php // +---------------------------------------------------------------------- // | 自动定位天气 PHP调用示例 // | 复制即可使用,需替换为自己的API Key // +---------------------------------------------------------------------- $key = "你的授权码"; $url = "http://ping.4759.cn/api/weather_api.php?key=" . urlencode($key); $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_SSL_VERIFYPEER => false ]); $response = curl_exec($ch); curl_close($ch); $result = json_decode($response, true); print_r($result); ?>

3. Python调用示例

import requests key = "你的授权码" url = f"http://ping.4759.cn/api/weather_api.php?key={key}" res = requests.get(url, timeout=10) data = res.json() print(data)

4. 成功返回完整真实示例(与线上返回完全一致)

{ "code": 200, "msg": "success", "used_api": "4759.cn 智能IP定位天气接口", "client_info": { "province": "河南省", "city": "驻马店市" }, "weather_source_data": { "location": { "name": "驻马店市", "province": "河南省", "city": "驻马店市", "district": "驿城区", "address": "河南省-驻马店市", "lat": 33.017842, "lng": 114.028471, "adcode": "411702" }, "current": { "update_time": "15:50", "weather": "阴", "weather_code": "d02", "temperature": "28", "wind": "东北风", "wind_level": "3级", "humidity": "43%", "pressure": "999百帕", "visibility": "7695", "air_quality": "优", "aqi": "45", "pm25": "16" }, "forecast": [ { "date": "09.03", "day_of_week": "周四", "day_weather": "多云", "night_weather": "晴", "high_temp": "29", "low_temp": "18", "wind": "东北风", "wind_level": "<3级", "sunrise": "05:59", "sunset": "18:47", "aqi": "41", "aqi_level": 0, "aqi_desc": "优" }, { "date": "09.04", "day_of_week": "周五", "day_weather": "晴", "night_weather": "晴", "high_temp": "30", "low_temp": "17", "wind": "北风", "wind_level": "<3级", "sunrise": "05:59", "sunset": "18:46", "aqi": "50", "aqi_level": 0, "aqi_desc": "优" }, { "date": "09.05", "day_of_week": "周六", "day_weather": "晴", "night_weather": "晴", "high_temp": "30", "low_temp": "19", "wind": "东北风", "wind_level": "<3级", "sunrise": "06:00", "sunset": "18:44", "aqi": "73", "aqi_level": 1, "aqi_desc": "良" }, { "date": "09.06", "day_of_week": "周日", "day_weather": "晴", "night_weather": "晴", "high_temp": "31", "low_temp": "18", "wind": "东北风", "wind_level": "<3级", "sunrise": "06:01", "sunset": "18:43", "aqi": "49", "aqi_level": 0, "aqi_desc": "优" }, { "date": "09.07", "day_of_week": "周一", "day_weather": "晴", "night_weather": "多云", "high_temp": "31", "low_temp": "19", "wind": "东北风", "wind_level": "<3级", "sunrise": "06:01", "sunset": "18:42", "aqi": "54", "aqi_level": 1, "aqi_desc": "良" } ] }, "call_stats": { "used_day": 33, "remaining_day": 467 } }

在线测试

点击按钮获取完整气象JSON。