package com.xiaopeng.gateway.service.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.xiaopeng.common.core.constant.CacheConstants; import com.xiaopeng.common.core.exception.CaptchaException; import com.xiaopeng.common.core.utils.StringUtils; import com.xiaopeng.common.redis.service.RedisService; import com.xiaopeng.gateway.service.ValidateCodeService; /** * 验证码实现处理 * * @author ruoyi */ @Service public class ValidateCodeServiceImpl implements ValidateCodeService { @Autowired private RedisService redisService; /** * 校验验证码 */ @Override public void checkCaptcha(String code, String uuid) throws CaptchaException { if (StringUtils.isEmpty(code)) { throw new CaptchaException("验证码不能为空"); } if (StringUtils.isEmpty(uuid)) { throw new CaptchaException("验证码已失效"); } String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; String captcha = redisService.getCacheObject(verifyKey); redisService.deleteObject(verifyKey); if (!code.equalsIgnoreCase(captcha)) { throw new CaptchaException("验证码错误"); } } }