360免費查詢手機號歸屬API地介面
阿新 • • 發佈:2020-11-30
介面地址: 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 + "\t"); fileWriter.write(httpArg + "\n\t"); 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("\r\n"); } 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; } }