Bläddra i källkod

验证码 校验鉴权类

tags/24080901
liuxinxin 1 år sedan
förälder
incheckning
28b9674dc3
1 ändrade filer med 43 tillägg och 0 borttagningar
  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 Visa fil

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

}

Laddar…
Avbryt
Spara