将白名单验证码也写入到redis中
This commit is contained in:
parent
3792b0baa4
commit
398cee97a7
@ -2,7 +2,9 @@ package cn.axzo.msg.center.notices.service.impl;
|
||||
|
||||
import cn.axzo.basics.common.exception.ServiceException;
|
||||
import cn.axzo.basics.common.util.AssertUtil;
|
||||
import cn.axzo.core.constant.RedisNameConstants;
|
||||
import cn.axzo.framework.auth.domain.TerminalInfo;
|
||||
import cn.axzo.msg.center.common.redis.IAxzoJedisManager;
|
||||
import cn.axzo.msg.center.domain.enums.InsideSmsCodeEnum;
|
||||
import cn.axzo.msg.center.notices.service.SmsService;
|
||||
import cn.axzo.msg.center.notices.service.manager.SmsManager;
|
||||
@ -18,6 +20,7 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -32,6 +35,10 @@ public class SmsServiceImpl implements SmsService {
|
||||
private Boolean returnCode;
|
||||
@Resource
|
||||
private SmsManager smsManager;
|
||||
|
||||
@Resource
|
||||
private IAxzoJedisManager iAxzoJedisManager;
|
||||
|
||||
@Override
|
||||
public SendCodeRes sendPhoneCodeV2(SendCodeV2Req req) {
|
||||
if (req.getType() == null) {
|
||||
@ -59,6 +66,7 @@ public class SmsServiceImpl implements SmsService {
|
||||
if (phoneWrites.contains(req.getPhone())) {
|
||||
//白名单返回个666
|
||||
result.setCode(666666);
|
||||
saveValidCode(req.getPhone(),terminalType + "", code);
|
||||
return result;
|
||||
}
|
||||
// // 验证boss看板用户是否存在
|
||||
@ -73,6 +81,21 @@ public class SmsServiceImpl implements SmsService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void saveValidCode(String phoneNumber, String type, int code) {
|
||||
Duration duration = Duration.ofSeconds(60 * 15L);
|
||||
String key = RedisNameConstants.SMS_CODE.concat(type + ":").concat(phoneNumber);
|
||||
// 在验证码有效期内(15分钟)重复发送验证码,返回同一验证码
|
||||
Integer realCode = iAxzoJedisManager.get(key);
|
||||
if (realCode == null || realCode == 0) {
|
||||
realCode = code;
|
||||
}
|
||||
if (String.valueOf(realCode).length() != String.valueOf(code).length()) {
|
||||
realCode = code;
|
||||
}
|
||||
iAxzoJedisManager.set(key, realCode, duration.getSeconds());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public CodeStatusRes getPhoneCodeStatus(CodeStatusReq req) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user