调用示例
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)
print(res.json())
4. 成功返回示例
{
"code": 200,
"msg": "success",
"data": {
"user_ip": "123.123.123.123",
"province": "广东省",
"city": "汕尾市",
"adcode": "441500",
"weather": [
{
"date": "2026-03-30",
"day": {...}
}
]
},
"call_stats": {
"used_day": 5,
"remaining_day": 995
}
}