您的位置:首页 > 其它

通过API接口 获取 IP 跟 手机 所在地信息

2013-03-15 11:28 218 查看
/* 传入手机号码,通过API的到xml格式数据,对xml进一步解析,最后返回相应的号码信息的数组。*/
function  getCity_tel($phonenumber) {
/* 注释掉的是调用的淘宝的API */
/*$url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$phonenumber;
$ret = iconv('GBK','UTF-8',file_get_contents($url));
$ret = str_replace('__GetZoneResult_ = ','',$ret);
$ret = str_replace("'",'"',$ret);
$ret = str_replace(" ",'',$ret);
$ret = str_replace('{','{"',$ret);
$ret = str_replace(":",'":',$ret);
$ret = str_replace(",",',"',$ret);
$ret = preg_replace("/\s/",'',$ret);
$tel = json_decode($ret);*/

/* 这里调用的是有道的API */
$data = array();
$url = "http://www.yodao.com/smartresult-xml/search.s?type=mobile&q=".$phonenumber;
$tel = simplexml_load_string(file_get_contents($url));
$data['phonenum'] = (string)$tel->product->phonenum;
$data['location'] = explode(" ",(string)$tel->product->location);
return $data;
}

/* 传入IP地址,通过API的到JSON格式数据,对JSON进一步解析,最后返回相应的IP地址的数组。*/
function getCity_ip($ip)
{
/* 这里调用的是淘宝的API */
$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;
}


直接调用返回的都是数组,直接处理数组就可以得到想到的信息了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: