|
|
@ -16,8 +16,14 @@ import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.dev.devapi.api.SysApi;
|
|
|
|
|
|
|
|
import com.xypower.common.RegexUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
@ -37,39 +43,48 @@ public class SimUtil {
|
|
|
|
//自定义ACTION常数 作为广播的IntentFilter识别常数
|
|
|
|
//自定义ACTION常数 作为广播的IntentFilter识别常数
|
|
|
|
public static String SMS_SEND_ACTION = "com.xypower.mpmaster.SMS_SEND_ACTION";
|
|
|
|
public static String SMS_SEND_ACTION = "com.xypower.mpmaster.SMS_SEND_ACTION";
|
|
|
|
public static String SMSTYPE = "smstype";
|
|
|
|
public static String SMSTYPE = "smstype";
|
|
|
|
|
|
|
|
public static String SMSDATA = "smsdata";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String SMSIFCORRECT = "smsifcorrect";
|
|
|
|
|
|
|
|
|
|
|
|
//短信解析
|
|
|
|
//短信解析
|
|
|
|
public static void analysisSMSInfo(Intent intent, Context context) {
|
|
|
|
public static void analysisSMSInfo(Intent intent, Context context) {
|
|
|
|
SmsMessageModel smsInfo = getSMSInfo(intent);
|
|
|
|
SmsMessageModel smsInfo = getSMSInfo(intent);
|
|
|
|
if (smsInfo != null) {
|
|
|
|
if (smsInfo != null) {
|
|
|
|
|
|
|
|
String packageName = context.getApplicationContext().getPackageName();
|
|
|
|
String content = smsInfo.getContent();
|
|
|
|
String content = smsInfo.getContent();
|
|
|
|
int slot = smsInfo.getSlot();
|
|
|
|
int slot = smsInfo.getSlot();//那张卡收到的短信
|
|
|
|
String sender = smsInfo.getSender();
|
|
|
|
String sender = smsInfo.getSender();//收到的短信的手机号
|
|
|
|
String sendmessage = "";
|
|
|
|
String sendmessage = "";//要回复的短信
|
|
|
|
String sendtype = "";
|
|
|
|
String sendtype = "";//收到的短信类型
|
|
|
|
|
|
|
|
JSONArray jsonArray = new JSONArray();//收到的短信内容拆分包装成数组
|
|
|
|
|
|
|
|
boolean ifmessageCorrect = false;//用来判断收到的短信内容是否正确
|
|
|
|
if (StringUtils.isEmpty(content)) {
|
|
|
|
if (StringUtils.isEmpty(content)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (content.contains(SmsTypeEnum.REBOOT1.value())) {
|
|
|
|
if (content.contains(SmsTypeEnum.REBOOT1.value())) {
|
|
|
|
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
sendmessage = content + " OK";
|
|
|
|
sendmessage = content + " OK";
|
|
|
|
sendtype = SmsTypeEnum.REBOOT1.value();
|
|
|
|
sendtype = SmsTypeEnum.REBOOT1.value();
|
|
|
|
} else if (content.contains(SmsTypeEnum.REBOOT2.value())) {
|
|
|
|
} else if (content.contains(SmsTypeEnum.REBOOT2.value())) {
|
|
|
|
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
sendmessage = content + " OK";
|
|
|
|
sendmessage = content + " OK";
|
|
|
|
sendtype = SmsTypeEnum.REBOOT2.value();
|
|
|
|
sendtype = SmsTypeEnum.REBOOT2.value();
|
|
|
|
} else if (content.contains(SmsTypeEnum.SET_YW_SCHEDULE.value())) {
|
|
|
|
} else if (content.contains(SmsTypeEnum.SET_YW_SCHEDULE.value())) {
|
|
|
|
String packageName = context.getApplicationContext().getPackageName();
|
|
|
|
|
|
|
|
String[] split1 = StringUtils.splitString1(content);
|
|
|
|
String[] split1 = StringUtils.splitString1(content);
|
|
|
|
if (split1 != null && split1.length > 1) {
|
|
|
|
if (split1 != null && split1.length > 1) {
|
|
|
|
String s = split1[1];
|
|
|
|
String s = split1[1];
|
|
|
|
String[] split2 = StringUtils.splitString2(s);
|
|
|
|
String[] split2 = StringUtils.splitString2(s);
|
|
|
|
if (split2 != null && split2.length >= 1) {
|
|
|
|
if (split2 != null && split2.length >= 1) {
|
|
|
|
|
|
|
|
int length = split2.length;
|
|
|
|
|
|
|
|
if (length % 2 == 1) {
|
|
|
|
String num = split2[0];
|
|
|
|
String num = split2[0];
|
|
|
|
Integer integer = StringUtils.convert2Int(num);
|
|
|
|
Integer integer = StringUtils.convert2Int(num);
|
|
|
|
if (integer != null) {
|
|
|
|
if (integer != null) {
|
|
|
|
if (integer == 0) {//删除所有运维
|
|
|
|
if (integer == 0) {//删除所有运维
|
|
|
|
UpdateSysConfigUtil.updateAbsHeartbeats(packageName, new JSONArray());
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
|
if (length == integer + 1) {
|
|
|
|
int times = 0;
|
|
|
|
int times = 0;
|
|
|
|
for (int i = 0; i < split2.length; i++) {
|
|
|
|
for (int i = 0; i < split2.length; i++) {
|
|
|
|
if (i == 0) {
|
|
|
|
if (i == 0) {
|
|
|
@ -78,22 +93,135 @@ public class SimUtil {
|
|
|
|
String ts = split2[i];
|
|
|
|
String ts = split2[i];
|
|
|
|
Integer time = StringUtils.convert2Int(ts);
|
|
|
|
Integer time = StringUtils.convert2Int(ts);
|
|
|
|
if (i % 2 == 1) {
|
|
|
|
if (i % 2 == 1) {
|
|
|
|
time = 0;
|
|
|
|
if (time > 23) {
|
|
|
|
|
|
|
|
ifmessageCorrect = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
times = time * 3600;
|
|
|
|
times = time * 3600;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (time > 59) {
|
|
|
|
|
|
|
|
ifmessageCorrect = false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
times += time * 60;
|
|
|
|
times += time * 60;
|
|
|
|
jsonArray.put(times);
|
|
|
|
jsonArray.put(times);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifmessageCorrect) {
|
|
|
|
|
|
|
|
UpdateSysConfigUtil.setAbsHeartbeats(packageName, jsonArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendmessage = content + " OK";
|
|
|
|
|
|
|
|
sendtype = SmsTypeEnum.REBOOT2.value();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendSms(context, slot, sender, sendmessage, sendtype);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String menssageBack = "";
|
|
|
|
|
|
|
|
if (ifmessageCorrect) {
|
|
|
|
|
|
|
|
menssageBack = " OK";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
menssageBack = " ERROR";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sendmessage = content + menssageBack;
|
|
|
|
|
|
|
|
sendtype = SmsTypeEnum.SET_YW_SCHEDULE.value();
|
|
|
|
|
|
|
|
} else if (content.contains(SmsTypeEnum.GET_YW_SCHEDULE.value())) {
|
|
|
|
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
|
|
|
|
JSONArray absHeartbeats = UpdateSysConfigUtil.getAbsHeartbeats(packageName);
|
|
|
|
|
|
|
|
if (absHeartbeats == null || absHeartbeats.length() == 0) {
|
|
|
|
|
|
|
|
sendmessage = SmsTypeEnum.GET_YW_SCHEDULE.value() + "=0";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
int length = absHeartbeats.length();
|
|
|
|
|
|
|
|
sendmessage = SmsTypeEnum.GET_YW_SCHEDULE.value() + "=" + length;
|
|
|
|
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
|
|
|
|
int mAbsHeartbeatTime = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
mAbsHeartbeatTime = absHeartbeats.getInt(i);
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int hour = mAbsHeartbeatTime / 3600;
|
|
|
|
|
|
|
|
int leftsecond = mAbsHeartbeatTime % 3600;
|
|
|
|
|
|
|
|
int minute = leftsecond / 3600;
|
|
|
|
|
|
|
|
sendmessage += "," + hour + "," + minute;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (content.contains(SmsTypeEnum.SET_OPERATE.value())) {
|
|
|
|
|
|
|
|
sendtype = SmsTypeEnum.SET_OPERATE.value();
|
|
|
|
|
|
|
|
String[] split1 = StringUtils.splitString1(content);
|
|
|
|
|
|
|
|
if (split1 != null && split1.length > 1) {
|
|
|
|
|
|
|
|
String s = split1[1];
|
|
|
|
|
|
|
|
Integer integer = StringUtils.convert2Int(s);
|
|
|
|
|
|
|
|
if (integer != null) {
|
|
|
|
|
|
|
|
if (integer == 0 || integer == 1) {
|
|
|
|
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
|
|
|
|
UpdateSysConfigUtil.setMntnMode(packageName, integer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String menssageBack = "";
|
|
|
|
|
|
|
|
if (ifmessageCorrect) {
|
|
|
|
|
|
|
|
menssageBack = " OK";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
menssageBack = " ERROR";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sendmessage = content + menssageBack;
|
|
|
|
|
|
|
|
} else if (content.contains(SmsTypeEnum.GET_OPERATE.value())) {
|
|
|
|
|
|
|
|
sendtype = SmsTypeEnum.GET_OPERATE.value();
|
|
|
|
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
|
|
|
|
int mntnMode = UpdateSysConfigUtil.getMntnMode(packageName);
|
|
|
|
|
|
|
|
sendmessage = SmsTypeEnum.GET_OPERATE + "=" + mntnMode;
|
|
|
|
|
|
|
|
} else if (content.contains(SmsTypeEnum.SET_OPERATE_URL.value())) {
|
|
|
|
|
|
|
|
sendtype = SmsTypeEnum.SET_OPERATE_URL.value();
|
|
|
|
|
|
|
|
String[] split1 = StringUtils.splitString1(content);
|
|
|
|
|
|
|
|
if (split1 != null && split1.length > 1) {
|
|
|
|
|
|
|
|
String s = split1[1];
|
|
|
|
|
|
|
|
String[] split2 = StringUtils.splitString1(s);
|
|
|
|
|
|
|
|
if (split2 != null && split2.length == 2) {
|
|
|
|
|
|
|
|
String ipAddress = split2[0];
|
|
|
|
|
|
|
|
String port = split2[1];
|
|
|
|
|
|
|
|
boolean b = RegexUtil.checkIpAddress(ipAddress);
|
|
|
|
|
|
|
|
if (b) {
|
|
|
|
|
|
|
|
Integer integer = StringUtils.convert2Int(port);
|
|
|
|
|
|
|
|
if (integer != null) {
|
|
|
|
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
|
|
|
|
UpdateSysConfigUtil.setMntnServer(packageName, ipAddress, integer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String menssageBack = "";
|
|
|
|
|
|
|
|
if (ifmessageCorrect) {
|
|
|
|
|
|
|
|
menssageBack = " OK";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
menssageBack = " ERROR";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sendmessage = content + menssageBack;
|
|
|
|
|
|
|
|
} else if (content.contains(SmsTypeEnum.GET_OPERATE_URL.value())) {
|
|
|
|
|
|
|
|
sendtype = SmsTypeEnum.GET_OPERATE.value();
|
|
|
|
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
|
|
|
|
String mntnServer = UpdateSysConfigUtil.getMntnServer(packageName);
|
|
|
|
|
|
|
|
sendmessage = SmsTypeEnum.GET_OPERATE + "=" + mntnServer;
|
|
|
|
|
|
|
|
} else if (content.contains(SmsTypeEnum.UPDATE.value())) {
|
|
|
|
|
|
|
|
sendtype = SmsTypeEnum.UPDATE.value();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String[] split1 = StringUtils.splitString1(content);
|
|
|
|
|
|
|
|
if (split1 != null && split1.length == 2) {
|
|
|
|
|
|
|
|
ifmessageCorrect = true;
|
|
|
|
|
|
|
|
String s = split1[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String menssageBack = "";
|
|
|
|
|
|
|
|
if (ifmessageCorrect) {
|
|
|
|
|
|
|
|
menssageBack = " OK";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
menssageBack = " ERROR";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sendmessage = content + menssageBack;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sendSms(context, slot, sender, sendmessage, sendtype, ifmessageCorrect, jsonArray);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//短信解析
|
|
|
|
//短信解析
|
|
|
@ -173,7 +301,7 @@ public class SimUtil {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//指定sim卡位置发送短信
|
|
|
|
//指定sim卡位置发送短信
|
|
|
|
public static void sendSms(Context mContext, int slot, String sender, String message, String value) {
|
|
|
|
public static void sendSms(Context mContext, int slot, String sender, String message, String value, boolean ifmessageCorrect, JSONArray jsonArray) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
|
|
|
SubscriptionManager localSubscriptionManager = SubscriptionManager.from(mContext);
|
|
|
|
SubscriptionManager localSubscriptionManager = SubscriptionManager.from(mContext);
|
|
|
|
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
@ -192,6 +320,8 @@ public class SimUtil {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Intent itSend = new Intent(SMS_SEND_ACTION);
|
|
|
|
Intent itSend = new Intent(SMS_SEND_ACTION);
|
|
|
|
itSend.putExtra(SMSTYPE, value);
|
|
|
|
itSend.putExtra(SMSTYPE, value);
|
|
|
|
|
|
|
|
itSend.putExtra(SMSIFCORRECT, ifmessageCorrect);
|
|
|
|
|
|
|
|
itSend.putExtra(SMSDATA, (Serializable) jsonArray);
|
|
|
|
//sendIntent参数为传送后接受的广播信息PendingIntent
|
|
|
|
//sendIntent参数为传送后接受的广播信息PendingIntent
|
|
|
|
PendingIntent sendPI = PendingIntent.getBroadcast(mContext, 0, itSend, 0);
|
|
|
|
PendingIntent sendPI = PendingIntent.getBroadcast(mContext, 0, itSend, 0);
|
|
|
|
|
|
|
|
|
|
|
|