From 28b9674dc392bf64b1f8abce886289ad1c3506b1 Mon Sep 17 00:00:00 2001 From: liuxinxin Date: Thu, 16 Feb 2023 17:51:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=20=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E9=89=B4=E6=9D=83=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/sms/helper/VerifyCodeCheckHelper.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sms/helper/VerifyCodeCheckHelper.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sms/helper/VerifyCodeCheckHelper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sms/helper/VerifyCodeCheckHelper.java new file mode 100644 index 0000000..c1a5034 --- /dev/null +++ b/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()); + } + +}