功能:从配置加载消息中心客户端设置
This commit is contained in:
+16
-8
@@ -4,9 +4,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xiaowang.yuminailcore.service.MessageHubClientService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageBuilder;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -20,16 +22,22 @@ import java.util.UUID;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RefreshScope
|
||||
@RequiredArgsConstructor
|
||||
public class MessageHubClientServiceImpl implements MessageHubClientService {
|
||||
|
||||
private static final String SMS_QUEUE = "smsQueue";
|
||||
private static final String SOURCE_SYSTEM = "yuminail";
|
||||
private static final String VERIFY_TEMPLATE_CODE = "SPUG0001";
|
||||
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Value("${messagehub.client.sms-queue:smsQueue}")
|
||||
private String smsQueue;
|
||||
|
||||
@Value("${messagehub.client.source-system:yuminail}")
|
||||
private String sourceSystem;
|
||||
|
||||
@Value("${messagehub.client.verify-template-code:SPUG0001}")
|
||||
private String verifyTemplateCode;
|
||||
|
||||
@Override
|
||||
public void sendSmsVerificationCode(String phone, String code) {
|
||||
try {
|
||||
@@ -37,8 +45,8 @@ public class MessageHubClientServiceImpl implements MessageHubClientService {
|
||||
messageBody.put("receiver", phone);
|
||||
messageBody.put("channelType", "SMS");
|
||||
messageBody.put("msgType", "VERIFICATION");
|
||||
messageBody.put("templateCode", VERIFY_TEMPLATE_CODE);
|
||||
messageBody.put("sourceSystem", SOURCE_SYSTEM);
|
||||
messageBody.put("templateCode", verifyTemplateCode);
|
||||
messageBody.put("sourceSystem", sourceSystem);
|
||||
messageBody.put("uniqueId", UUID.randomUUID().toString());
|
||||
messageBody.put("sendMethod", "SPUG");
|
||||
|
||||
@@ -56,9 +64,9 @@ public class MessageHubClientServiceImpl implements MessageHubClientService {
|
||||
.setMessageId(UUID.randomUUID().toString())
|
||||
.build();
|
||||
|
||||
rabbitTemplate.convertAndSend(SMS_QUEUE, message);
|
||||
rabbitTemplate.convertAndSend(smsQueue, message);
|
||||
log.info("短信验证码消息已发送到队列,手机号: {}, sourceSystem: {}, templateCode: {}",
|
||||
phone, SOURCE_SYSTEM, VERIFY_TEMPLATE_CODE);
|
||||
phone, sourceSystem, verifyTemplateCode);
|
||||
} catch (Exception exception) {
|
||||
log.error("发送短信验证码失败", exception);
|
||||
throw new RuntimeException("发送短信验证码失败: " + exception.getMessage(), exception);
|
||||
|
||||
@@ -20,3 +20,9 @@ server:
|
||||
mybatis:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
|
||||
messagehub:
|
||||
client:
|
||||
sms-queue: smsQueue
|
||||
source-system: yuminail
|
||||
verify-template-code: SPUG0001
|
||||
|
||||
Reference in New Issue
Block a user