|
@@ -0,0 +1,93 @@
|
|
|
+package cn.com.ctop.crawler.modules.core.util;
|
|
|
+
|
|
|
+import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 筋斗云接码平台对接
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class JindouyunMobileUtil {
|
|
|
+ public static final String domainUrl = "http://openapi.92jindou.com"; //域名
|
|
|
+ public static final String loginUrl = "/api/login"; //登录
|
|
|
+ public static final String getPhone = "/api/getPhone"; //获取手机号
|
|
|
+ public static final String getMessage = "/api/getMessage"; //获取验证码
|
|
|
+ public static final String cancelRecv = "/api/cancelRecv"; //释放号码
|
|
|
+ public static final String addBlacklist = "/api/addBlacklist"; //加黑号码
|
|
|
+ public static final String username = "xuzuoyun";
|
|
|
+ public static final String password = "heaven";
|
|
|
+
|
|
|
+ //登录
|
|
|
+ public static String login() throws Exception{
|
|
|
+ String login = domainUrl + loginUrl + "?userName=" + username + "&password=" + password;
|
|
|
+ String result = HttpUtils.httpGetRequest(login); //成功示例:0|c17d216a5d9a4494951e195e3093071f
|
|
|
+ if(result != null && result.startsWith("0")){
|
|
|
+ return result.split("\\|")[2];
|
|
|
+ }else{
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取号码
|
|
|
+ public static String getPhone(String sid, String token) throws Exception{
|
|
|
+ String phone = domainUrl + getPhone + "?sid=" + sid + "&token=" + token;
|
|
|
+ String result = HttpUtils.httpGetRequest(phone); //成功示例:0|手机号|运营商|省份|城市 0|16533852954|虚拟运营商|未知|未知|19359933
|
|
|
+ if(result != null && result.startsWith("1")){
|
|
|
+ return result.split("\\|")[1];
|
|
|
+ }else{
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取验证码
|
|
|
+ //返回0|后系统自动释放,以后不会再取到,无需再次加黑或释放,频繁重复调用可能导致账号被锁定
|
|
|
+ //相同手机号至少5秒请求一次,请求频繁可能导致账号被锁定
|
|
|
+ public static String getMessage(String sid, String phone, String token) throws Exception{
|
|
|
+ String message = domainUrl + getMessage + "?sid=" + sid + "&phone=" + phone + "&token=" + token;
|
|
|
+ String result = HttpUtils.httpGetRequest(message); //成功示例:0|您的验证码是123456|123456
|
|
|
+ if(result != null && result.startsWith("0")){
|
|
|
+ return result.split("\\|")[2];
|
|
|
+ }else{
|
|
|
+ log.error("获取验证码失败,错误结果为:{},sid{},phone:{},token:{}",result,sid,phone,token);
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //释放号码
|
|
|
+ public static String cancelRecv(String sid, String phone, String token) throws Exception{
|
|
|
+ String cancel = domainUrl + cancelRecv + "?sid=" + sid + "&phone=" + phone + "&token=" + token;
|
|
|
+ String result = HttpUtils.httpGetRequest(cancel);
|
|
|
+ if(result != null && result.startsWith("1")){
|
|
|
+ return result.split("\\|")[1];
|
|
|
+ }else{
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //加黑号码
|
|
|
+ public static String addBlacklist(String sid, String phone, String token) throws Exception{
|
|
|
+ String blackList = domainUrl + addBlacklist + "?sid=" + sid + "&phone=" + phone + "&token=" + token;
|
|
|
+ String result = HttpUtils.httpGetRequest(blackList);
|
|
|
+ if(result!=null && result.startsWith("\\|")){
|
|
|
+ return result.split("\\|")[1];
|
|
|
+ }else{
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ JindouyunMobileUtil j = new JindouyunMobileUtil();
|
|
|
+ try{
|
|
|
+ login();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|