调用新浪接口获得访问者地理位置及线路情况

新浪的IP地址查询接口: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
搜狐IP地址查询接口(默认GBK):http://pv.sohu.com/cityjson
搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/cityjson?ie=utf-8
搜狐另外的IP地址查询接口:http://txt.go.sohu.com/ip/soip
腾讯的接口:http://fw.qq.com/ipaddress (腾讯的接口原本是最好用的,可现在打不开啦)


直接访问新浪接口的php文件会返回如下内容:
var remote_ip_info = {"ret":1,"start":"58.58.32.0","end":"58.58.47.255","country":"\u4e2d\u56fd","province":"\u5c71\u4e1c","city":"\u9752\u5c9b","district":"","isp":"\u7535\u4fe1","type":"","desc":""};
这是这是encode后的json串,decode后内容:
{
    "ret":1,
    "start":"58.58.32.0",
    "end":"58.58.47.255",
    "country":"中国",
    "province":"山东",
    "city":"青岛",
    "district":"",
    "isp":"电信",
    "type":"",
    "desc":""
}
新浪js接口使用举例:
<script type="text/javascript" src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" charset="gb2312"></script>
<script type="text/javascript">
         var ss = remote_ip_info['country'] + remote_ip_info['province']+ remote_ip_info['city'];
        alert(ss)
</script>


参考原文:http://blog.sina.com.cn/s/blog_69d6a78101011ksf.html
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值