From 003193d95acb645346d03e7080039de1d32c0ab8 Mon Sep 17 00:00:00 2001 From: Hydromel <1440265357@qq.com> Date: Tue, 4 Mar 2025 15:32:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E4=BF=A1=EF=BC=9A=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E6=8B=8D=E7=85=A7=E6=97=B6=E9=97=B4=E8=A1=A8?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BF=AE=E6=94=B9=EF=BC=8C=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E6=8B=8D=E7=85=A7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mpmaster/build.gradle | 2 +- .../com/xypower/mpmaster/sms/SimUtil.java | 204 ++++++++++-------- .../mpmaster/sms/UpdateSysConfigUtil.java | 17 +- .../xypower/mpmaster/sms/ValueTypeUtil.java | 23 +- 4 files changed, 153 insertions(+), 93 deletions(-) diff --git a/mpmaster/build.gradle b/mpmaster/build.gradle index ac9e5d59..672c1037 100644 --- a/mpmaster/build.gradle +++ b/mpmaster/build.gradle @@ -4,7 +4,7 @@ plugins { def AppMajorVersion = 1 def AppMinorVersion = 1 -def AppBuildNumber = 1 +def AppBuildNumber = 2 def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java index 4dde7d55..801a19fe 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java @@ -81,7 +81,6 @@ public class SimUtil { } int slot = smsInfo.getSlot();//那张卡收到的短信 String sender = smsInfo.getSender();//收到的短信的手机号 - String sendmessage = "ERROR";//要回复的短信 List abslist = new ArrayList<>();//收到的短信内容拆分包装成数组 boolean ifmessageCorrect = false;//用来判断收到的短信内容是否正确 if (StringUtils.isEmpty(content)) { @@ -122,21 +121,21 @@ public class SimUtil { String s = split1[1]; String[] split2 = StringUtils.splitString2(s); int spilt2len = split2.length; - if (split2 != null && spilt2len > 1 && spilt2len % 2 == 1) { + if (split2 != null && spilt2len > 0) { String num = split2[0]; Integer integer = StringUtils.convert2Int(num); if (integer != null) { if (integer == 0) {//删除所有运维 ifmessageCorrect = true; } else { - if (spilt2len == integer * 2 + 1) { - int times = 0; - for (int i = 0; i < spilt2len; i++) { - if (i == 0) { - continue; - } - String ts = split2[i]; - Integer time = StringUtils.convert2Int(ts); + int times = 0; + for (int i = 0; i < spilt2len; i++) { + if (i == 0) { + continue; + } + String ts = split2[i]; + Integer time = StringUtils.convert2Int(ts); + if (time != null) { if (i % 2 == 1) { if (time > 23) { ifmessageCorrect = false; @@ -181,11 +180,14 @@ public class SimUtil { 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(context, integer); + String[] strings = StringUtils.splitString2(s); + if (strings != null && strings.length >= 1) { + Integer integer = StringUtils.convert2Int(strings[0]); + if (integer != null) { + if (integer == 0 || integer == 1) { + ifmessageCorrect = true; + UpdateSysConfigUtil.setMntnMode(context, integer); + } } } } @@ -230,8 +232,14 @@ public class SimUtil { String[] split1 = StringUtils.splitString1(content); if (split1 != null && split1.length > 1) { ifmessageCorrect = true; - String cmdid = split1[1]; - UpdateSysConfigUtil.setCmdid(context, cmdid); + String s = split1[1]; + String[] strings = StringUtils.splitString2(s); + if (strings != null && strings.length >= 1) { + String cmdid = strings[0]; + if (cmdid != null) { + UpdateSysConfigUtil.setCmdid(context, cmdid); + } + } } sendmessage = getSendString(content, ifmessageCorrect); } else if (content.contains(SmsTypeEnum.GET_CMDID.value())) { @@ -242,32 +250,32 @@ public class SimUtil { restartType = 1; String[] split1 = StringUtils.splitString1(content); if (split1 != null && split1.length > 1) { + String server = null; + Integer port = null; + Integer utcp = null; + Integer encrypto = null; String s = split1[1]; String[] split2 = StringUtils.splitString2(s); - if (split2 != null && (split2.length == 2 || split2.length == 4)) { - String server; - Integer integer; - server = split2[0]; - String port = split2[1]; - integer = StringUtils.convert2Int(port); - Integer utcp = -1; - Integer encrypto = -1; - if (integer != null) { - ifmessageCorrect = true; - if (split2.length == 4) { - String s1 = split2[2]; - utcp = StringUtils.convert2Int(s1); - utcp = getUtcp(utcp); - String s2 = split2[3]; - encrypto = StringUtils.convert2Int(s2); - encrypto = getEncrypto(encrypto); - if (utcp == -1 || encrypto == -1) { - ifmessageCorrect = false; - } - } + if (split2 != null && split2.length > 1) { + ifmessageCorrect = true; + if (split2.length > 0) { + server = split2[0]; + } + if (split2.length > 1) { + String s1 = split2[1]; + port = StringUtils.convert2Int(s1); + } + if (split2.length > 2) { + String s2 = split2[2]; + utcp = StringUtils.convert2Int(s2); + utcp = getUtcp(utcp); + } + if (split2.length > 3) { + String s3 = split2[3]; + encrypto = StringUtils.convert2Int(s3); } if (ifmessageCorrect) { - UpdateSysConfigUtil.setIP(context, server, integer, utcp, encrypto); + UpdateSysConfigUtil.setIP(context, server, port, utcp, encrypto); } } } @@ -279,13 +287,13 @@ public class SimUtil { restartType = 1; String[] split1 = StringUtils.splitString1(content); sendmessage = getSendString(content, ifmessageCorrect); - if (split1 != null && split1.length == 2) { + if (split1 != null && split1.length >= 2) { ifmessageCorrect = true; JSONObject osdmap = new JSONObject(); String s = split1[1]; String[] split2 = StringUtils.splitString2(s); int spilt2len = split2.length; - if (split2 != null && spilt2len > 1 && spilt2len % 2 == 1) { + if (split2 != null && spilt2len > 1) { String num = split2[0]; Integer integer = StringUtils.convert2Int(num); if (integer != null) { @@ -417,7 +425,7 @@ public class SimUtil { if (split1 != null && split1.length > 1) { String s = split1[1]; String[] split2 = StringUtils.splitString2(s); - if (split2 != null && split2.length == 2) { + if (split2 != null && split2.length > 1) { Integer channel = StringUtils.convert2Int(split2[0]); if (channel != null) { ifmessageCorrect = true; @@ -430,17 +438,21 @@ public class SimUtil { } else if (content.contains(SmsTypeEnum.GET_PHOTO_SCHEDULE_LIST.value())) { String[] split1 = StringUtils.splitString1(content); if (split1 != null && split1.length == 2) { - Integer channel = StringUtils.convert2Int(split1[1]); - String photoSchedules = UpdateSysConfigUtil.getPhotoSchedules(channel); - sendmessage = SmsTypeEnum.GET_PHOTO_SCHEDULE_LIST.value() + "=" + photoSchedules; + String s = split1[1]; + String[] strings = StringUtils.splitString2(s); + if (strings != null && strings.length >= 1) { + Integer integer = StringUtils.convert2Int(strings[0]); + String photoSchedules = UpdateSysConfigUtil.getPhotoSchedules(integer); + sendmessage = SmsTypeEnum.GET_PHOTO_SCHEDULE_LIST.value() + "=" + photoSchedules; + } } } else if (content.contains(SmsTypeEnum.SET_RESOLUTION.value())) { restartType = 1; 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 == 5) { + String[] split2 = StringUtils.splitString2(s); + if (split2 != null && split2.length >= 5) { Integer channel = StringUtils.convert2Int(split2[0]); Integer resolutionCX = StringUtils.convert2Int(split2[1]); Integer resolutionCY = StringUtils.convert2Int(split2[2]); @@ -465,19 +477,23 @@ public class SimUtil { sendmessage = SmsTypeEnum.GET_RESOLUTION.value() + "=" + resolutionCX + "," + resolutionCY + "," + videoCX + "," + videoCY; } else if (content.contains(SmsTypeEnum.TAKE_PHOTO.value())) { String[] split = StringUtils.splitString1(content); - if (split != null && split.length == 3) { - ifmessageCorrect = true; - Integer channel = StringUtils.convert2Int(split[0]); - Integer preset = StringUtils.convert2Int(split[1]); - Integer type = StringUtils.convert2Int(split[2]); - if (channel != null) { - boolean photoOrVideo; - if (type == 0) { - photoOrVideo = true; - } else { - photoOrVideo = false; + if (split != null && split.length > 1) { + String s = split[1]; + String[] strings = StringUtils.splitString2(s); + if (strings != null && strings.length >= 3) { + ifmessageCorrect = true; + Integer channel = StringUtils.convert2Int(strings[0]); + Integer preset = StringUtils.convert2Int(strings[1]); + Integer type = StringUtils.convert2Int(strings[2]); + if (channel != null && preset != null && type != null) { + boolean photoOrVideo; + if (type == 0) { + photoOrVideo = true; + } else { + photoOrVideo = false; + } + UpdateSysConfigUtil.takePhotoOrVideo(context, channel, preset, photoOrVideo); } - UpdateSysConfigUtil.takePhotoOrVideo(context, channel, preset, photoOrVideo); } sendmessage = getSendString(content, ifmessageCorrect); } @@ -487,8 +503,11 @@ public class SimUtil { if (split1 != null && split1.length == 2) { ifmessageCorrect = true; String s = split1[1]; - Integer integer = StringUtils.convert2Int(s); - UpdateSysConfigUtil.setHB(context, integer); + String[] strings = StringUtils.splitString2(s); + if (strings != null && strings.length >= 1) { + Integer integer = StringUtils.convert2Int(strings[0]); + UpdateSysConfigUtil.setHB(context, integer); + } } sendmessage = getSendString(content, ifmessageCorrect); } else if (content.contains(SmsTypeEnum.GET_HEART.value())) { @@ -505,8 +524,11 @@ public class SimUtil { if (split1 != null && split1.length == 2) { ifmessageCorrect = true; String s = split1[1]; - Integer integer = StringUtils.convert2Int(s); - UpdateSysConfigUtil.setTB(context, integer); + String[] strings = StringUtils.splitString2(s); + if (strings != null && strings.length >= 1) { + Integer integer = StringUtils.convert2Int(strings[0]); + UpdateSysConfigUtil.setTB(context, integer); + } } sendmessage = getSendString(content, ifmessageCorrect); } else if (content.contains(SmsTypeEnum.GET_TP.value())) { @@ -518,8 +540,11 @@ public class SimUtil { if (split1 != null && split1.length == 2) { ifmessageCorrect = true; String s = split1[1]; - Integer integer = StringUtils.convert2Int(s); - UpdateSysConfigUtil.setPackage(context, integer); + String[] strings = StringUtils.splitString2(s); + if (strings != null && strings.length > 0) { + Integer integer = StringUtils.convert2Int(strings[0]); + UpdateSysConfigUtil.setPackage(context, integer); + } } sendmessage = getSendString(content, ifmessageCorrect); } else if (content.contains(SmsTypeEnum.GET_PACKAGE.value())) { @@ -557,21 +582,35 @@ public class SimUtil { return apputcp; } - private static int getEncrypto(Integer encrypto) { - int appencrypto = -1; - //短信文档中 1:密文,2:明文 3:不加密 app应用中 0:不加密 1:明文 2:加密 所以需要转换一下 - if (encrypto != null && (encrypto == 1 || encrypto == 2 || encrypto == 3)) { - if (encrypto == 1) { - appencrypto = 2; - } else if (encrypto == 2) { - appencrypto = 1; - } else if (encrypto == 3) { - appencrypto = 0; + public static int getSmsUtcp(Integer apputcp) { + int smsutcp = -1; + //短信文档中 0:udp 1:tcp app应用中 0:tcp 1:udp 所以需要转换一下 + if (apputcp != null && (apputcp == 0 || apputcp == 1)) { + if (apputcp == 0) { + smsutcp = 1; + } else if (apputcp == 1) { + smsutcp = 0; } } - return appencrypto; + return smsutcp; } +// private static int getEncrypto(Integer encrypto) { +// int appencrypto = -1; +// //短信文档中 1:密文,2:明文 3:不加密 app应用中 0:不加密 1:明文 2:加密 所以需要转换一下 +// if (encrypto != null && (encrypto == 1 || encrypto == 2 || encrypto == 3)) { +// if (encrypto == 1) { +// appencrypto = 2; +// } else if (encrypto == 2) { +// appencrypto = 1; +// } else if (encrypto == 3) { +// appencrypto = 0; +// } +// } +// return appencrypto; +// } + + private static String getSendString(String content, boolean ifmessageCorrect) { String sendmessage; String menssageBack = ""; @@ -774,19 +813,14 @@ public class SimUtil { } else if (configType == 3) { //数组 JSONArray objects = new JSONArray(configValue); JSONUtils.updateConfigFile(filePath, fileName, configName, configType, objects); + } else if (configType == 4) { //对象 + JSONObject objects = new JSONObject(configValue); + JSONUtils.updateConfigFile(filePath, fileName, configName, configType, objects); } } else { ifmessageCorrect = false; } } -// if (rebootMpApp != 0) { -// MicroPhotoContext.restartMpApp(context, "Config Updated From SMS"); -// } else { -// Intent intent = new Intent(); -// intent.setAction(MicroPhotoContext.ACTION_UPDATE_CONFIGS_MP); -// intent.setPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP); -// context.sendBroadcast(intent); -// } } else { ifmessageCorrect = false; } @@ -901,6 +935,8 @@ public class SimUtil { HashMap hashMap = ValueTypeUtil.checkFilePathAndName(fileType); filePath = hashMap.get(UpdateSysConfigUtil.FILEPATH); fileName = hashMap.get(UpdateSysConfigUtil.FILENAME); + + if (!TextUtils.isEmpty(filePath + fileName)) { File file = new File(filePath + fileName); if (file.exists()) { diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/UpdateSysConfigUtil.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/UpdateSysConfigUtil.java index dccdc568..8616c942 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/UpdateSysConfigUtil.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/UpdateSysConfigUtil.java @@ -166,14 +166,18 @@ public class UpdateSysConfigUtil { } //修改app的ip - public static void setIP(Context context, String server, int port, int utcp, int encrypto) { + public static void setIP(Context context, String server, Integer port, Integer utcp, Integer encrypto) { MicroPhotoContext.AppConfig mpAppConfig = MicroPhotoContext.getMpAppConfig(context); + if (server!=null) { mpAppConfig.server = server; + } + if (port!=null && port!=-1) { mpAppConfig.port = port; - if (utcp != -1) { + } + if (utcp != null&& utcp!=-1 ) { mpAppConfig.networkProtocol = utcp; } - if (encrypto != -1) { + if (encrypto != null&& encrypto!=-1) { mpAppConfig.encryption = encrypto; } MicroPhotoContext.saveMpAppConfig(context, mpAppConfig); @@ -186,8 +190,9 @@ public class UpdateSysConfigUtil { String server = mpAppConfig.server; int port = mpAppConfig.port; int networkProtocol = mpAppConfig.networkProtocol; + int smsUtcp = SimUtil.getSmsUtcp(networkProtocol); int encryption = mpAppConfig.encryption; - return server + "," + port + "," + networkProtocol + "," + encryption; + return server + "," + port + "," + smsUtcp + "," + encryption; } //修改app的心跳 @@ -372,8 +377,8 @@ public class UpdateSysConfigUtil { List schedules = new ArrayList<>(); long ts = System.currentTimeMillis() / 1000; long val = 0; - val |= (channel << 16); - val |= (preset << 8); + val |= (channel << 12); + val |= (preset << 4); val |= photoOrVideo ? 0L : 1L; schedules.add(Long.valueOf(val)); diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/ValueTypeUtil.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/ValueTypeUtil.java index f9a8248d..a702e4b0 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/ValueTypeUtil.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/ValueTypeUtil.java @@ -1,10 +1,13 @@ package com.xypower.mpmaster.sms; +import android.os.Environment; + import com.xypower.common.MicroPhotoContext; import org.json.JSONArray; +import java.io.File; import java.util.HashMap; public class ValueTypeUtil { @@ -37,18 +40,34 @@ public class ValueTypeUtil { * * */ public static HashMap checkFilePathAndName( int fileType) { + String path = Environment.getExternalStorageDirectory().getAbsolutePath(); + if (!path.endsWith(File.separator)) { + path += File.separator; + } HashMap hashMap = new HashMap<>(); String filePath = null; String fileName = null; switch (fileType) { case 1: - filePath =MicroPhotoContext.PACKAGE_NAME_MPAPP + "/data/"; + filePath =path+MicroPhotoContext.PACKAGE_NAME_MPAPP + "/data/"; fileName = "App.json"; break; case 2: filePath =MicroPhotoContext.PACKAGE_NAME_MPMASTER + "/data/"; fileName = "Master.json"; break; + case 81: + case 82: + case 83: + case 84: + case 85: + case 86: + case 87: + case 88: + case 89: + filePath =path+MicroPhotoContext.PACKAGE_NAME_MPAPP + "/data/schedules/"; + fileName = Integer.toString(fileType - 80); + break; case 91: case 92: case 93: @@ -58,7 +77,7 @@ public class ValueTypeUtil { case 97: case 98: case 99: - filePath =MicroPhotoContext.PACKAGE_NAME_MPAPP + "/data/channels/"; + filePath =path+MicroPhotoContext.PACKAGE_NAME_MPAPP + "/data/channels/"; fileName = Integer.toString(fileType - 90) + ".json"; break; default: