mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-02 03:40:26 +00:00
新增:手动重发发送失败的消息 (#80)
This commit is contained in:
parent
86f3960300
commit
96d9fa9f1e
@ -25,6 +25,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||||||
import com.idormy.sms.forwarder.adapter.LogAdapter;
|
import com.idormy.sms.forwarder.adapter.LogAdapter;
|
||||||
import com.idormy.sms.forwarder.model.vo.LogVo;
|
import com.idormy.sms.forwarder.model.vo.LogVo;
|
||||||
import com.idormy.sms.forwarder.sender.HttpServer;
|
import com.idormy.sms.forwarder.sender.HttpServer;
|
||||||
|
import com.idormy.sms.forwarder.sender.SendUtil;
|
||||||
import com.idormy.sms.forwarder.sender.SmsHubApiTask;
|
import com.idormy.sms.forwarder.sender.SmsHubApiTask;
|
||||||
import com.idormy.sms.forwarder.service.BatteryService;
|
import com.idormy.sms.forwarder.service.BatteryService;
|
||||||
import com.idormy.sms.forwarder.service.FrontService;
|
import com.idormy.sms.forwarder.service.FrontService;
|
||||||
@ -304,6 +305,21 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
|
|||||||
Toast.makeText(MainActivity.this, R.string.delete_log_toast, Toast.LENGTH_SHORT).show();
|
Toast.makeText(MainActivity.this, R.string.delete_log_toast, Toast.LENGTH_SHORT).show();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//重发消息回调,重发失败也会触发
|
||||||
|
Handler handler = new Handler(Looper.myLooper(), msg -> {
|
||||||
|
initTLogs();
|
||||||
|
showList(logVos);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
//对于发送失败的消息添加重发按钮
|
||||||
|
if (logVo.getForwardStatus() == 0) {
|
||||||
|
builder.setPositiveButton("重发消息", (dialog, which) -> {
|
||||||
|
Toast.makeText(MainActivity.this, R.string.resend_toast, Toast.LENGTH_SHORT).show();
|
||||||
|
SendUtil.resendMsgByLog(MainActivity.this, handler, logVo);
|
||||||
|
dialog.dismiss();
|
||||||
|
});
|
||||||
|
}
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class LogVo {
|
public class LogVo {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
private String type;
|
||||||
private String from;
|
private String from;
|
||||||
private String content;
|
private String content;
|
||||||
private String simInfo;
|
private String simInfo;
|
||||||
@ -19,8 +20,9 @@ public class LogVo {
|
|||||||
public LogVo() {
|
public LogVo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogVo(Long id, String from, String content, String simInfo, String time, String rule, int senderImageId, int forwardStatus, String forwardResponse) {
|
public LogVo(Long id, String type, String from, String content, String simInfo, String time, String rule, int senderImageId, int forwardStatus, String forwardResponse) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.type = type;
|
||||||
this.from = from;
|
this.from = from;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
this.simInfo = simInfo;
|
this.simInfo = simInfo;
|
||||||
|
@ -24,6 +24,7 @@ import com.idormy.sms.forwarder.model.vo.BarkSettingVo;
|
|||||||
import com.idormy.sms.forwarder.model.vo.DingDingSettingVo;
|
import com.idormy.sms.forwarder.model.vo.DingDingSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.EmailSettingVo;
|
import com.idormy.sms.forwarder.model.vo.EmailSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.FeiShuSettingVo;
|
import com.idormy.sms.forwarder.model.vo.FeiShuSettingVo;
|
||||||
|
import com.idormy.sms.forwarder.model.vo.LogVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.PushPlusSettingVo;
|
import com.idormy.sms.forwarder.model.vo.PushPlusSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.QYWXAppSettingVo;
|
import com.idormy.sms.forwarder.model.vo.QYWXAppSettingVo;
|
||||||
import com.idormy.sms.forwarder.model.vo.QYWXGroupRobotSettingVo;
|
import com.idormy.sms.forwarder.model.vo.QYWXGroupRobotSettingVo;
|
||||||
@ -36,6 +37,9 @@ import com.idormy.sms.forwarder.utils.LogUtil;
|
|||||||
import com.idormy.sms.forwarder.utils.NetUtil;
|
import com.idormy.sms.forwarder.utils.NetUtil;
|
||||||
import com.idormy.sms.forwarder.utils.RuleUtil;
|
import com.idormy.sms.forwarder.utils.RuleUtil;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SendUtil {
|
public class SendUtil {
|
||||||
@ -77,6 +81,57 @@ public class SendUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从日志获取消息内容并尝试重发
|
||||||
|
* 根据当前rule和sender来重发,而不是失败时设置的规则
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param handler 回调,用于刷新日志列表
|
||||||
|
* @param logVo 日志
|
||||||
|
*/
|
||||||
|
public static void resendMsgByLog(Context context, Handler handler, LogVo logVo) {
|
||||||
|
Log.d(TAG, logVo.toString());
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
Date date = new Date();
|
||||||
|
try {
|
||||||
|
date = sdf.parse(logVo.getTime());
|
||||||
|
} catch (ParseException e) {
|
||||||
|
Log.e(TAG, "SimpleDateFormat parse error", e);
|
||||||
|
}
|
||||||
|
SmsVo smsVo = new SmsVo(logVo.getFrom(), logVo.getContent(), date, logVo.getSimInfo());
|
||||||
|
Log.d(TAG, "resendMsgByLog smsVo:" + smsVo);
|
||||||
|
|
||||||
|
//从simInfo判断接收的是SIM1还是SIM2,获取不到时默认走ALL
|
||||||
|
String simInfo = smsVo.getSimInfo();
|
||||||
|
String key = null;
|
||||||
|
if (simInfo.startsWith("SIM1")) {
|
||||||
|
key = "SIM1";
|
||||||
|
} else if (simInfo.startsWith("SIM2")) {
|
||||||
|
key = "SIM2";
|
||||||
|
}
|
||||||
|
|
||||||
|
RuleUtil.init(context);
|
||||||
|
List<RuleModel> ruleList = RuleUtil.getRule(null, key, logVo.getType());
|
||||||
|
if (!ruleList.isEmpty()) {
|
||||||
|
SenderUtil.init(context);
|
||||||
|
for (RuleModel ruleModel : ruleList) {
|
||||||
|
//规则匹配发现需要发送
|
||||||
|
try {
|
||||||
|
if (ruleModel.checkMsg(smsVo)) {
|
||||||
|
List<SenderModel> senderModels = SenderUtil.getSender(ruleModel.getSenderId(), null);
|
||||||
|
for (SenderModel senderModel : senderModels) {
|
||||||
|
String smsTemplate = ruleModel.getSwitchSmsTemplate() ? ruleModel.getSmsTemplate() : "";
|
||||||
|
String regexReplace = ruleModel.getSwitchRegexReplace() ? ruleModel.getRegexReplace() : "";
|
||||||
|
SendUtil.senderSendMsg(handler, smsVo, senderModel, logVo.getId(), smsTemplate, regexReplace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "resendMsgByLog: fail checkMsg:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendMsgByRuleModelSenderId(final Handler handError, RuleModel ruleModel, SmsVo smsVo, Long senderId) throws Exception {
|
public static void sendMsgByRuleModelSenderId(final Handler handError, RuleModel ruleModel, SmsVo smsVo, Long senderId) throws Exception {
|
||||||
if (senderId == null) {
|
if (senderId == null) {
|
||||||
throw new Exception("先新建并选择发送通道");
|
throw new Exception("先新建并选择发送通道");
|
||||||
|
@ -198,7 +198,7 @@ public class LogUtil {
|
|||||||
if (senderName != null) rule += senderName.trim();
|
if (senderName != null) rule += senderName.trim();
|
||||||
|
|
||||||
int senderImageId = SenderModel.getImageId(senderType);
|
int senderImageId = SenderModel.getImageId(senderType);
|
||||||
LogVo logVo = new LogVo(itemId, itemFrom, content, simInfo, time, rule, senderImageId, forwardStatus, forwardResponse);
|
LogVo logVo = new LogVo(itemId, type, itemFrom, content, simInfo, time, rule, senderImageId, forwardStatus, forwardResponse);
|
||||||
LogVos.add(logVo);
|
LogVos.add(logVo);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "getLog e:" + e.getMessage());
|
Log.e(TAG, "getLog e:" + e.getMessage());
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
<string name="delete_log_title">Delete confirmation</string>
|
<string name="delete_log_title">Delete confirmation</string>
|
||||||
<string name="delete_log_tips">Are you sure to delete this log entry?</string>
|
<string name="delete_log_tips">Are you sure to delete this log entry?</string>
|
||||||
<string name="delete_log_toast">The log entry is deleted.</string>
|
<string name="delete_log_toast">The log entry is deleted.</string>
|
||||||
|
<string name="resend_toast">Resending</string>
|
||||||
<string name="details">Details</string>
|
<string name="details">Details</string>
|
||||||
<string name="clear_logs_tips">Are you sure to clear all forwarding logs?</string>
|
<string name="clear_logs_tips">Are you sure to clear all forwarding logs?</string>
|
||||||
<string name="pull_tips">Pull to refresh.</string>
|
<string name="pull_tips">Pull to refresh.</string>
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
<string name="delete_log_title">日志删除确认</string>
|
<string name="delete_log_title">日志删除确认</string>
|
||||||
<string name="delete_log_tips">确定删除该条日志记录?</string>
|
<string name="delete_log_tips">确定删除该条日志记录?</string>
|
||||||
<string name="delete_log_toast">该条日志记录已经删除!</string>
|
<string name="delete_log_toast">该条日志记录已经删除!</string>
|
||||||
|
<string name="resend_toast">正在重发</string>
|
||||||
<string name="details">详情</string>
|
<string name="details">详情</string>
|
||||||
<string name="clear_logs_tips">确定要清空转发记录吗?</string>
|
<string name="clear_logs_tips">确定要清空转发记录吗?</string>
|
||||||
<string name="pull_tips">下拉可以刷新!</string>
|
<string name="pull_tips">下拉可以刷新!</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user