From 3b76b115b7f6736f18646d6d3c27492004ed8ff0 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Tue, 16 Jun 2020 11:05:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A3=80=E6=9F=A5=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/manager/VerificationCodeManager.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cloud-manager-sms/src/main/java/com/cm/manager/sms/manager/VerificationCodeManager.java b/cloud-manager-sms/src/main/java/com/cm/manager/sms/manager/VerificationCodeManager.java index 4613762..d06d5d1 100644 --- a/cloud-manager-sms/src/main/java/com/cm/manager/sms/manager/VerificationCodeManager.java +++ b/cloud-manager-sms/src/main/java/com/cm/manager/sms/manager/VerificationCodeManager.java @@ -1,6 +1,8 @@ package com.cm.manager.sms.manager; +import com.cm.common.exception.ParamsException; import com.cm.manager.sms.pojo.VerificationCode; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -88,6 +90,23 @@ public class VerificationCodeManager { verificationCodeMap.remove(key); } + /** + * 校验验证码 + * + * @param key + * @param code + */ + public void checkVerificationCode(String key, String code) { + String verificationCode = getVerificationCode(key); + if (StringUtils.isBlank(verificationCode)) { + throw new ParamsException("验证码无效"); + } + if (!StringUtils.equals(code, verificationCode)) { + throw new ParamsException("验证码不匹配"); + } + clearUsedVerificationCode(key); + } + /** * 删除过期验证码 */