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"); + } +}