This commit is contained in:
zjf committed 2025-07-18 11:33:13 +08:00
1 parent 704c8d5a5f
commit d77922561b
5 files changed
+120 -73

No files matched your search

@@ -14,10 +14,7 @@ import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.concurrent.TimeUnit;
@@ -59,6 +56,18 @@ public class ImageCodeEndpoint {
captcha.out(response.getOutputStream());
}
@SneakyThrows
@GetMapping("/visitor/image")
public void visitorImage(@RequestParam(value = "randomStr")String randomStr, HttpServletResponse response) {
ArithmeticCaptcha captcha = new ArithmeticCaptcha(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT);
String result = captcha.text();
redisTemplate.opsForValue()
.set(CacheConstants.VISITOR_CODE_KEY + randomStr, result, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
// 转换流信息写出
captcha.out(response.getOutputStream());
}
/**
* 行为 创建滑块图形验证码
*/