淘寶IP地址庫API接口(PHP)經過ip獲取地址信息

淘寶IP地址庫網址:http://ip.taobao.com/php

淘寶地址庫API接口

提供的服務包括:
1. 根據用戶提供的IP地址,快速查詢出該IP地址所在的地理信息和地理相關的信息,包括國家、省、市和運營商。
2. 用戶能夠根據本身所在的位置和使用的IP地址更新咱們的服務內容。json

接口說明:
1. 請求接口(GET方式):
http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址字串]url

2. 響應信息(json格式數據):
國家 、省(自治區或直轄市)、市(縣)、運營商spa

3. 返回數據格式:code

{"code":0,"data":{"ip":"210.75.225.254","country":"\u4e2d\u56fd","area":"\u534e\u5317",
"region":"\u5317\u4eac\u5e02","city":"\u5317\u4eac\u5e02","county":"","isp":"\u7535\u4fe1",
"country_id":"86","area_id":"100000","region_id":"110000","city_id":"110000",
"county_id":"-1","isp_id":"100017"}}
其中code的值的含義爲,0:成功,1:失敗。

4. PHP代碼示例:接口

function getCity($ip)
{
$url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
$ip=json_decode(file_get_contents($url));
if((string)$ip->code=='1'){
  return false;
  }
  $data = (array)$ip->data;
return $data;
}
$ip='221.216.64.183';
print_r(getCity($ip));exit;
相關文章
相關標籤/搜索