sms
parent
9d1cea06d4
commit
d03da85c04
|
|
@ -115,6 +115,7 @@ public enum ErrorCode {
|
|||
SMS_CODE_EXPIRED("04-01-002", "验证码过期,请重新发送"),
|
||||
SMS_CODE_NOT_RIGHT("04-01-003", "验证码不正确"),
|
||||
SMS_CODE_TOO_FREQUENT("04-01-004", "操作过于频繁,请稍后再试"),
|
||||
SMS_SEND_ERROR("04-01-005", "发送异常"),
|
||||
|
||||
/**
|
||||
* 内审
|
||||
|
|
|
|||
|
|
@ -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.request.MessageSendCmd;
|
||||
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.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.qinan.safetyeval.client.dto.SendMessageCmd;
|
||||
import org.qinan.safetyeval.domain.exception.BizException;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
|
|
@ -22,9 +21,6 @@ import org.springframework.http.MediaType;
|
|||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
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 javax.annotation.PostConstruct;
|
||||
|
|
@ -33,7 +29,6 @@ import java.security.MessageDigest;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
|
@ -100,7 +95,9 @@ public class SmsRemote {
|
|||
String validCode = generateVerificationCode();
|
||||
String bizId = SMS_SIGN_PREFIX + mobile;
|
||||
String content = "【秦安安全】您正在注册本系统,验证码:" + validCode + ",5分钟内有效,请勿泄露给他人,如非本人操作请忽略本条短信。";
|
||||
sendSms(mobile, content);
|
||||
// sendSms(mobile, content);
|
||||
|
||||
sendMessage(mobile, validCode);
|
||||
redisService.set(bizId, validCode, 5 * 60 * 1000);
|
||||
return SingleResponse.of(true);
|
||||
}
|
||||
|
|
@ -277,29 +274,31 @@ public class SmsRemote {
|
|||
}
|
||||
|
||||
|
||||
@ApiOperation("发送短信")
|
||||
@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);
|
||||
}
|
||||
|
||||
public com.alibaba.cola.dto.SingleResponse<Boolean> sendMessage(String mobile, String validCode) {
|
||||
MessageSendCmd messageSendCmd = new MessageSendCmd();
|
||||
messageSendCmd.setBusinessId(UUID.randomUUID().toString().replace("-", ""));
|
||||
|
||||
messageSendCmd.setBusinessId(UuidUtil.get32UUID());
|
||||
MessageTargetCmd messageTargetCmd = new MessageTargetCmd();
|
||||
messageTargetCmd.setMobile(cmd.getMobile());
|
||||
// messageTargetCmd.setUserId(info.getUserId());// 消息接受人id
|
||||
messageTargetCmd.setMobile(mobile);
|
||||
messageSendCmd.setTargetCmd(messageTargetCmd);
|
||||
|
||||
// 消息编码-第5步中获取的消息编码
|
||||
messageSendCmd.setSourceCode(sourceCode);
|
||||
|
||||
//底座很根据消息通道是否开启来判断是否可以发送短信
|
||||
//当NeedTokenEnum为false时,统一使用admin账号的消息通道开启状态
|
||||
// 否则,使用的是当前登录人token所属租户的消息通道开启状态
|
||||
messageSendCmd.setNeedTokenEnum(false);
|
||||
|
||||
messageSendCmd.setSourceCode(sourceCode);
|
||||
Map<String, Object> codeMap = new HashMap<>();
|
||||
codeMap.put("valid_code", "123456");
|
||||
messageSendCmd.setParams(codeMap);
|
||||
|
||||
log.info("发送短信参数: messageSendCmd: {}", JSONUtil.toJsonStr(messageSendCmd));
|
||||
com.alibaba.cola.dto.SingleResponse<Boolean> result = messageFacade.send(messageSendCmd);
|
||||
log.info("发送短信结果: result: {}", JSONUtil.toJsonStr(result));
|
||||
return result;
|
||||
Map<String, Object> sendParams = new HashMap<>();// 消息模板中的参数
|
||||
sendParams.put("code", validCode);
|
||||
messageSendCmd.setParams(sendParams);
|
||||
log.info("注册发送短信:messageSendCmd: {}", JSONUtil.toJsonStr(messageSendCmd));
|
||||
SingleResponse<Boolean> d = messageFacade.send(messageSendCmd);
|
||||
log.info("注册发送短信: {}", JSONUtil.toJsonStr(d));
|
||||
if (!d.isSuccess()) {
|
||||
throw new BizException(SMS_SEND_ERROR, d.getErrMessage());
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ openapi:
|
|||
|
||||
sms:
|
||||
sign:
|
||||
sourceCode: MS000151
|
||||
sourceCode: MS000165
|
||||
|
||||
auth:
|
||||
deptId:
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ openapi:
|
|||
|
||||
sms:
|
||||
sign:
|
||||
sourceCode: MS000146
|
||||
sourceCode: MS000147
|
||||
|
||||
auth:
|
||||
deptId:
|
||||
|
|
|
|||
Loading…
Reference in New Issue