瀏覽代碼

验证码返回格式调整

chengyao 3 年之前
父節點
當前提交
71e039049f

+ 2 - 3
src/main/java/com/diagbot/facade/SysUserFacade.java

@@ -124,6 +124,7 @@ public class SysUserFacade extends SysUserServiceImpl {
     }
 
     public void getCaptcha(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        response.setContentType("image/png");
         HttpSession session = request.getSession();
         String captchaId = session.getId();
         session.setAttribute("captchaId", captchaId);
@@ -131,14 +132,12 @@ public class SysUserFacade extends SysUserServiceImpl {
         ImageCaptchaUtil imageCaptchaUtil = new ImageCaptchaUtil();
         BufferedImage image = imageCaptchaUtil.createRandom();
         String captcha = imageCaptchaUtil.getText();
+        redisUtils.set("user:captcha" + captchaId, captcha, 60 * 3);
         ImageIO.write(image, ImageCaptchaParams.DEFAULT_FORMAT, outputStream);
         outputStream.flush();
         outputStream.close();
-        redisUtils.set("user:captcha" + captchaId, captcha, 60 * 3);
     }
 
-    ;
-
     /**
      * 获取jwt
      *

+ 3 - 2
src/main/java/com/diagbot/web/SysUserController.java

@@ -24,6 +24,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.oauth2.common.OAuth2AccessToken;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -74,10 +75,10 @@ public class SysUserController {
     }
 
     @ApiOperation(value = "获取验证码[by:cy]")
-    @PostMapping("/getCaptcha")
+    @GetMapping("/getCaptcha")
     @SysLogger("getCaptcha")
     public void getCaptcha(HttpServletRequest request, HttpServletResponse response) throws IOException {
-          userFacade.getCaptcha(request,response);
+           userFacade.getCaptcha(request, response);
     }
 
     @ApiOperation(value = "获取标识--选择登录页面[by:cy]")