支持GET和POST两种请求方式
https://your-domain/api_ip.php
GET 或 POST
JSON
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
key |
string | 是 | 您的API密钥(在用户中心查看) |
ip |
string | 否 | 要查询的IP地址(IPv4或IPv6),不提供则查询当前IP |
通过URL参数传递参数,适合简单查询
GET /api_ip.php?key=YOUR_API_KEY&ip=8.8.8.8
GET /api_ip.php?key=YOUR_API_KEY
curl "https://your-domain/api_ip.php?key=YOUR_API_KEY&ip=8.8.8.8"
fetch('https://your-domain/api_ip.php?key=YOUR_API_KEY&ip=8.8.8.8')
.then(response => response.json())
.then(data => console.log(data));
$url = 'https://your-domain/api_ip.php?key=YOUR_API_KEY&ip=8.8.8.8';
$response = file_get_contents($url);
$data = json_decode($response, true);
通过POST表单或JSON传递参数,适合批量查询或需要隐藏密钥的场景
POST /api_ip.php
Content-Type: application/x-www-form-urlencoded
key=YOUR_API_KEY&ip=8.8.8.8
POST /api_ip.php
Content-Type: application/json
{
"key": "YOUR_API_KEY",
"ip": "8.8.8.8"
}
curl -X POST "https://your-domain/api_ip.php" \
-d "key=YOUR_API_KEY&ip=8.8.8.8"
curl -X POST "https://your-domain/api_ip.php" \
-H "Content-Type: application/json" \
-d '{"key":"YOUR_API_KEY","ip":"8.8.8.8"}'
const formData = new FormData();
formData.append('key', 'YOUR_API_KEY');
formData.append('ip', '8.8.8.8');
fetch('https://your-domain/api_ip.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => console.log(data));
fetch('https://your-domain/api_ip.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
key: 'YOUR_API_KEY',
ip: '8.8.8.8'
})
})
.then(response => response.json())
.then(data => console.log(data));
$data = [
'key' => 'YOUR_API_KEY',
'ip' => '8.8.8.8'
];
$options = [
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => http_build_query($data)
]
];
$context = stream_context_create($options);
$response = file_get_contents('https://your-domain/api_ip.php', false, $context);
$result = json_decode($response, true);
{
"code": 200,
"message": "查询成功,已扣除1积分",
"data": {
"ip": "8.8.8.8",
"country": "美国",
"region": "加利福尼亚州",
"city": "山景城",
"district": "",
"isp": "Google LLC",
"owner": "",
"country_code": "US",
"continent_code": "NA",
"remaining_points": 99.00
}
}
{
"code": 401,
"message": "无效的API密钥"
}
| 错误码 | 说明 |
|---|---|
200 |
请求成功 |
400 |
请求参数错误(如IP格式无效) |
401 |
认证失败(API密钥无效或缺失) |
403 |
积分不足 |
404 |
IP未在数据库中找到 |
500 |
服务器内部错误 |