我是靠谱客的博主 秀丽羽毛,这篇文章主要介绍IP地址获取当前地理位置(省份)的接口php用淘宝接口获取ip的城市省份,现在分享给大家,希望可以做个参考。

腾讯的接口是 ,返回数组 http://fw.qq.com/ipaddress
返回值 var IPData = new Array("61.135.152.194","","北京市","");
 
新浪的接口 : http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 
多地域测试方法:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=218.192.3.42
返回值 var remote_ip_info = {"ret":1,"start":"218.192.0.0","end":"218.192.7.255","country":"u4e2du56fd","province":"u5e7fu4e1c","city":"u5e7fu5dde","district":"","isp":"u6559u80b2u7f51","type":"u5b66u6821","desc":"u5e7fu5ddeu5927u5b66u7ebau7ec7u670du88c5u5b66u9662"};
 
 
使用 腾迅的api接口,php获取ip地址以及所在城市
http://fw.qq.com/ipaddress返回类似:var IPData = new Array("61.51.71.183","","北京市","");
代码 
 
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public static function positionAction($ip) { $ch = curl_init("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip={$ip}"); //curl_setopt($ch,CURLOPT_ENCODING ,'utf8'); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取数据返回 $location = json_decode(curl_exec($ch)); curl_close($ch); if ($location->ret == -1) { return [ 'status' => 0, 'info' => '获取地理位置失败' ]; } return [ 'status' => 1, 'info' => '获取地理位置成功', 'handle' => $location ]; }

 

php用淘宝接口获取ip的城市省份

 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/** * 通过淘宝IP接口获取IP地理位置 * @param string $ip * @return: string **/ function getCity($ip) {   $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;   $ipinfo=json_decode(file_get_contents($url));   if($ipinfo->code=='1'){     return false;   }   $city = $ipinfo->data->region.$ipinfo->data->city;   return $city;  } header("Content-Type:text/html;charset=utf-8"); // 这样调用,显示山东省临沂市 var_dump(getCity("112.234.69.189")); ?>

 

 

最后

以上就是秀丽羽毛最近收集整理的关于IP地址获取当前地理位置(省份)的接口php用淘宝接口获取ip的城市省份的全部内容,更多相关IP地址获取当前地理位置(省份)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(95)

评论列表共有 0 条评论

立即
投稿
返回
顶部