瀏覽代碼

验证码 校验鉴权类

tags/24080901
liuxinxin 1 年之前
父節點
當前提交
28b9674dc3
共有 1 個文件被更改,包括 43 次插入0 次删除
  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 查看文件

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

}

Loading…
取消
儲存