查询手机归属地接口

2021-12-08 09:08:01 浏览数 (1)

代码语言:javascript复制
@Test
    public void testGetProvince() {

        String phoneNumber = "18629020328";
        String url = "http://apis.baidu.com/apistore/mobilephoneservice/mobilephone?apikey=6e825bd531b8b1839fc1cda66b19edb9&tel=" phoneNumber;
        try {
            HttpResponse resp = HttpClientHelper.INSTANCE.get(url, null, new Header[]{new BasicHeader("apikey", "6e825bd531b8b1839fc1cda66b19edb9")});
            String s = EntityUtils.toString(resp.getEntity(), "UTF-8");

            System.out.println(s);

            JsonNode jsonNode = JsonObjectUtils.stringToJsonNode(s);
            if (jsonNode.get("retMsg").getTextValue().equals("success")) {
                System.out.println(jsonNode.get("retData").get("supplier").getTextValue());
                System.out.println(jsonNode.get("retData").get("province").getTextValue());
                System.out.println(jsonNode.get("retData").get("city").getTextValue());
                System.out.println(jsonNode.get("retData").get("suit").getTextValue());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

0 人点赞