通过IP地址获取该IP的地理位置,准确率达到99.9%,毫秒级查询。
接口地址: http://api.70api.com/api/ipinfo/
支持协议: HTTP/HTTPS
返回格式: JSON
请求方式: GET
请求示例: https://api.70api.com/api/ipinfo/?apiKey=947addb8b6ca0f0939e555acda4fe078&ip=112.25.18.135
请求参数说明:
名称 | 必填 | 类型 | 说明 |
---|---|---|---|
ip | 是 | string | 需要操作的IP,不传则默认为请求端的IP,支持jsonp |
apiKey | 是 | string | 登录平台购买对应API产品获得唯一标识 : apiKey |
返回参数说明:
名称 | 类型 | 说明 |
---|---|---|
msg | string | 提示信息 |
res | boolean | 返回结果 true|false |
code | int | 0为正常 其他为异常 |
data | array | 返回的结果 |
country | string | 国家 |
isp | string | ISP服务商 |
city | string | 城市 |
province | string | 省份 |
返回示例:
{ "res": true, "code": 0, "msg": "成功", "data": { "country": "中国", "province": "江苏", "city": "南京", "isp": "移动" }, "timestamp": 1585041459 }
参数名称 | 参数值 |
---|---|
{ "res": true, "code": 0, "msg": "成功", "data": { "country": "中国", "province": "江苏", "city": "南京", "isp": "移动" }, "timestamp": 1585041459 }
错误码格式说明:
名称 | 类型 | 说明 |
---|---|---|
40001 | string | 请求频繁,请稍后再试! |
40004 | string | 非法请求 |
10009 | string | 该api暂时停止服务 |
10001 | string | 参数错误,请参考文档传递正确参数 |
10000 | string | 缺少必填参数,请参考文档传递必填参数 |
代码示例:
$ip = '112.25.18.135';
$api = 'https://api.70api.com/api/ipinfo/?apiKey=947addb8b6ca0f0939e555acda4fe078&ip=' . $ip;
$result = json_decode(file_get_contents($api), 1);
if (!empty($result['data']) && isset($result['data']['country'])) {
echo ' 国家: ' . $result['data']['country'];
echo ' 省份: ' . $result['data']['province'];
echo ' 城市: ' . $result['data']['city'];
echo ' isp: ' . $result['data']['isp'];
} else {
echo '获取失败:' . (empty($result['msg']) ? '未知错误' : $result['msg']);
}