调用示例
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
}
}