From e51de30aeec4226db51eb99689307f8f683e48da Mon Sep 17 00:00:00 2001 From: jiang Date: Tue, 10 Sep 2024 18:08:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ValidateCodeServiceImpl.java | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/bonus-gateway/src/main/java/com/bonus/gateway/service/impl/ValidateCodeServiceImpl.java b/bonus-gateway/src/main/java/com/bonus/gateway/service/impl/ValidateCodeServiceImpl.java index 9bcb3e6..023d1be 100644 --- a/bonus-gateway/src/main/java/com/bonus/gateway/service/impl/ValidateCodeServiceImpl.java +++ b/bonus-gateway/src/main/java/com/bonus/gateway/service/impl/ValidateCodeServiceImpl.java @@ -1,20 +1,9 @@ package com.bonus.gateway.service.impl; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import javax.annotation.Resource; -import javax.imageio.ImageIO; - -import com.bonus.common.core.utils.VerificationCodeUtils; -import com.bonus.common.core.utils.sms.SmsUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.util.FastByteArrayOutputStream; -import com.google.code.kaptcha.Producer; import com.bonus.common.core.constant.CacheConstants; import com.bonus.common.core.constant.Constants; import com.bonus.common.core.exception.CaptchaException; +import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.StringUtils; import com.bonus.common.core.utils.sign.Base64; import com.bonus.common.core.utils.uuid.IdUtils; @@ -22,6 +11,16 @@ import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.redis.service.RedisService; import com.bonus.gateway.config.properties.CaptchaProperties; import com.bonus.gateway.service.ValidateCodeService; +import com.google.code.kaptcha.Producer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.FastByteArrayOutputStream; + +import javax.annotation.Resource; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.concurrent.TimeUnit; /** * 验证码实现处理 @@ -56,7 +55,6 @@ public class ValidateCodeServiceImpl implements ValidateCodeService { if (!captchaEnabled) { return ajax; } - // 保存验证码信息 String uuid = IdUtils.simpleUUID(); String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; @@ -96,16 +94,16 @@ public class ValidateCodeServiceImpl implements ValidateCodeService { @Override public void checkCaptcha(String code, String uuid) throws CaptchaException { if (StringUtils.isEmpty(code)) { - throw new CaptchaException("人机验证码不能为空"); + throw new ServiceException("人机验证码不能为空"); } String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.nvl(uuid, ""); String captcha = redisService.getCacheObject(verifyKey); if (captcha == null) { - throw new CaptchaException("人机验证码已失效"); + throw new ServiceException("人机验证码已失效"); } redisService.deleteObject(verifyKey); if (!code.equalsIgnoreCase(captcha)) { - throw new CaptchaException("人机验证码错误"); + throw new ServiceException("人机验证码错误"); } } @@ -113,21 +111,19 @@ public class ValidateCodeServiceImpl implements ValidateCodeService { /** * 校验手机验证码 */ - public void checkPhoneCaptcha(String code, String phone) throws CaptchaException { + @Override + public void checkPhoneCaptcha(String code, String uuid) throws CaptchaException { if (StringUtils.isEmpty(code)) { - throw new CaptchaException("手机验证码不能为空"); + throw new ServiceException("验证码不能为空"); } - if (StringUtils.isEmpty(phone)) { - throw new CaptchaException("手机号不能为空"); - } - String verifyKey = CacheConstants.CAPTCHA_PHONE_CODE_KEY + StringUtils.nvl(phone, ""); + String verifyKey = CacheConstants.VERIFICATION_CODE + StringUtils.nvl(uuid, ""); String captcha = redisService.getCacheObject(verifyKey); if (captcha == null) { - throw new CaptchaException("手机验证码已失效"); + throw new ServiceException("验证码已失效"); } redisService.deleteObject(verifyKey); if (!code.equalsIgnoreCase(captcha)) { - throw new CaptchaException("手机验证码错误"); + throw new ServiceException("验证码错误"); } }