Explorar el Código

验证码 校验鉴权类

master
liuxinxin hace 1 año
padre
commit
28b9674dc3
Se han modificado 1 ficheros con 43 adiciones y 0 borrados
  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 Ver fichero

@@ -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());
}

}

Cargando…
Cancelar
Guardar