Przeglądaj źródła

验证码 校验鉴权类

master
liuxinxin 1 rok temu
rodzic
commit
28b9674dc3
1 zmienionych plików z 43 dodań i 0 usunięć
  1. +43
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/sms/helper/VerifyCodeCheckHelper.java

+ 43
- 0
pmapi/src/main/java/com/ningdatech/pmapi/sms/helper/VerifyCodeCheckHelper.java Wyświetl plik

@@ -0,0 +1,43 @@
package com.ningdatech.pmapi.sms.helper;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.ningdatech.cache.repository.CachePlusOps;
import com.ningdatech.pmapi.sms.constant.VerificationCodeType;
import com.ningdatech.pmapi.sms.model.dto.VerifyCodeCacheDTO;
import com.ningdatech.pmapi.sms.utils.SmsRedisKeyUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
* @author liuxinxin
* @date 2022/8/16 上午11:43
*/
@Component
@RequiredArgsConstructor
public class VerifyCodeCheckHelper {

private final CachePlusOps cachePlusOps;

/**
* 对某种类型的验证码进行校验
* @param type
* @param mobile
* @param verificationCode
* @return
*/
public boolean verification(VerificationCodeType type, String mobile, String verificationCode) {
if (StringUtils.isBlank(mobile) || Objects.isNull(type)) {
return false;
}
String key = SmsRedisKeyUtils.smsCodeVerifyKey(type, mobile);
Object cacheObj = cachePlusOps.get(key);
if (Objects.isNull(cacheObj)) {
return false;
}
VerifyCodeCacheDTO cache = (VerifyCodeCacheDTO) cacheObj;
return verificationCode.trim().equals(cache.getCode());
}

}

Ładowanie…
Anuluj
Zapisz