zoukankan      html  css  js  c++  java
  • 360免费查询手机号归属API地接口

    接口地址: https://cx.shouji.360.cn/phonearea.php?number=手机号

    
    import java.io.*;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    public class Main {
    
        public static void main(String[] args0) throws IOException {
    
            FileWriter fileWriter = new FileWriter("d://test1.txt");
    
            String httpUrl = "https://cx.shouji.360.cn/phonearea.php";
    
            String httpArg = "";
    
            for (int i = 7000; i < 8000; i++) {
    
                if (i >= 1000) {
    
                    httpArg = "number=188" + String.valueOf(i) + "4257";
                    System.out.println(httpArg);
    
                } else if (i >= 100) {
    
                    httpArg = "number=1880" + String.valueOf(i) + "4257";
    
    
                } else if (i >= 10) {
    
                    httpArg = "number=18800" + String.valueOf(i) + "4257";
    
    
                } else {
    
                    httpArg = "number=188000" + String.valueOf(i) + "4257";
    
    
    
                }
    
                String jsonResult = request(httpUrl, httpArg);
    
                String res = unicodeDecode(jsonResult);
    
                if (res.contains("长沙")) {
                    System.out.println("号码:" + httpArg + "	");
                    fileWriter.write(httpArg + "
    	");
                    System.out.println("结果:" + res);
                }
    
            }
    
            fileWriter.flush();
    
            fileWriter.close();
    
        }
    
        /**
    
         * @param
    
         *            :请求接口
    
         * @param httpArg
    
         *            :参数
    
         * @return 返回结果
    
         */
    
        public static String request(String httpUrl, String httpArg) {
    
            BufferedReader reader = null;
    
            String result = null;
    
            StringBuffer sbf = new StringBuffer();
    
            httpUrl = httpUrl + "?" + httpArg;
    
            try {
    
                URL url = new URL(httpUrl);
    
                HttpURLConnection connection = (HttpURLConnection) url
    
                        .openConnection();
    
                connection.setRequestMethod("GET");
    
    // 填入apikey到HTTP header
    
                //connection.setRequestProperty("apikey", "0574246ccaa94772abaf4f8229414249");
    
                connection.connect();
    
                InputStream is = connection.getInputStream();
    
                reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
    
                String strRead = null;
    
                while ((strRead = reader.readLine()) != null) {
    
                    sbf.append(strRead);
    
                    sbf.append("
    ");
    
                }
    
                reader.close();
    
                result = sbf.toString();
    
            } catch (Exception e) {
    
                e.printStackTrace();
    
            }
    
            return result;
    
        }
    
        /**
         * @Title: unicodeDecode
         * @Description: unicode解码
         * @param string
         * @return
         */
        public static String unicodeDecode(String string) {
            Pattern pattern = Pattern.compile("(\\u(\p{XDigit}{4}))");
            Matcher matcher = pattern.matcher(string);
            char ch;
            while (matcher.find()) {
                ch = (char) Integer.parseInt(matcher.group(2), 16);
                string = string.replace(matcher.group(1), ch + "");
            }
            return string;
        }
    }
    
    
    
  • 相关阅读:
    springboot + driud连接池踩的坑____新手学习
    tomcat的安装
    无限极分类
    javascript ECMAscript 和node.js commonJs之间的关系
    变量名,引用和地址
    java中闭包的理解
    thinkphp 模型的curd
    thinkphp之migration 迁移文件的使用
    验证ArrayList是线程不安全的集合
    一个java小程序,盗取插入的U盘中的数据。
  • 原文地址:https://www.cnblogs.com/ljincheng/p/14062822.html
Copyright © 2011-2022 走看看