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); + } + /** * 删除过期验证码 */