使用java获取手机号归属地等信息httpClient实现

不淡定的哥 2020-01-15

entity string static exception url java获取手机号信息 java获取手机号归属地

java获取手机号归属地

一般想获取手机号归属地等信息个人是无法获取的,但是可以通过调用第三方接口获取,具体百度搜索很多
这里例子提供一个百度的接口 ,该功能已经发布到网站作为一个在线小工具,
拿走不谢:www.yzcopen.com/con/iphone
用都的jar httpClient相关
代码:


public class HttpTool {

/**
 * 手机号地区接口
 * @param request
 * @return
 */
private final static String iphoneurl = "http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=";

/**
 * http请求
 * @return
 * @throws Exception
 */
public static String doHttpgetAPi(String url)  throws Exception {
    HttpGet post = null;
     CloseableHttpResponse response = null;
    try {
        CloseableHttpClient httpClient = HttpClients.createDefault();
         post = new HttpGet(url);
        // 构造消息头
         post.setHeader("Content-Type", "application/json; charset=utf-8");
         post.setHeader("Connection", "Close");
         response =  httpClient.execute(post);
        if(response != null){
              HttpEntity entity=response.getEntity();  
                String str=EntityUtils.toString(entity); 
              return str;
        }
        return null;
    } catch (Exception e) {
        e.printStackTrace();
    }finally{
        if(response!=null){
            response.getEntity().getContent().close();
        }
        if(post != null){
            try {
                post.releaseConnection();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}

public static void main(String[] args) {
    String ipurl = iphoneurl+"您的手机号";
    String result = HttpTool.doHttpgetAPi(url);
    System.out.println(result );
}

}

通过执行返回的结果是:
{"response":{"13854510856":{"detail":{"area":[{"city":"烟台"}],"province":"山东","type":"domestic","operator":"移动"},"location":"山东烟台移动"}},"responseHeader":{"status":200,"time":1579079131507,"version":"1.1.0"}}

登录 后评论
下一篇
云栖号资讯小编
1894人浏览
2020-06-01
相关推荐
互联网定位技术小谈
3267人浏览
2017-03-22 19:04:00
spring boot跨域处理
1669人浏览
2017-12-26 15:09:51
android 服务器json
601人浏览
2012-05-23 09:26:00
JAVA实现微信支付V3
1100人浏览
2018-07-04 16:43:24
0
0
0
380