luotaiqian 2026-07-27 16:49:03 +08:00
parent 9d1cea06d4
commit d03da85c04
4 changed files with 28 additions and 28 deletions

View File

@ -115,6 +115,7 @@ public enum ErrorCode {
SMS_CODE_EXPIRED("04-01-002", "验证码过期,请重新发送"), SMS_CODE_EXPIRED("04-01-002", "验证码过期,请重新发送"),
SMS_CODE_NOT_RIGHT("04-01-003", "验证码不正确"), SMS_CODE_NOT_RIGHT("04-01-003", "验证码不正确"),
SMS_CODE_TOO_FREQUENT("04-01-004", "操作过于频繁,请稍后再试"), SMS_CODE_TOO_FREQUENT("04-01-004", "操作过于频繁,请稍后再试"),
SMS_SEND_ERROR("04-01-005", "发送异常"),
/** /**
* *

View File

@ -6,12 +6,11 @@ import com.jjb.saas.framework.redis.service.RedisService;
import com.jjb.saas.message.client.message.facede.MessageFacade; import com.jjb.saas.message.client.message.facede.MessageFacade;
import com.jjb.saas.message.client.message.request.MessageSendCmd; import com.jjb.saas.message.client.message.request.MessageSendCmd;
import com.jjb.saas.message.client.message.request.MessageTargetCmd; import com.jjb.saas.message.client.message.request.MessageTargetCmd;
import io.swagger.annotations.ApiOperation; import com.zcloud.gbscommon.utils.UuidUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.qinan.safetyeval.client.dto.SendMessageCmd;
import org.qinan.safetyeval.domain.exception.BizException; import org.qinan.safetyeval.domain.exception.BizException;
import org.redisson.api.RLock; import org.redisson.api.RLock;
import org.redisson.api.RedissonClient; import org.redisson.api.RedissonClient;
@ -22,9 +21,6 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -33,7 +29,6 @@ import java.security.MessageDigest;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -100,7 +95,9 @@ public class SmsRemote {
String validCode = generateVerificationCode(); String validCode = generateVerificationCode();
String bizId = SMS_SIGN_PREFIX + mobile; String bizId = SMS_SIGN_PREFIX + mobile;
String content = "【秦安安全】您正在注册本系统,验证码:" + validCode + "5分钟内有效请勿泄露给他人如非本人操作请忽略本条短信。"; String content = "【秦安安全】您正在注册本系统,验证码:" + validCode + "5分钟内有效请勿泄露给他人如非本人操作请忽略本条短信。";
sendSms(mobile, content); // sendSms(mobile, content);
sendMessage(mobile, validCode);
redisService.set(bizId, validCode, 5 * 60 * 1000); redisService.set(bizId, validCode, 5 * 60 * 1000);
return SingleResponse.of(true); return SingleResponse.of(true);
} }
@ -277,29 +274,31 @@ public class SmsRemote {
} }
@ApiOperation("发送短信") public com.alibaba.cola.dto.SingleResponse<Boolean> sendMessage(String mobile, String validCode) {
@PostMapping("/sendMessage")
public com.alibaba.cola.dto.SingleResponse<Boolean> sendMessage(@Validated @RequestBody SendMessageCmd cmd) {
if (StringUtils.isBlank(sourceCode)) {
throw new BizException(SMS_SOURCE_CODE_NOT_EXIST);
}
MessageSendCmd messageSendCmd = new MessageSendCmd(); MessageSendCmd messageSendCmd = new MessageSendCmd();
messageSendCmd.setBusinessId(UUID.randomUUID().toString().replace("-", "")); messageSendCmd.setBusinessId(UuidUtil.get32UUID());
MessageTargetCmd messageTargetCmd = new MessageTargetCmd(); MessageTargetCmd messageTargetCmd = new MessageTargetCmd();
messageTargetCmd.setMobile(cmd.getMobile()); // messageTargetCmd.setUserId(info.getUserId());// 消息接受人id
messageTargetCmd.setMobile(mobile);
messageSendCmd.setTargetCmd(messageTargetCmd); messageSendCmd.setTargetCmd(messageTargetCmd);
// 消息编码-第5步中获取的消息编码
messageSendCmd.setSourceCode(sourceCode);
//底座很根据消息通道是否开启来判断是否可以发送短信
//当NeedTokenEnum为false时统一使用admin账号的消息通道开启状态
// 否则使用的是当前登录人token所属租户的消息通道开启状态
messageSendCmd.setNeedTokenEnum(false); messageSendCmd.setNeedTokenEnum(false);
messageSendCmd.setSourceCode(sourceCode); Map<String, Object> sendParams = new HashMap<>();// 消息模板中的参数
Map<String, Object> codeMap = new HashMap<>(); sendParams.put("code", validCode);
codeMap.put("valid_code", "123456"); messageSendCmd.setParams(sendParams);
messageSendCmd.setParams(codeMap); log.info("注册发送短信:messageSendCmd: {}", JSONUtil.toJsonStr(messageSendCmd));
SingleResponse<Boolean> d = messageFacade.send(messageSendCmd);
log.info("发送短信参数: messageSendCmd: {}", JSONUtil.toJsonStr(messageSendCmd)); log.info("注册发送短信: {}", JSONUtil.toJsonStr(d));
com.alibaba.cola.dto.SingleResponse<Boolean> result = messageFacade.send(messageSendCmd); if (!d.isSuccess()) {
log.info("发送短信结果: result: {}", JSONUtil.toJsonStr(result)); throw new BizException(SMS_SEND_ERROR, d.getErrMessage());
return result; }
return d;
} }
} }

View File

@ -67,7 +67,7 @@ openapi:
sms: sms:
sign: sign:
sourceCode: MS000151 sourceCode: MS000165
auth: auth:
deptId: deptId:

View File

@ -68,7 +68,7 @@ openapi:
sms: sms:
sign: sign:
sourceCode: MS000146 sourceCode: MS000147
auth: auth:
deptId: deptId: