Skip to content

Instantly share code, notes, and snippets.

@zhengnan110
Last active July 31, 2017 07:37
Show Gist options
  • Save zhengnan110/00f967b053339c7a7359788ab4fcb087 to your computer and use it in GitHub Desktop.
Save zhengnan110/00f967b053339c7a7359788ab4fcb087 to your computer and use it in GitHub Desktop.
ttt
package utils;
import java.util.HashMap;
import java.util.Map;
/**
* Created by donlei on 2017/4/22.
*/
class SMSMoneyNotEnoughExp extends Exception {
}
class SMSNotLogin extends Exception {
}
public class AlzSms {
private static String token = "";
private static String API_URL = "http://api.hellotrue.com/api/do.php?";
private static String api_acct = "";
private static String pwd = "";
public static void Init(String api_acct, String pwd) {
AlzSms.api_acct = api_acct;
AlzSms.pwd = pwd;
}
public static void Login() throws Exception {
if (!"".equals(token) && token.length() > 3) {
return;
}
//api-riiectbn
// api-9u2j3w53
// 123456//test123456
String rsp = OkHttpClientManager.getAsString(API_URL + "action=loginIn&name=" + api_acct + "&password=" + pwd);
String[] ret = rsp.split("|");
if (ret.length == 2 && Integer.parseInt(ret[0]) == 1) {
token = ret[1].trim();
}
}
public static String GetPhoneNum() throws Exception {
if ("".equals(token)) {
throw new SMSNotLogin();
}
String rsp = OkHttpClientManager.getAsString(API_URL + "action=getPhone&sid=2471&token=" + token);
String[] ret = rsp.split("|");
if (ret.length == 2) {
if (Integer.parseInt(ret[0]) == 1) {
return ret[1].trim();
} else {
if (ret[1].contains("超出频率") || ret[1].contains("系统暂时没有可用号码")) {
Thread.sleep(3000);
return "";
}
if (ret[1].contains("余额不足")) {
throw new SMSMoneyNotEnoughExp();
}
}
}
return "";
}
public static String GetPhoneCode(String phone) throws Exception {
if ("".equals(token)) {
throw new SMSNotLogin();
}
String rsp = OkHttpClientManager.getAsString(API_URL + "action=getMessage&sid=2471&token=" + token + "&phone=" + phone);
String[] ret = rsp.split("|");
if (ret.length == 2) {
if (Integer.parseInt(ret[0]) == 1) {
return ret[1].trim();
} else {
if (ret[1].contains("超出频率") || ret[1].contains("系统暂时没有可用号码")) {
Thread.sleep(3000);
return "";
}
if (ret[1].contains("余额不足")) {
throw new SMSMoneyNotEnoughExp();
}
}
}
return "";
}
public static String AddBlack(String phone) throws Exception {
if ("".equals(token)) {
throw new SMSNotLogin();
}
String rsp = OkHttpClientManager.getAsString(API_URL + "action=addBlacklist&sid=2471&token=" + token + "&phone=" + phone);
String[] ret = rsp.split("|");
if (ret.length == 2) {
if (Integer.parseInt(ret[0]) == 1) {
return ret[1].trim();
} else {
if (ret[1].contains("超出频率") || ret[1].contains("系统暂时没有可用号码")) {
Thread.sleep(3000);
return "";
}
if (ret[1].contains("余额不足")) {
throw new SMSMoneyNotEnoughExp();
}
}
}
return "";
}
public static String ReleasePhone(String phone) throws Exception {
if ("".equals(token)) {
throw new SMSNotLogin();
}
String rsp = OkHttpClientManager.getAsString(API_URL + "action=cancelRecv&sid=2471&token=" + token + "&phone=" + phone);
String[] ret = rsp.split("|");
if (ret.length == 2) {
if (Integer.parseInt(ret[0]) == 1) {
return ret[1].trim();
} else {
if (ret[1].contains("超出频率") || ret[1].contains("系统暂时没有可用号码")) {
Thread.sleep(3000);
return "";
}
if (ret[1].contains("余额不足")) {
throw new SMSMoneyNotEnoughExp();
}
}
}
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment