IP定位,腾讯定位周边数据分享

JSON 2018-11-20 15:18:26 50630

这些天有空,把IP查询IP模糊定位的工具更新了一遍,开始用高德,写完后发现查询几次要“阿里式滑动”验证,故放弃了。

针对https://www.sojson.com/ip/ 工具,我真心怕你们“程序员”去爬虫输出结果,请看到这些分享,自己实现,有难点可以咨询我,不要采用爬虫的方式去实现,因为本站工具颇多,基本上好多工具都被程序员爬虫或者模拟正常使用者大量不正常使用,而且好多“素质低”完全不管本站死活,造成本站间接性很卡。在此恳求就算用爬虫去爬取别人的东西来实现某一个业务点,那也请节制一点,做好优化,如缓存等等,还是那句话,不要把免费的资源不当资源。

腾讯IP定位申请

在腾讯地图开放平台“https://lbs.qq.com/”用你的QQ号或者微信号登陆,填写个人信息,手机号及邮箱认证,就有几万的额度,有企业资质审核通过就会有几十万的免费额度。

创建一个KEY:https://lbs.qq.com/console/mykey.html?console=mykey

配额查看管理:https://lbs.qq.com/console/myquota.html?console=myquota

点击提升配额需要填写企业信息,有30万的免费额度,一般的都够用了,填写完毕后会3个工作日审核


腾讯IP定位Java代码实现

Http.Response response = Http.create("http://apis.map.qq.com/ws/location/v1/ip?key=你的key&ip=%s", ip)
                .get()
                .timeout(2)
                .send().getResponse();
if(response!=null && response.getStatus() == 200){
    String result = response.getResult();
    JSONObject json = JSONObject.fromObject(result);

    //判断是否无法精准定位
    if(json.getInt("status") == 0 ){//可以定位
        JSONObject location = json.getJSONObject("result").getJSONObject("location");
        //不是默认定位值
        String lng = location.getString("lng");
        String lat = location.getString("lat");
        //腾讯定位要是定位不到,就是默认北京的这个"116.407526"和"39.90403"
        if(!("116.407526".equals(lng) && "39.90403".equals(lat))){
            try {
                //开始精准定位
                Http.Response jresponse = Http.create("https://apis.map.qq.com/ws/geocoder/v1/?location=%s,%s&get_poi=1&key=你的key",  lat,lng)
                        .head("Host","map.qq.com")
                        .head("Accept","*/*")
                        .head("Accept-Encoding","gzip, deflate, br")
                        .head("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8")
                        .head("Cache-Control","no-cache")
                        .head("Referer","https://map.qq.com/")
                        .head("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36")
                        .head("X-Requested-With","XMLHttpRequest")
                        .get()
                        .timeout(2)
                        .send().getResponse();
                if(jresponse!=null && jresponse.getStatus() == 200 && StringUtils.isNotBlank(jresponse.getResult())){
                    JSONObject jjson = JSONObject.fromObject(jresponse.getResult());
                    //成功
                    if(Constant.S_ZERO.equals(jjson.optString("status"))){

                        JSONObject resultJSON = jjson.optJSONObject("result");

                        if(null != resultJSON && resultJSON.size() > 0){
                            bo.setAddress(resultJSON.optString("address"));
                            JSONObject ad_info = resultJSON.optJSONObject("ad_info");
                            bo.setDistrictadcode(ad_info.optString("adcode"));
                            JSONArray poiList = resultJSON.optJSONArray("pois");
                            //转换
                            if(null != poiList && poiList.size() > 0){
                                List<IPBo.PoiList> poiLists = new ArrayList<>();
                                poiList.forEach(e-> poiLists.add(new IPBo.PoiList(e)));
                                bo.setPoiLists(poiLists);
                            }

                            //地区详细详细
                            JSONObject address_component = resultJSON.optJSONObject("address_component");

//                                                "nation":"中国",
//                                                "province":"湖南省",
//                                                "city":"长沙市",
//                                                "district":"岳麓区",
//                                                "street":"岳麓大道",
//                                                "street_number":"岳麓大道218号"
                            bo.setNation(address_component.optString("nation"));
                            bo.setProvince(address_component.optString("province"));
                            //市
                            bo.setCity(address_component.optString("city"));
                            //区,可能为空字串
                            bo.setDistrict(address_component.optString("district"));
                            //街道
                            bo.setStreet(address_component.optString("street"));
                            //门牌,可能为空字串
                            bo.setStreetNumber(address_component.optString("street_number"));

                        }
                    }
                }
                //开启精准定位
                bo.setLocation(Boolean.TRUE);
            } catch (Exception e) {
                log.error("IP 查询精准定位请求异常,ip:%s,url:%s",ip,urlOrIp,e);
                cache = false;
            }


        }
    }

}



//数据不全,虽然成功但是不缓存
if(cache){
    //存储半个小时
    VCache.setex(historyKey,bo,1800);
}

对应的业务BO实体


@Data
public class IPBo implements Serializable {

	private static final long serialVersionUID = -1052580448111049751L;
	
	private String ip ;//ip
	
	private String address;//地址
	private String localAddress;//本地获取的地址
	private String baiduAddress;//百度获取的地址

	private String ua;//浏览器信息
	
	private String lg;//语言
	
	private String window;//系统
	private String browser;//什么浏览器
	private int type;//300:请输入正确的Ip或域名,500:系统繁忙错误


    //国家
    private String nation;
    //省
    private String province;
    //市
    private String city;
    //区
    private String district;
    //邮编
    private String adcode;
    //区号
    private String areacode;
    //精准区号
    private String districtadcode;
    //街道
    private String street;
    //门牌,可能为空字串
    private String streetNumber;

    private String message;

    //定位建筑 集合
    private List<PoiList> poiLists;

    //是否精准定位
    private Boolean location = Boolean.FALSE;

    public IPBo(String ip,int type,String message) {
        this.type = type;
        this.message = message;
        this.ip = ip;
    }




	public IPBo() {
	}



    @Data
    public static class PoiList implements Serializable {
        private static final long serialVersionUID = -1052180448111049751L;

        //电话
        private String tel;
        //"岳麓区政协委员会",
        private String title;
        //"望岳街道金星北路一段517号",
        private String address;
        //地址的类型 政府机构及社会团体;政府机关;区县级政府及事业单位",
        private String category;
        //坐标
        private String lt;
        //距离
        private String distance;


        public PoiList(){

        }

        public PoiList(Object e){
                JSONObject elem;
                if(null != e && e instanceof JSONObject){
                    elem = (JSONObject) e;
                }else{
                    elem = JSONObject.fromObject(e);
                }
                this.tel = elem.optString("tel");
                this.title = elem.optString("title");
                this.address = elem.optString("address");
                this.category = elem.optString("category");
                if(StringUtils.contains(this.category,":")){
                    this.category = this.category.replaceAll(":","/");
                }
                this.distance = elem.optString("_distance");
                JSONObject location = elem.optJSONObject("location");
                if(null != location){
                    this.lt = String.format("%s/%s",location.optString("lat"),location.optString("lng"));
                }

        }

    }
	
	
	
}

JSON使用包为net.sf.json.JSONObject,地址为:https://www.sojson.com/blog/20.html


分享高德2个有用的地址:

https://www.amap.com/service/regeo?longitude=112.90131&latitude=28.20051

https://www.amap.com/service/getHistory?type=301


版权所属:SO JSON在线解析

原文地址:https://www.sojson.com/blog/308.html

转载时必须以链接形式注明原始出处及本声明。

本文主题:

如果本文对你有帮助,那么请你赞助我,让我更有激情的写下去,帮助更多的人。

关于作者
一个低调而闷骚的男人。
相关文章
IP地址查询,IP定位IP纯真数据查询
阿里云和腾讯云哪个好?
腾讯云代金券 10000 元/ 30000 代金券领取技巧
关于微信weixin.com,价值3000万域名腾讯仲裁“0元”得手实际分析
SOJSON首页的圣诞雪花特效,特效分享,雪花特效下载
神速ICP备案经验分享,ICP备案居然一天就通过了
Oracle与Mysql删除重复的数据,Oracle和Mysql数据去重复
CDN + 数据中心粗粒度构想
Jackson 美化输出JSON,优雅的输出JSON数据,格式化输出JSON数据... ...
湖南众4s店服务怎么样?进来看看你就知道了
最新文章
XML内部实体和外部实体 146
Java面向对象编程概念 111
PHP回显语句 91
Linux—文件树 116
C语言while循环和do while循环 131
Python元组剖析 200
MySQL触发器教程 296
sql使用布尔运算符和关系运算符 241
C语言的变量和常量 296
PHP变量剖析 198
最热文章
最新MyEclipse8.5注册码,有效期到2020年 (已经更新) 681984
苹果电脑Mac怎么恢复出厂系统?苹果系统怎么重装系统? 674712
免费天气API,全国天气 JSON API接口,可以获取五天的天气预报 602004
免费天气API,天气JSON API,不限次数获取十五天的天气预报 576769
Jackson 时间格式化,时间注解 @JsonFormat 用法、时差问题说明 552904
我为什么要选择RabbitMQ ,RabbitMQ简介,各种MQ选型对比 509353
Elasticsearch教程(四) elasticsearch head 插件安装和使用 479956
Jackson 美化输出JSON,优雅的输出JSON数据,格式化输出JSON数据... ... 264463
Java 信任所有SSL证书,HTTPS请求抛错,忽略证书请求完美解决 244246
Elasticsearch教程(一),全程直播(小白级别) 225520
支付扫码

所有赞助/开支都讲公开明细,用于网站维护:赞助名单查看

查看我的收藏

正在加载... ...