免费IP归属地查询接口和通过ip获取大致位置信息

1 淘宝API接口:

文档:http://ip.taobao.com/instructions

示例:  

GET http://ip.taobao.com/outGetIpInfo?ip=221.218.209.125&accessKey=alibaba-inc

{
data: {
area: "",
country: "中国",
isp_id: "100026",
queryIp: "221.218.209.125",
city: "北京",
ip: "221.218.209.125",
isp: "联通",
county: "",
region_id: "110000",
area_id: "",
county_id: null,
region: "北京",
country_id: "CN",
city_id: "110100"
},
msg: "query success",
code: 0
}


2 IP-API接口:

文档:https://ip-api.com/docs/api:json

示例:

GET http://ip-api.com/json/221.218.209.125?lang=zh-CN

{
status: "success",
country: "中国",
countryCode: "CN",
region: "BJ",
regionName: "北京市",
city: "北京",
zip: "",
lat: 39.9285,
lon: 116.385,
timezone: "Asia/Shanghai",
isp: "China Unicom Beijing Province Network",
org: "",
as: "AS4808 China Unicom Beijing Province Network",
query: "221.218.209.125"
}


3 太平洋IP接口:

文档:http://whois.pconline.com.cn/

示例:

GET http://whois.pconline.com.cn/ipJson.jsp?ip=221.218.209.125&json=true

{
ip: "221.218.209.125",
pro: "北京市",
proCode: "110000",
city: "北京市",
cityCode: "110000",
region: "海淀区",
regionCode: "110108",
addr: "北京市海淀区 联通ADSL",
regionNames: "",
err: ""
}


4 IP-API接口的整合案例

// 根据IP地址获取城市信息
protected function getCity($ip)
{
$url = "http://ip-api.com/json/".$ip."?lang=zh-CN";
$data = file_get_contents($url);
$data = json_decode($data, true);
if (!empty($data['status']) && $data['status'] == 'success') {
// 国家-省份-城市-经度,纬度
return $data['country'].'-'.$data['regionName'].'-'.$data['city'].'-'.$data['lon'].','.$data['lat'];
}
return '获取城市信息失败';
}


相关推荐

  • 生成图片

    from PIL import Image, ImageColor, ImageDraw, ImageFont, ImageFilterdef create_image_with_text(size, color, text, font_path, font_size, text_color, shadow_color, output_path): """ Create a new image of specified size and color with centered text that has a border and shadow. :param size: A tuple con

  • 获取指定目录下的所有图片信息

    1 获取指定目录下的所有图片信息// 获取指定目录下的所有图片信息 public function getImagesInfo($directory) { $images = []; // 创建递归目录迭代器 $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY ); // 遍历目录中的每个文件 foreach (

  • Thinkphp各版本的PHP要求

    ThinkPHP 8.0:运行环境要求PHP8.0+,兼容PHP8.3ThinkPHP 6.1:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 6.0:运行环境要求PHP7.2+,兼容PHP8.1ThinkPHP 5.1:运行环境要求PHP5.6+,兼容PHP8.0ThinkPHP 5.0:运行环境要求PHP5.4+,兼容PHP7.3