新增检查验证码

This commit is contained in:
wenc000 2020-06-16 11:05:39 +08:00
parent 7c3a605c2f
commit 3b76b115b7

View File

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