From ce382d9c2cde3a79d56a126f5d549915631c4023 Mon Sep 17 00:00:00 2001 From: whq <460794335@qq.com> Date: Fri, 31 Mar 2023 14:11:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vordm/controller/CaptchaController.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/CaptchaController.java diff --git a/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/CaptchaController.java b/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/CaptchaController.java new file mode 100644 index 0000000..6116ac5 --- /dev/null +++ b/kn-service/biz-vordm/src/main/java/com/kening/vordm/controller/CaptchaController.java @@ -0,0 +1,39 @@ +package com.kening.vordm.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springblade.common.cache.CacheNames; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.redis.cache.BladeRedis; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author wanghongqing + * @date 2023/3/31 11:10 + **/ +@RestController +@RequestMapping("/captcha") +@RequiredArgsConstructor +@Api(value = "验证码校验接口", tags = "验证码校验") +public class CaptchaController extends BladeController { + + private final BladeRedis bladeRedis; + + @PostMapping("/validate") + @ApiOperation(value = "验证码校验", notes = "传入需要校验的验证码以及缓存Key") + public R validDefaultTime(@RequestParam String code, @RequestParam String key) { + // 获取验证码 + String redisCode = bladeRedis.get(CacheNames.CAPTCHA_KEY + key); + // 判断验证码 + if (code == null || !StringUtil.equalsIgnoreCase(redisCode, code)) { + return R.fail(1404, "Verification code error"); + } + return R.success("OK"); + } +}