perf:调整消息日志相关代码

This commit is contained in:
曾文豪
2024-08-05 14:46:54 +08:00
parent cdae6a9868
commit ad90c83cf7
11 changed files with 85 additions and 171 deletions

View File

@@ -7,9 +7,9 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.tiesheng.message.pojos.MessageReqResp;
import com.tiesheng.message.service.TsMessageSender;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.pojos.ApiResp;
import com.tiesheng.util.service.http.OkHttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -119,17 +119,7 @@ public class AliyunSmsSender implements TsMessageSender {
* @param tempParam 短信模板
* @return
*/
public MessageReqResp sendSms(String phoneNumbers, AliyunTempParam tempParam) {
MessageReqResp reqResp = new MessageReqResp("阿里云短信");
reqResp.setTarget(phoneNumbers);
reqResp.setResult(1);
reqResp.setContent(JSONUtil.createObj()
.putOpt("PhoneNumbers", phoneNumbers)
.putOpt("SignName", tempParam.getSignName())
.putOpt("TemplateCode", tempParam.getTemplateCode())
.putOpt("TemplateParam", tempParam.getTemplateParam())
.toString());
public ApiResp<String> sendSms(String phoneNumbers, AliyunTempParam tempParam) {
// 业务API参数
ConcurrentHashMap<String, String> queryMap = new ConcurrentHashMap<>();
@@ -140,18 +130,16 @@ public class AliyunSmsSender implements TsMessageSender {
queryMap.put("TemplateParam", tempParam.getTemplateParam().toString());
}
reqResp.setRespBody(request("SendSms", queryMap));
JSONObject respObj = JSONUtil.parseObj(reqResp.getRespBody());
JSONObject respObj = JSONUtil.parseObj(request("SendSms", queryMap));
if (!Objects.equals(respObj.getStr("Code"), "OK")) {
reqResp.setResult(0);
reqResp.setToast(respObj.getStr("Message"));
return ApiResp.resp130(respObj.getStr("Message"));
}
return reqResp;
return ApiResp.respOK("");
}
@Override
public MessageReqResp send(String user, JSONObject body) {
public ApiResp<String> send(String user, JSONObject body) {
boolean mobile = Validator.isMobile(user);
if (!mobile) {
return null;

View File

@@ -1,87 +0,0 @@
package com.tiesheng.message.pojos;
public class MessageReqResp {
private String type;
/**
* 发送对象
*/
private String target;
/**
* 发送内容
*/
private String content;
/**
* 返回结果
*/
private String respBody;
/**
* 结果0-否1-是
*/
private Integer result;
/**
* 提示的异常信息
*/
private String toast;
public MessageReqResp(String type) {
this.type = type;
}
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getRespBody() {
return respBody;
}
public void setRespBody(String respBody) {
this.respBody = respBody;
}
public Integer getResult() {
return result;
}
public void setResult(Integer result) {
this.result = result;
}
public String getToast() {
return toast;
}
public void setToast(String toast) {
this.toast = toast;
}
}

View File

@@ -2,7 +2,7 @@ package com.tiesheng.message.service;
import cn.hutool.json.JSONObject;
import com.tiesheng.message.pojos.MessageReqResp;
import com.tiesheng.util.pojos.ApiResp;
/**
* @author hao
@@ -20,7 +20,7 @@ public interface TsMessageSender {
* @param channel 消息通道,如果为空表示所有通道
* @return 返回的内容,如果为空表示发送成功
*/
MessageReqResp send(String user, JSONObject body);
ApiResp<String> send(String user, JSONObject body);
/**

View File

@@ -4,8 +4,8 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.tiesheng.message.pojos.MessageReqResp;
import com.tiesheng.message.pojos.UserChannel;
import com.tiesheng.util.pojos.ApiResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -61,18 +61,18 @@ public class TsMessageService {
* @param userChannel
* @param body
*/
public MessageReqResp send(UserChannel userChannel, JSONObject body) {
public ApiResp<String> send(UserChannel userChannel, JSONObject body) {
if (StrUtil.isEmpty(userChannel.getUser()) || StrUtil.isEmpty(userChannel.getChannel())) {
return null;
return ApiResp.resp130("消息对象或消息通道不存在");
}
TsMessageSender messageSender = CollUtil.findOne(messageSenderList,
sender -> Objects.equals(sender.getChannel(), userChannel.getChannel()) && sender.support());
if (messageSender != null) {
messageSender.send(userChannel.getUser(), body);
return messageSender.send(userChannel.getUser(), body);
}
return null;
return ApiResp.resp130("消息未成功发送");
}
}