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;
        }
    }
    
    
    
  • 相关阅读:
    内存泄漏 Memory Leaks 内存优化 MD
    Handler Thread 内部类引起内存泄露分析
    为什么不取消注册BroadcastReceiver会导致内存泄漏
    WebChromeClient 简介 API 案例
    WebViewClient 简介 API 案例
    java.net.URI 简介 文档 API
    android.net.Uri 简介 API
    RV 多样式 MultiType 聊天界面 消息类型 MD
    JS函数声明与定义,作用域,函数声明与表达式的区别
    CSS中table tr:nth-child(even)改变tr背景颜色: IE7,8无效
  • 原文地址:https://www.cnblogs.com/ljincheng/p/14062822.html
Copyright © 2011-2022 走看看