新增:pushplus增加标题模板

优化:发送通道测试内容统一
This commit is contained in:
pppscn 2022-01-22 19:48:22 +08:00
parent fdad4471a8
commit c011f6f811
4 changed files with 185 additions and 16 deletions

View File

@ -52,6 +52,7 @@ import com.idormy.sms.forwarder.model.vo.QYWXAppSettingVo;
import com.idormy.sms.forwarder.model.vo.QYWXGroupRobotSettingVo;
import com.idormy.sms.forwarder.model.vo.ServerChanSettingVo;
import com.idormy.sms.forwarder.model.vo.SmsSettingVo;
import com.idormy.sms.forwarder.model.vo.SmsVo;
import com.idormy.sms.forwarder.model.vo.TelegramSettingVo;
import com.idormy.sms.forwarder.model.vo.WebNotifySettingVo;
import com.idormy.sms.forwarder.sender.SenderBarkMsg;
@ -76,7 +77,6 @@ import com.idormy.sms.forwarder.view.StepBar;
import com.umeng.analytics.MobclickAgent;
import java.net.Proxy;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@ -508,7 +508,8 @@ public class SenderActivity extends AppCompatActivity {
String atMobiles = editTextDingdingAtMobiles.getText().toString().trim();
Boolean atAll = switchDingdingAtAll.isChecked();
try {
SenderDingdingMsg.sendMsg(0, handler, token, secret, atMobiles, atAll, R.string.test_content + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderDingdingMsg.sendMsg(0, handler, null, token, secret, atMobiles, atAll, smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
@ -647,7 +648,8 @@ public class SenderActivity extends AppCompatActivity {
}
try {
SenderMailMsg.sendEmail(0, handler, protocol, host, port, ssl, fromEmail, nickname, pwd, toEmail, title, R.string.test_content + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderMailMsg.sendEmail(0, handler, null, protocol, host, port, ssl, fromEmail, nickname, pwd, toEmail, smsVo.getTitleForSend(title), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
@ -772,7 +774,8 @@ public class SenderActivity extends AppCompatActivity {
String barkIcon = editTextBarkIcon.getText().toString().trim();
if (CommonUtil.checkUrl(barkServer, false)) {
try {
SenderBarkMsg.sendMsg(0, handler, barkServer, barkIcon, getString(R.string.test_phone_num), getString(R.string.test_sms), getString(R.string.test_group_name));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderBarkMsg.sendMsg(0, handler, null, barkServer, barkIcon, getString(R.string.test_phone_num), smsVo.getSmsVoForSend(), getString(R.string.test_group_name));
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
@ -885,7 +888,8 @@ public class SenderActivity extends AppCompatActivity {
}
try {
SenderWebNotifyMsg.sendMsg(0, handler, webServer, webParams, secret, method, "SmsForwarder Title", R.string.test_content + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderWebNotifyMsg.sendMsg(0, handler, null, webServer, webParams, secret, method, smsVo.getMobile(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
@ -983,7 +987,8 @@ public class SenderActivity extends AppCompatActivity {
}
try {
SenderQyWxGroupRobotMsg.sendMsg(0, handler, webHook, "SmsForwarder Title", R.string.test_content + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderQyWxGroupRobotMsg.sendMsg(0, handler, null, webHook, smsVo.getMobile(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
@ -1120,7 +1125,8 @@ public class SenderActivity extends AppCompatActivity {
}
try {
SenderQyWxAppMsg.sendMsg(0, handler, senderModel, QYWXAppSettingVoNew, R.string.test_content + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderQyWxAppMsg.sendMsg(0, handler, null, senderModel, QYWXAppSettingVoNew, smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
@ -1216,7 +1222,8 @@ public class SenderActivity extends AppCompatActivity {
}
try {
SenderServerChanMsg.sendMsg(0, handler, serverChanServer, getString(R.string.test_phone_num), getString(R.string.test_sms));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderServerChanMsg.sendMsg(0, handler, null, serverChanServer, smsVo.getMobile(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
@ -1405,8 +1412,9 @@ public class SenderActivity extends AppCompatActivity {
String method = radioGroupTelegramMethod.getCheckedRadioButtonId() == R.id.radioTelegramMethodGet ? "GET" : "POST";
try {
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
TelegramSettingVo telegramSettingVoNew = new TelegramSettingVo(apiToken, chatId, proxyTypeId, proxyHost, proxyPort, proxyAuthenticator, proxyUsername, proxyPassword, method);
SenderTelegramMsg.sendMsg(0, handler, telegramSettingVoNew, getString(R.string.test_phone_num), getString(R.string.test_sms), telegramSettingVoNew.getMethod());
SenderTelegramMsg.sendMsg(0, handler, null, telegramSettingVoNew, smsVo.getMobile(), smsVo.getSmsVoForSend(), telegramSettingVoNew.getMethod());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
@ -1520,7 +1528,8 @@ public class SenderActivity extends AppCompatActivity {
}
try {
SenderSmsMsg.sendMsg(0, handler, simSlot, mobiles, onlyNoNetwork, getString(R.string.test_phone_num), getString(R.string.test_sms));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderSmsMsg.sendMsg(0, handler, simSlot, mobiles, onlyNoNetwork, smsVo.getMobile(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
@ -1620,7 +1629,8 @@ public class SenderActivity extends AppCompatActivity {
}
try {
SenderFeishuMsg.sendMsg(0, handler, webHook, secret, getString(R.string.test_phone_num), new Date(), getString(R.string.test_sms));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderFeishuMsg.sendMsg(0, handler, null, webHook, secret, smsVo.getMobile(), new Date(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
@ -1656,6 +1666,7 @@ public class SenderActivity extends AppCompatActivity {
final EditText editTextPushPlusWebhook = view1.findViewById(R.id.editTextPushPlusWebhook);
final EditText editTextPushPlusCallbackUrl = view1.findViewById(R.id.editTextPushPlusCallbackUrl);
final EditText editTextPushPlusValidTime = view1.findViewById(R.id.editTextPushPlusValidTime);
final EditText editTextPushPlusTitle = view1.findViewById(R.id.editTextPushPlusTitle);
if (pushPlusSettingVo != null) {
editTextPushPlusToken.setText(pushPlusSettingVo.getToken());
@ -1665,6 +1676,7 @@ public class SenderActivity extends AppCompatActivity {
editTextPushPlusWebhook.setText(pushPlusSettingVo.getWebhook());
editTextPushPlusCallbackUrl.setText(pushPlusSettingVo.getCallbackUrl());
editTextPushPlusValidTime.setText(pushPlusSettingVo.getValidTime());
editTextPushPlusTitle.setText(pushPlusSettingVo.getTitleTemplate());
}
Button buttonPushPlusOk = view1.findViewById(R.id.buttonPushPlusOk);
@ -1691,7 +1703,8 @@ public class SenderActivity extends AppCompatActivity {
editTextPushPlusChannel.getText().toString().trim(),
editTextPushPlusWebhook.getText().toString().trim(),
editTextPushPlusCallbackUrl.getText().toString().trim(),
editTextPushPlusValidTime.getText().toString().trim()
editTextPushPlusValidTime.getText().toString().trim(),
editTextPushPlusTitle.getText().toString().trim()
);
if (TextUtils.isEmpty(pushPlusSettingVoNew.getToken())) {
Toast.makeText(SenderActivity.this, R.string.invalid_token, Toast.LENGTH_LONG).show();
@ -1730,6 +1743,10 @@ public class SenderActivity extends AppCompatActivity {
});
buttonPushPlusTest.setOnClickListener(view -> {
String title = editTextPushPlusTitle.getText().toString().trim();
if (title.isEmpty()) title = "SmsForwarder Title";
PushPlusSettingVo pushPlusSettingVoNew = new PushPlusSettingVo(
editTextPushPlusToken.getText().trim(),
editTextPushPlusTopic.getText().toString().trim(),
@ -1737,7 +1754,8 @@ public class SenderActivity extends AppCompatActivity {
editTextPushPlusChannel.getText().toString().trim(),
editTextPushPlusWebhook.getText().toString().trim(),
editTextPushPlusCallbackUrl.getText().toString().trim(),
editTextPushPlusValidTime.getText().toString().trim()
editTextPushPlusValidTime.getText().toString().trim(),
title
);
if (TextUtils.isEmpty(pushPlusSettingVoNew.getToken())) {
@ -1746,12 +1764,41 @@ public class SenderActivity extends AppCompatActivity {
}
try {
SenderPushPlusMsg.sendMsg(0, handler, pushPlusSettingVoNew, "SmsForwarder", getString(R.string.test_content) + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderPushPlusMsg.sendMsg(0, handler, null, pushPlusSettingVoNew, smsVo.getTitleForSend(title), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
});
Button buttonInsertSender = view1.findViewById(R.id.bt_insert_sender);
buttonInsertSender.setOnClickListener(view -> {
editTextPushPlusTitle.setFocusable(true);
editTextPushPlusTitle.requestFocus();
CommonUtil.insertOrReplaceText2Cursor(editTextPushPlusTitle, "{{来源号码}}");
});
Button buttonInsertExtra = view1.findViewById(R.id.bt_insert_extra);
buttonInsertExtra.setOnClickListener(view -> {
editTextPushPlusTitle.setFocusable(true);
editTextPushPlusTitle.requestFocus();
CommonUtil.insertOrReplaceText2Cursor(editTextPushPlusTitle, "{{卡槽信息}}");
});
Button buttonInsertTime = view1.findViewById(R.id.bt_insert_time);
buttonInsertTime.setOnClickListener(view -> {
editTextPushPlusTitle.setFocusable(true);
editTextPushPlusTitle.requestFocus();
CommonUtil.insertOrReplaceText2Cursor(editTextPushPlusTitle, "{{接收时间}}");
});
Button buttonInsertDeviceName = view1.findViewById(R.id.bt_insert_device_name);
buttonInsertDeviceName.setOnClickListener(view -> {
editTextPushPlusTitle.setFocusable(true);
editTextPushPlusTitle.requestFocus();
CommonUtil.insertOrReplaceText2Cursor(editTextPushPlusTitle, "{{设备名称}}");
});
}
//Gotify
@ -1861,7 +1908,8 @@ public class SenderActivity extends AppCompatActivity {
GotifySettingVo gotifySettingVoNew = new GotifySettingVo(webServer, title, priority);
try {
SenderGotifyMsg.sendMsg(0, handler, gotifySettingVoNew, title, R.string.test_content + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
SmsVo smsVo = new SmsVo(getString(R.string.test_phone_num), getString(R.string.test_sender_sms), new Date(), getString(R.string.test_sim_info));
SenderGotifyMsg.sendMsg(0, handler, null, gotifySettingVoNew, smsVo.getTitleForSend(title), smsVo.getSmsVoForSend());
} catch (Exception e) {
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();

View File

@ -13,11 +13,12 @@ public class PushPlusSettingVo implements Serializable {
private String webhook;
private String callbackUrl;
private String validTime;
private String titleTemplate;
public PushPlusSettingVo() {
}
public PushPlusSettingVo(String token, String topic, String template, String channel, String webhook, String callbackUrl, String validTime) {
public PushPlusSettingVo(String token, String topic, String template, String channel, String webhook, String callbackUrl, String validTime, String titleTemplate) {
this.token = token;
this.topic = topic;
this.template = template;
@ -25,5 +26,6 @@ public class PushPlusSettingVo implements Serializable {
this.webhook = webhook;
this.callbackUrl = callbackUrl;
this.validTime = validTime;
this.titleTemplate = titleTemplate;
}
}

View File

@ -30,6 +30,17 @@ public class SmsVo implements Serializable {
this.simInfo = simInfo;
}
@SuppressLint("SimpleDateFormat")
public String getTitleForSend() {
return getTitleForSend("", "");
}
@SuppressLint("SimpleDateFormat")
public String getTitleForSend(String titleTemplate) {
return getTitleForSend(titleTemplate, "");
}
@SuppressLint("SimpleDateFormat")
public String getTitleForSend(String titleTemplate, String regexReplace) {
if (titleTemplate == null || titleTemplate.isEmpty()) titleTemplate = "{{来源号码}}";
@ -47,6 +58,16 @@ public class SmsVo implements Serializable {
return RegexReplace(regexReplace, titleForSend);
}
@SuppressLint("SimpleDateFormat")
public String getSmsVoForSend() {
return getSmsVoForSend("", "");
}
@SuppressLint("SimpleDateFormat")
public String getSmsVoForSend(String ruleSmsTemplate) {
return getSmsVoForSend(ruleSmsTemplate, "");
}
@SuppressLint("SimpleDateFormat")
public String getSmsVoForSend(String ruleSmsTemplate, String regexReplace) {
String deviceMark = SettingUtil.getAddExtraDeviceMark().trim();

View File

@ -234,6 +234,104 @@
tools:ignore="LabelFor" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_sms_template"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_template"
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="10sp"
tools:ignore="SmallSp" />
</LinearLayout>
<EditText
android:id="@+id/editTextPushPlusTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:gravity="start|top"
android:inputType="text"
android:minLines="1"
android:text=""
tools:ignore="LabelFor,TextFields" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/bt_insert_sender"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:background="@color/colorBlueGrey"
android:text="@string/insert_sender"
tools:ignore="ButtonStyle,NestedWeights" />
<Button
android:id="@+id/bt_insert_extra"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:background="@color/colorBlueGrey"
android:text="@string/insert_extra"
tools:ignore="ButtonStyle,NestedWeights" />
<Button
android:id="@+id/bt_insert_time"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:background="@color/colorBlueGrey"
android:text="@string/insert_time"
tools:ignore="ButtonStyle,NestedWeights" />
<Button
android:id="@+id/bt_insert_device_name"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:background="@color/colorBlueGrey"
android:text="@string/insert_device_name"
tools:ignore="ButtonStyle,NestedWeights" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"