dev
parent
2829d082ae
commit
0a4785ae1b
|
|
@ -74,7 +74,7 @@ public class AccountController {
|
|||
|
||||
@ApiOperation("发送短信")
|
||||
@PostMapping("/sendMessage")
|
||||
public com.alibaba.cola.dto.SingleResponse<Boolean> sendMessage(@Validated @RequestBody SendMessageCmd cmd) {
|
||||
public com.alibaba.cola.dto.SingleResponse<String> sendMessage(@Validated @RequestBody SendMessageCmd cmd) {
|
||||
return smsRemote.sign(cmd.getMobile());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,10 +94,13 @@ public enum ErrorCode {
|
|||
* 短信码不存在
|
||||
*/
|
||||
SMS_SOURCE_CODE_NOT_EXIST("04-01-001", "短信码不存在"),
|
||||
SMS_CODE_EXPIRED("04-01-002", "验证码过期,请重新发送"),
|
||||
SMS_CODE_NOT_RIGHT("04-01-003", "验证码不正确"),
|
||||
|
||||
// gbs
|
||||
GBS_USER_ERROR("04-01-001", "gbs用户未登录"),
|
||||
|
||||
|
||||
/**
|
||||
* 未知错误
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.qinan.safetyeval.infrastructure.remote;
|
|||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.cola.dto.SingleResponse;
|
||||
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;
|
||||
|
|
@ -33,7 +34,7 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static org.qinan.safetyeval.domain.exception.ErrorCode.SMS_SOURCE_CODE_NOT_EXIST;
|
||||
import static org.qinan.safetyeval.domain.exception.ErrorCode.*;
|
||||
|
||||
/**
|
||||
* 助通短信平台(融合云 v2)远程调用
|
||||
|
|
@ -57,6 +58,7 @@ public class SmsRemote {
|
|||
|
||||
@DubboReference
|
||||
private MessageFacade messageFacade;
|
||||
private final RedisService redisService;
|
||||
|
||||
|
||||
@Value("${sms.sign.sourceCode:}")
|
||||
|
|
@ -85,11 +87,25 @@ public class SmsRemote {
|
|||
return sendSms(mobile, content);
|
||||
}
|
||||
|
||||
public SingleResponse<Boolean> sign(String mobile) {
|
||||
public SingleResponse<String> sign(String mobile) {
|
||||
String validCode = generateVerificationCode();
|
||||
String bizId = cn.hutool.core.lang.UUID.fastUUID().toString();
|
||||
String content = "【秦安安全】您正在注册本系统,验证码:" + validCode + ",5分钟内有效,请勿泄露给他人,如非本人操作请忽略本条短信。";
|
||||
sendSms(mobile, content);
|
||||
return SingleResponse.of(true);
|
||||
redisService.set(bizId, validCode, 5 * 60 * 1000);
|
||||
return SingleResponse.of(bizId);
|
||||
}
|
||||
|
||||
public SingleResponse<String> signValidCode(String mobile, String validCode) {
|
||||
String bizId = cn.hutool.core.lang.UUID.fastUUID().toString();
|
||||
Object code = redisService.get(bizId);
|
||||
if (code == null) {
|
||||
throw new BizException(SMS_CODE_EXPIRED);
|
||||
}
|
||||
if (code.toString().equals(validCode)) {
|
||||
throw new BizException(SMS_CODE_NOT_RIGHT);
|
||||
}
|
||||
return SingleResponse.of(bizId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue