新增:转发规则上支持配置正则替换内容

This commit is contained in:
pppscn 2021-12-03 12:54:38 +08:00
parent 6a02047162
commit e9e29944c6
13 changed files with 332 additions and 79 deletions

View File

@ -2,7 +2,7 @@
# SmsForwarder (短信转发器)
[![GitHub release](https://img.shields.io/github/release/pppscn/SmsForwarder.svg)](https://github.com/pppscn/SmsForwarder/releases) [![GitHub stars](https://img.shields.io/github/stars/pppscn/SmsForwarder)](https://github.com/pppscn/SmsForwarder/stargazers) [![GitHub forks](https://img.shields.io/github/forks/pppscn/SmsForwarder)](https://github.com/pppscn/SmsForwarder/network/members) [![GitHub issues](https://img.shields.io/github/issues/pppscn/SmsForwarder)](https://github.com/pppscn/SmsForwarder/issues) [![GitHub license](https://img.shields.io/github/license/pppscn/SmsForwarder)](https://github.com/pppscn/SmsForwarder/blob/main/LICENSE)
[![GitHub release](https://img.shields.io/github/release/pppscn/SmsForwarder.svg)](https://github.com/pppscn/SmsForwarder/releases) [![GitHub stars](https://img.shields.io/github/stars/pppscn/SmsForwarder)](https://github.com/pppscn/SmsForwarder/stargazers) [![GitHub forks](https://img.shields.io/github/forks/pppscn/SmsForwarder)](https://github.com/pppscn/SmsForwarder/network/members) [![GitHub issues](https://img.shields.io/github/issues/pppscn/SmsForwarder)](https://github.com/pppscn/SmsForwarder/issues) [![GitHub license](https://img.shields.io/github/license/pppscn/SmsForwarder)](https://github.com/pppscn/SmsForwarder/blob/main/LICENSE)
短信转发器——监控Android手机短信、来电、APP通知并根据指定规则转发到其他手机钉钉机器人、企业微信群机器人、飞书机器人、企业微信应用消息、邮箱、bark、webhook、Telegram机器人、Server酱、PushPlus、手机短信等。
@ -82,6 +82,8 @@
- [x] 增加配置导出导入功能(一键克隆)
- [x] 监听其他APP通知信息并转发
- [x] 转发到PushPlus
- [x] 转发规则上允许自定义模板(留空则取全局设置)
- [x] 转发规则上支持配置正则替换内容
--------
@ -101,7 +103,6 @@
| 添加/编辑发送通道飞书机器人 | 增加配置导出导入功能(一键克隆) | 监听其他APP通知信息并转发 | 获取所有应用列表方便复制APP包名|
| ![添加/编辑发送通道飞书](pic/senderfeishu.png "添加/编辑发送通道飞书") | ![增加配置导出导入功能(一键克隆)](pic/clone.png "增加配置导出导入功能(一键克隆)") | ![监听其他APP通知信息并转发](pic/app_notify.png "监听其他APP通知信息并转发") | ![获取所有应用列表方便复制APP包名](pic/app_list.png "获取所有应用列表方便复制APP包名") |
--------
## 反馈与建议:

View File

@ -227,6 +227,14 @@ public class RuleActivity extends AppCompatActivity {
textSmsTemplate.setText(ruleModel.getSmsTemplate());
}
//正则替换
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switchRegexReplace = view1.findViewById(R.id.switch_regex_replace);
EditText textRegexReplace = view1.findViewById(R.id.text_regex_replace);
if (ruleModel != null) {
switchRegexReplace.setChecked(ruleModel.getSwitchRegexReplace());
textRegexReplace.setText(ruleModel.getRegexReplace());
}
Button buttonRuleOk = view1.findViewById(R.id.buttonRuleOk);
Button buttonRuleDel = view1.findViewById(R.id.buttonRuleDel);
Button buttonRuleTest = view1.findViewById(R.id.buttonRuleTest);
@ -241,6 +249,15 @@ public class RuleActivity extends AppCompatActivity {
Toast.makeText(RuleActivity.this, R.string.new_sender_first, Toast.LENGTH_LONG).show();
return;
}
//检查正则替换填写是否正确
String regexReplace = textRegexReplace.getText().toString().trim();
int lineNum = checkRegexReplace(regexReplace);
if (lineNum > 0) {
Toast.makeText(getBaseContext(), String.format(RuleActivity.this.getString(R.string.regex_check_tips), lineNum), Toast.LENGTH_SHORT).show();
return;
}
int radioGroupRuleCheckId = Math.max(radioGroupRuleCheck.getCheckedRadioButtonId(), radioGroupRuleCheck2.getCheckedRadioButtonId());
Log.d(TAG, radioGroupRuleCheck.getCheckedRadioButtonId() + " " + radioGroupRuleCheck2.getCheckedRadioButtonId() + " " + radioGroupRuleCheckId);
if (ruleModel == null) {
@ -252,6 +269,8 @@ public class RuleActivity extends AppCompatActivity {
newRuleModel.setValue(editTextRuleValue.getText().toString().trim());
newRuleModel.setSwitchSmsTemplate(switchSmsTemplate.isChecked());
newRuleModel.setSmsTemplate(textSmsTemplate.getText().toString().trim());
newRuleModel.setSwitchRegexReplace(switchRegexReplace.isChecked());
newRuleModel.setRegexReplace(regexReplace);
newRuleModel.setSenderId(Long.valueOf(senderId.toString()));
RuleUtil.addRule(newRuleModel);
initRules();
@ -263,6 +282,8 @@ public class RuleActivity extends AppCompatActivity {
ruleModel.setValue(editTextRuleValue.getText().toString().trim());
ruleModel.setSwitchSmsTemplate(switchSmsTemplate.isChecked());
ruleModel.setSmsTemplate(textSmsTemplate.getText().toString().trim());
ruleModel.setSwitchRegexReplace(switchRegexReplace.isChecked());
ruleModel.setRegexReplace(regexReplace);
ruleModel.setSenderId(Long.valueOf(senderId.toString()));
RuleUtil.updateRule(ruleModel);
initRules();
@ -288,6 +309,14 @@ public class RuleActivity extends AppCompatActivity {
return;
}
//检查正则替换填写是否正确
String regexReplace = textRegexReplace.getText().toString().trim();
int lineNum = checkRegexReplace(regexReplace);
if (lineNum > 0) {
Toast.makeText(getBaseContext(), String.format(RuleActivity.this.getString(R.string.regex_check_tips), lineNum), Toast.LENGTH_SHORT).show();
return;
}
int radioGroupRuleCheckId = Math.max(radioGroupRuleCheck.getCheckedRadioButtonId(), radioGroupRuleCheck2.getCheckedRadioButtonId());
if (ruleModel == null) {
RuleModel newRuleModel = new RuleModel();
@ -296,6 +325,10 @@ public class RuleActivity extends AppCompatActivity {
newRuleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
newRuleModel.setValue(editTextRuleValue.getText().toString().trim());
newRuleModel.setSenderId(Long.valueOf(senderId.toString()));
newRuleModel.setSwitchSmsTemplate(switchSmsTemplate.isChecked());
newRuleModel.setSmsTemplate(textSmsTemplate.getText().toString().trim());
newRuleModel.setSwitchRegexReplace(switchRegexReplace.isChecked());
newRuleModel.setRegexReplace(regexReplace);
testRule(newRuleModel, Long.valueOf(senderId.toString()));
} else {
@ -304,6 +337,10 @@ public class RuleActivity extends AppCompatActivity {
ruleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
ruleModel.setValue(editTextRuleValue.getText().toString().trim());
ruleModel.setSenderId(Long.valueOf(senderId.toString()));
ruleModel.setSwitchSmsTemplate(switchSmsTemplate.isChecked());
ruleModel.setSmsTemplate(textSmsTemplate.getText().toString().trim());
ruleModel.setSwitchRegexReplace(switchRegexReplace.isChecked());
ruleModel.setRegexReplace(regexReplace);
testRule(ruleModel, Long.valueOf(senderId.toString()));
}
@ -370,6 +407,18 @@ public class RuleActivity extends AppCompatActivity {
textSmsTemplate.append("{{设备名称}}");
});
//正则替换
final LinearLayout layout_regex_replace = view1.findViewById(R.id.layout_regex_replace);
if (ruleModel != null) {
layout_regex_replace.setVisibility(ruleModel.getSwitchRegexReplace() ? View.VISIBLE : View.GONE);
}
switchRegexReplace.setOnCheckedChangeListener((buttonView, isChecked) -> {
layout_regex_replace.setVisibility(isChecked ? View.VISIBLE : View.GONE);
if (!isChecked) {
textRegexReplace.setText("");
}
});
}
//当更新选择的字段的时候更新之下各个选项的状态
@ -540,4 +589,17 @@ public class RuleActivity extends AppCompatActivity {
MobclickAgent.onPause(this);
}
private int checkRegexReplace(String regexReplace) {
if (regexReplace == null || regexReplace.isEmpty()) return 0;
int lineNum = 1;
String[] lineArray = regexReplace.split("\\n");
for (String line : lineArray) {
int position = line.indexOf("===");
if (position < 1) return lineNum;
lineNum++;
}
return 0;
}
}

View File

@ -83,6 +83,8 @@ public class RuleModel {
private String simSlot;
private boolean switchSmsTemplate;
private String smsTemplate;
private boolean switchRegexReplace;
private String regexReplace;
public static String getRuleMatch(String filed, String check, String value, String simSlot) {
String SimStr = SIM_SLOT_MAP.get(simSlot) + "";
@ -298,6 +300,10 @@ public class RuleModel {
return switchSmsTemplate;
}
public boolean getSwitchRegexReplace() {
return switchRegexReplace;
}
@NonNull
@Override
public String toString() {

View File

@ -20,5 +20,6 @@ public final class RuleTable {
public static final String COLUMN_NAME_TIME = "time";
public static final String COLUMN_NAME_SIM_SLOT = "sim_slot";
public static final String COLUMN_SMS_TEMPLATE = "sms_template";
public static final String COLUMN_REGEX_REPLACE = "regex_replace";
}
}

View File

@ -1,6 +1,7 @@
package com.idormy.sms.forwarder.model.vo;
import android.annotation.SuppressLint;
import android.util.Log;
import androidx.annotation.NonNull;
@ -30,22 +31,24 @@ public class SmsVo implements Serializable {
}
@SuppressLint("SimpleDateFormat")
public String getTitleForSend(String titleTemplate) {
public String getTitleForSend(String titleTemplate, String regexReplace) {
if (titleTemplate == null || titleTemplate.isEmpty()) titleTemplate = "{{来源号码}}";
String deviceMark = SettingUtil.getAddExtraDeviceMark().trim();
String versionName = SettingUtil.getVersionName();
return titleTemplate.replace("{{来源号码}}", mobile).replace("{{APP包名}}", mobile)
String titleForSend = titleTemplate.replace("{{来源号码}}", mobile).replace("{{APP包名}}", mobile)
.replace("{{短信内容}}", content).replace("{{通知内容}}", content)
.replace("{{卡槽信息}}", simInfo)
.replace("{{接收时间}}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date))
.replace("{{设备名称}}", deviceMark)
.replace("{{当前应用版本号}}", versionName)
.trim();
return RegexReplace(regexReplace, titleForSend);
}
@SuppressLint("SimpleDateFormat")
public String getSmsVoForSend(String ruleSmsTemplate) {
public String getSmsVoForSend(String ruleSmsTemplate, String regexReplace) {
String deviceMark = SettingUtil.getAddExtraDeviceMark().trim();
String customSmsTemplate = "{{来源号码}}\n{{短信内容}}\n{{卡槽信息}}\n{{接收时间}}\n{{设备名称}}";
@ -61,13 +64,37 @@ public class SmsVo implements Serializable {
}
String versionName = SettingUtil.getVersionName();
return customSmsTemplate.replace("{{来源号码}}", mobile).replace("{{APP包名}}", mobile)
String smsVoForSend = customSmsTemplate.replace("{{来源号码}}", mobile).replace("{{APP包名}}", mobile)
.replace("{{短信内容}}", content).replace("{{通知内容}}", content)
.replace("{{卡槽信息}}", simInfo)
.replace("{{接收时间}}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date))
.replace("{{设备名称}}", deviceMark)
.replace("{{当前应用版本号}}", versionName)
.trim();
return RegexReplace(regexReplace, smsVoForSend);
}
//正则替换内容
private String RegexReplace(String regexReplace, String Content) {
if (regexReplace == null || regexReplace.isEmpty()) return Content;
try {
String newContent = Content;
String[] lineArray = regexReplace.split("\\n");
for (String line : lineArray) {
String[] lineSplit = line.split("===");
if (lineSplit.length >= 1) {
String regex = lineSplit[0];
String replacement = lineSplit.length >= 2 ? lineSplit[1] : "";
newContent = newContent.replaceAll(regex, replacement);
}
}
return newContent;
} catch (Exception e) {
Log.e("RegexReplace", "获取接收手机号失败:" + e.getMessage());
return Content;
}
}
@NonNull

View File

@ -66,7 +66,8 @@ public class SendUtil {
) {
long logId = LogUtil.addLog(new LogModel(type, smsVo.getMobile(), smsVo.getContent(), smsVo.getSimInfo(), ruleModel.getId()));
String smsTemplate = ruleModel.getSwitchSmsTemplate() ? ruleModel.getSmsTemplate() : "";
SendUtil.senderSendMsgNoHandError(smsVo, senderModel, logId, smsTemplate);
String regexReplace = ruleModel.getSwitchRegexReplace() ? ruleModel.getRegexReplace() : "";
SendUtil.senderSendMsgNoHandError(smsVo, senderModel, logId, smsTemplate, regexReplace);
}
}
} catch (Exception e) {
@ -97,17 +98,18 @@ public class SendUtil {
throw new Exception("未找到发送通道");
}
for (SenderModel senderModel : senderModels
) {
SendUtil.senderSendMsg(handError, smsVo, senderModel, 0, "");
for (SenderModel senderModel : senderModels) {
String smsTemplate = ruleModel.getSwitchSmsTemplate() ? ruleModel.getSmsTemplate() : "";
String regexReplace = ruleModel.getSwitchRegexReplace() ? ruleModel.getRegexReplace() : "";
SendUtil.senderSendMsg(handError, smsVo, senderModel, 0, smsTemplate, regexReplace);
}
}
public static void senderSendMsgNoHandError(SmsVo smsVo, SenderModel senderModel, long logId, String smsTemplate) {
SendUtil.senderSendMsg(null, smsVo, senderModel, logId, smsTemplate);
public static void senderSendMsgNoHandError(SmsVo smsVo, SenderModel senderModel, long logId, String smsTemplate, String regexReplace) {
SendUtil.senderSendMsg(null, smsVo, senderModel, logId, smsTemplate, regexReplace);
}
public static void senderSendMsg(Handler handError, SmsVo smsVo, SenderModel senderModel, long logId, String smsTemplate) {
public static void senderSendMsg(Handler handError, SmsVo smsVo, SenderModel senderModel, long logId, String smsTemplate, String regexReplace) {
Log.i(TAG, "senderSendMsg smsVo:" + smsVo + "senderModel:" + senderModel);
switch (senderModel.getType()) {
@ -117,7 +119,7 @@ public class SendUtil {
DingDingSettingVo dingDingSettingVo = JSON.parseObject(senderModel.getJsonSetting(), DingDingSettingVo.class);
if (dingDingSettingVo != null) {
try {
SenderDingdingMsg.sendMsg(logId, handError, dingDingSettingVo.getToken(), dingDingSettingVo.getSecret(), dingDingSettingVo.getAtMobiles(), dingDingSettingVo.getAtAll(), smsVo.getSmsVoForSend(smsTemplate));
SenderDingdingMsg.sendMsg(logId, handError, dingDingSettingVo.getToken(), dingDingSettingVo.getSecret(), dingDingSettingVo.getAtMobiles(), dingDingSettingVo.getAtAll(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: dingding error " + e.getMessage());
@ -133,7 +135,7 @@ public class SendUtil {
if (emailSettingVo != null) {
try {
SenderMailMsg.sendEmail(logId, handError, emailSettingVo.getProtocol(), emailSettingVo.getHost(), emailSettingVo.getPort(), emailSettingVo.getSsl(), emailSettingVo.getFromEmail(), emailSettingVo.getNickname(),
emailSettingVo.getPwd(), emailSettingVo.getToEmail(), smsVo.getTitleForSend(emailSettingVo.getTitle()), smsVo.getSmsVoForSend(smsTemplate));
emailSettingVo.getPwd(), emailSettingVo.getToEmail(), smsVo.getTitleForSend(emailSettingVo.getTitle(), regexReplace), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: SenderMailMsg error " + e.getMessage());
@ -148,7 +150,7 @@ public class SendUtil {
BarkSettingVo barkSettingVo = JSON.parseObject(senderModel.getJsonSetting(), BarkSettingVo.class);
if (barkSettingVo != null) {
try {
SenderBarkMsg.sendMsg(logId, handError, barkSettingVo.getServer(), barkSettingVo.getIcon(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate), senderModel.getName());
SenderBarkMsg.sendMsg(logId, handError, barkSettingVo.getServer(), barkSettingVo.getIcon(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate, regexReplace), senderModel.getName());
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: SenderBarkMsg error " + e.getMessage());
@ -163,7 +165,7 @@ public class SendUtil {
WebNotifySettingVo webNotifySettingVo = JSON.parseObject(senderModel.getJsonSetting(), WebNotifySettingVo.class);
if (webNotifySettingVo != null) {
try {
SenderWebNotifyMsg.sendMsg(logId, handError, webNotifySettingVo.getWebServer(), webNotifySettingVo.getWebParams(), webNotifySettingVo.getSecret(), webNotifySettingVo.getMethod(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate));
SenderWebNotifyMsg.sendMsg(logId, handError, webNotifySettingVo.getWebServer(), webNotifySettingVo.getWebParams(), webNotifySettingVo.getSecret(), webNotifySettingVo.getMethod(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: SenderWebNotifyMsg error " + e.getMessage());
@ -178,7 +180,7 @@ public class SendUtil {
QYWXGroupRobotSettingVo qywxGroupRobotSettingVo = JSON.parseObject(senderModel.getJsonSetting(), QYWXGroupRobotSettingVo.class);
if (qywxGroupRobotSettingVo != null) {
try {
SenderQyWxGroupRobotMsg.sendMsg(logId, handError, qywxGroupRobotSettingVo.getWebHook(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate));
SenderQyWxGroupRobotMsg.sendMsg(logId, handError, qywxGroupRobotSettingVo.getWebHook(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: SenderQyWxGroupRobotMsg error " + e.getMessage());
@ -193,7 +195,7 @@ public class SendUtil {
QYWXAppSettingVo qYWXAppSettingVo = JSON.parseObject(senderModel.getJsonSetting(), QYWXAppSettingVo.class);
if (qYWXAppSettingVo != null) {
try {
SenderQyWxAppMsg.sendMsg(logId, handError, senderModel, qYWXAppSettingVo, smsVo.getSmsVoForSend(smsTemplate));
SenderQyWxAppMsg.sendMsg(logId, handError, senderModel, qYWXAppSettingVo, smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: qywx_app error " + e.getMessage());
@ -208,7 +210,7 @@ public class SendUtil {
ServerChanSettingVo serverChanSettingVo = JSON.parseObject(senderModel.getJsonSetting(), ServerChanSettingVo.class);
if (serverChanSettingVo != null) {
try {
SenderServerChanMsg.sendMsg(logId, handError, serverChanSettingVo.getSendKey(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate));
SenderServerChanMsg.sendMsg(logId, handError, serverChanSettingVo.getSendKey(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: SenderServerChanMsg error " + e.getMessage());
@ -223,7 +225,7 @@ public class SendUtil {
TelegramSettingVo telegramSettingVo = JSON.parseObject(senderModel.getJsonSetting(), TelegramSettingVo.class);
if (telegramSettingVo != null) {
try {
SenderTelegramMsg.sendMsg(logId, handError, telegramSettingVo.getApiToken(), telegramSettingVo.getChatId(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate));
SenderTelegramMsg.sendMsg(logId, handError, telegramSettingVo.getApiToken(), telegramSettingVo.getChatId(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: SenderTelegramMsg error " + e.getMessage());
@ -250,7 +252,7 @@ public class SendUtil {
simSlot = Integer.parseInt(smsVo.getSimInfo().substring(3, 4)) - 1;
Log.d(TAG, "simSlot = " + simSlot);
}
SenderSmsMsg.sendMsg(logId, handError, simSlot, smsSettingVo.getMobiles(), smsSettingVo.getOnlyNoNetwork(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate));
SenderSmsMsg.sendMsg(logId, handError, simSlot, smsSettingVo.getMobiles(), smsSettingVo.getOnlyNoNetwork(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: SenderSmsMsg error " + e.getMessage());
@ -265,7 +267,7 @@ public class SendUtil {
FeiShuSettingVo feiShuSettingVo = JSON.parseObject(senderModel.getJsonSetting(), FeiShuSettingVo.class);
if (feiShuSettingVo != null) {
try {
SenderFeishuMsg.sendMsg(logId, handError, feiShuSettingVo.getWebhook(), feiShuSettingVo.getSecret(), smsVo.getSmsVoForSend(smsTemplate));
SenderFeishuMsg.sendMsg(logId, handError, feiShuSettingVo.getWebhook(), feiShuSettingVo.getSecret(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: feishu error " + e.getMessage());
@ -280,7 +282,7 @@ public class SendUtil {
PushPlusSettingVo pushPlusSettingVo = JSON.parseObject(senderModel.getJsonSetting(), PushPlusSettingVo.class);
if (pushPlusSettingVo != null) {
try {
SenderPushPlusMsg.sendMsg(logId, handError, pushPlusSettingVo, smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate));
SenderPushPlusMsg.sendMsg(logId, handError, pushPlusSettingVo, smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate, regexReplace));
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: feishu error " + e.getMessage());

View File

@ -16,7 +16,7 @@ import java.util.List;
public class DbHelper extends SQLiteOpenHelper {
// If you change the database schema, you must increment the database version.
public static final String TAG = "DbHelper";
public static final int DATABASE_VERSION = 6;
public static final int DATABASE_VERSION = 7;
public static final String DATABASE_NAME = "sms_forwarder.db";
private static final List<String> SQL_CREATE_ENTRIES =
@ -104,6 +104,10 @@ public class DbHelper extends SQLiteOpenHelper {
sql = "Alter table " + LogTable.LogEntry.TABLE_NAME + " add column " + RuleTable.RuleEntry.COLUMN_NAME_TYPE + " TEXT NOT NULL DEFAULT 'sms' ";
db.execSQL(sql);
}
if (oldVersion < 7) { //转发规则添加正则替换内容
String sql = "Alter table " + RuleTable.RuleEntry.TABLE_NAME + " add column " + RuleTable.RuleEntry.COLUMN_REGEX_REPLACE + " TEXT NOT NULL DEFAULT '' ";
db.execSQL(sql);
}
}
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {

View File

@ -45,6 +45,7 @@ public class RuleUtil {
values.put(RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID, ruleModel.getSenderId());
values.put(RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT, ruleModel.getSimSlot());
values.put(RuleTable.RuleEntry.COLUMN_SMS_TEMPLATE, ruleModel.getSmsTemplate());
values.put(RuleTable.RuleEntry.COLUMN_REGEX_REPLACE, ruleModel.getRegexReplace());
// Insert the new row, returning the primary key value of the new row
@ -62,6 +63,7 @@ public class RuleUtil {
values.put(RuleTable.RuleEntry.COLUMN_NAME_SENDER_ID, ruleModel.getSenderId());
values.put(RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT, ruleModel.getSimSlot());
values.put(RuleTable.RuleEntry.COLUMN_SMS_TEMPLATE, ruleModel.getSmsTemplate());
values.put(RuleTable.RuleEntry.COLUMN_REGEX_REPLACE, ruleModel.getRegexReplace());
String selection = RuleTable.RuleEntry._ID + " = ? ";
String[] whereArgs = {String.valueOf(ruleModel.getId())};
@ -100,6 +102,7 @@ public class RuleUtil {
RuleTable.RuleEntry.COLUMN_NAME_TIME,
RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT,
RuleTable.RuleEntry.COLUMN_SMS_TEMPLATE,
RuleTable.RuleEntry.COLUMN_REGEX_REPLACE,
};
// Define 'where' part of query.
String selection = " 1 = 1 ";
@ -163,6 +166,8 @@ public class RuleUtil {
cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT));
String smsTemplate = cursor.getString(
cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_SMS_TEMPLATE));
String regexReplace = cursor.getString(
cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_REGEX_REPLACE));
Log.d(TAG, "getRule: itemId" + itemId);
RuleModel ruleModel = new RuleModel();
@ -176,6 +181,8 @@ public class RuleUtil {
ruleModel.setSimSlot(itemSimSlot);
ruleModel.setSwitchSmsTemplate(!smsTemplate.trim().isEmpty());
ruleModel.setSmsTemplate(smsTemplate);
ruleModel.setSwitchRegexReplace(!regexReplace.trim().isEmpty());
ruleModel.setRegexReplace(regexReplace);
tRules.add(ruleModel);
}

View File

@ -275,24 +275,11 @@
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/custom_templates"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:text="@string/custom_templates_tips"
android:textSize="11sp" />
</LinearLayout>
android:text="@string/enable_custom_templates_tips"
android:textSize="11sp" />
<EditText
android:id="@+id/text_sms_template"
@ -398,6 +385,65 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="5dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="@string/enable_regex_replace"
android:textStyle="bold" />
<Switch
android:id="@+id/switch_regex_replace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_regex_replace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="5dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/enable_regex_replace_tips"
android:textSize="11sp" />
<EditText
android:id="@+id/text_regex_replace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:inputType="textMultiLine"
android:gravity="start|top"
android:minLines="1"
android:text=""
tools:ignore="LabelFor" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -264,7 +264,6 @@
</LinearLayout>
<LinearLayout
android:id="@+id/layout_sms_template"
android:layout_width="match_parent"
@ -277,24 +276,11 @@
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/custom_templates"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:text="@string/custom_templates_tips"
android:textSize="11sp" />
</LinearLayout>
android:text="@string/enable_custom_templates_tips"
android:textSize="11sp" />
<EditText
android:id="@+id/text_sms_template"
@ -401,6 +387,65 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="5dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="@string/enable_regex_replace"
android:textStyle="bold" />
<Switch
android:id="@+id/switch_regex_replace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_regex_replace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="5dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/enable_regex_replace_tips"
android:textSize="11sp" />
<EditText
android:id="@+id/text_regex_replace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:inputType="textMultiLine"
android:gravity="start|top"
android:minLines="1"
android:text=""
tools:ignore="LabelFor" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -279,24 +279,11 @@
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/custom_templates"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:text="@string/custom_templates_tips"
android:textSize="11sp" />
</LinearLayout>
android:text="@string/enable_custom_templates_tips"
android:textSize="11sp" />
<EditText
android:id="@+id/text_sms_template"
@ -403,6 +390,65 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="5dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="@string/enable_regex_replace"
android:textStyle="bold" />
<Switch
android:id="@+id/switch_regex_replace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_regex_replace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="5dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/enable_regex_replace_tips"
android:textSize="11sp" />
<EditText
android:id="@+id/text_regex_replace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:inputType="textMultiLine"
android:gravity="start|top"
android:minLines="1"
android:text=""
tools:ignore="LabelFor" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -140,7 +140,7 @@
<string name="App_Secret">App Secret</string>
<string name="is_at_all">Is at all</string>
<string name="specified_member">Specified Member</string>
<string name="at_all"><![CDATA[@all]]></string>
<string name="at_all">\@all</string>
<string name="specified_member_tips">TipSpecify members receive messages, member ID list (multiple recipients with \'|\' space, maximum 1000)</string>
<string name="QYWXGroupRobotWebHook">WebHook, e.g. https://qyapi.weixin.qq.com/cgixx?key=xxx</string>
<string name="ServerChanSendKey">ServerChan\'s SendKey</string>
@ -171,6 +171,9 @@
<string name="forward_app_notify_tips">Master switch, please grant notice first</string>
<string name="enable_custom_templates">Enable custom templates</string>
<string name="enable_custom_templates_tips">Priority: custom template for forwarding rules >Global custom template >The default</string>
<string name="enable_regex_replace">Enable regular replacement content</string>
<string name="enable_regex_replace_tips">Format: RegularExpression===ReplacementResult,One rule per line.\ne.g. (\\d{3})\\d+(\\d{4})===$1****$2</string>
<string name="regex_check_tips">Format check: line %d is badly formatted! Format: RegularExpression===ReplacementResult</string>
<string name="enable_exclude_from_recents">Exclude from recents</string>
<string name="enable_exclude_from_recents_tips">After this function is enabled, manual killing of processes is effectively avoided, which helps to keep the process alive</string>
<string name="custom_templates">Custom templates</string>

View File

@ -140,7 +140,7 @@
<string name="App_Secret">应用Secret</string>
<string name="is_at_all">是否@all</string>
<string name="specified_member">指定成员</string>
<string name="at_all"><![CDATA[@all]]></string>
<string name="at_all">\@all</string>
<string name="specified_member_tips">Tip指定接收消息的成员成员ID列表多个接收者用|分隔最多支持1000个</string>
<string name="QYWXGroupRobotWebHook">设置WebHook地址:示例https://qyapi.weixin.qq.com/cgixx?key=xxx</string>
<string name="ServerChanSendKey">设置Server酱·Turbo版的SendKey</string>
@ -171,6 +171,9 @@
<string name="forward_app_notify_tips">总开关,请先授予通知使用权</string>
<string name="enable_custom_templates">启用自定义模版</string>
<string name="enable_custom_templates_tips">优先级:转发规则的自定义模板 > 全局自定义模版 > 默认</string>
<string name="enable_regex_replace">启用正则替换内容</string>
<string name="enable_regex_replace_tips">格式:正则表达式===替换结果,每行一个规则.\n例如(\\d{3})\\d{4}(\\d{4})===$1****$2</string>
<string name="regex_check_tips">正则替换检查:第 %d 行格式错误!格式:正则表达式===替换结果</string>
<string name="enable_exclude_from_recents">不在最近任务列表中显示</string>
<string name="enable_exclude_from_recents_tips">开启后,有效避免手动误杀进程,利于保活</string>
<string name="custom_templates">转发信息模版</string>