|
@@ -0,0 +1,53 @@
|
|
|
|
+package com.citu.module.menduner.system.controller.app.common.captcha;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.citu.framework.common.util.servlet.ServletUtils;
|
|
|
|
+import com.xingyuv.captcha.model.common.ResponseModel;
|
|
|
|
+import com.xingyuv.captcha.model.vo.CaptchaVO;
|
|
|
|
+import com.xingyuv.captcha.service.CaptchaService;
|
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.annotation.security.PermitAll;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+
|
|
|
|
+@Tag(name = "用户端 - 验证码")
|
|
|
|
+@RestController("appCaptchaController")
|
|
|
|
+@RequestMapping("/menduner/system/captcha")
|
|
|
|
+public class AppCaptchaController {
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private CaptchaService captchaService;
|
|
|
|
+
|
|
|
|
+ @PostMapping({"/get"})
|
|
|
|
+ @Operation(summary = "获得验证码")
|
|
|
|
+ @PermitAll
|
|
|
|
+ public ResponseModel get(@RequestBody CaptchaVO data, HttpServletRequest request) {
|
|
|
|
+ assert request.getRemoteHost() != null;
|
|
|
|
+ data.setBrowserInfo(getRemoteId(request));
|
|
|
|
+ return captchaService.get(data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @PostMapping("/check")
|
|
|
|
+ @Operation(summary = "校验验证码")
|
|
|
|
+ @PermitAll
|
|
|
|
+ public ResponseModel check(@RequestBody CaptchaVO data, HttpServletRequest request) {
|
|
|
|
+ data.setBrowserInfo(getRemoteId(request));
|
|
|
|
+ return captchaService.check(data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String getRemoteId(HttpServletRequest request) {
|
|
|
|
+ String ip = ServletUtils.getClientIP(request);
|
|
|
|
+ String ua = request.getHeader("user-agent");
|
|
|
|
+ if (StrUtil.isNotBlank(ip)) {
|
|
|
|
+ return ip + ua;
|
|
|
|
+ }
|
|
|
|
+ return request.getRemoteAddr() + ua;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|