perf:调整消息通知

This commit is contained in:
曾文豪
2023-03-31 14:21:07 +08:00
parent 1c0e63bf98
commit 8d9632bcaa
8 changed files with 145 additions and 70 deletions

View File

@@ -7,8 +7,7 @@ import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.tiesheng.message.pojos.MessageReqResp;
import com.tiesheng.message.service.TieshengMessageConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import com.tiesheng.message.service.TieshengMessageSender;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@@ -22,16 +21,13 @@ import java.util.*;
*/
@Configuration
@ConfigurationProperties(prefix = "tiesheng.aliyun")
public class AliyunSmsConfig {
public class AliyunSmsConfig implements TieshengMessageSender {
/**
* 请求地址
*/
private static final String ENDPOINT = "https://dysmsapi.aliyuncs.com";
@Autowired
TieshengMessageConfigurer tieshengMessageConfigurer;
private String accessKeyId;
private String accessKeySecret;
private String signName;
@@ -62,7 +58,7 @@ public class AliyunSmsConfig {
*/
public MessageReqResp sendSms(String phoneNumbers, String templateCode, JSONObject params) {
MessageReqResp reqResp = new MessageReqResp();
MessageReqResp reqResp = new MessageReqResp("阿里云短信");
reqResp.setTarget(phoneNumbers);
reqResp.setResult(1);
reqResp.setContent(JSONUtil.createObj()
@@ -115,11 +111,19 @@ public class AliyunSmsConfig {
reqResp.setToast(respObj.getStr("Message"));
}
tieshengMessageConfigurer.onMessageSend("阿里云短信", reqResp);
return reqResp;
}
@Override
public MessageReqResp send(String user, String title, Object body) {
return sendSms(user, title, (JSONObject) body);
}
@Override
public String getChannel() {
return "sms";
}
///////////////////////////////////////////////////////////////////////////
// setter\getter
///////////////////////////////////////////////////////////////////////////