From f214709cf1d896e7c9743f206b7a708f020e5322 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期五, 21 十月 2022 17:54:03 +0800
Subject: [PATCH] changes

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/security/authcode/VerifyCodeController.java |   47 +++++++++++++++++------------------------------
 1 files changed, 17 insertions(+), 30 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/security/authcode/VerifyCodeController.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/security/authcode/VerifyCodeController.java
index dfc6e23..61b53d8 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/security/authcode/VerifyCodeController.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/security/authcode/VerifyCodeController.java
@@ -1,14 +1,14 @@
 package com.sandu.ximon.admin.security.authcode;
 
 import cn.hutool.core.lang.Snowflake;
-import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.sandu.common.security.annotation.AnonymousAccess;
+import com.sandu.ximon.admin.utils.RedisUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
-import sun.misc.BASE64Encoder;
 
 import javax.imageio.ImageIO;
 import javax.servlet.ServletException;
@@ -32,7 +32,10 @@
 public class VerifyCodeController {
 
     private final Snowflake snowflake;
+//    private final RedisUtils redisUtils;
 
+
+    @AnonymousAccess
     @RequestMapping("/getImg")
     @ResponseBody
     public Map getVerifiCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
@@ -42,55 +45,39 @@
              3.鎶婇獙璇佺爜鍥剧墖鍙戦�佺粰瀹㈡埛绔�
              */
         long key = snowflake.nextId();
-        ImageVerificationCode ivc = new ImageVerificationCode();     //鐢ㄦ垜浠殑楠岃瘉鐮佺被锛岀敓鎴愰獙璇佺爜绫诲璞�
+        ImageVerificationCode ivc = new ImageVerificationCode();     //鐢熸垚楠岃瘉鐮佺被瀵硅薄
         BufferedImage image = ivc.getImage();  //鑾峰彇楠岃瘉鐮�
-
-//        ByteArrayOutputStream baos = new ByteArrayOutputStream();//io娴�
-//        ImageIO.write(image, "JPEG", baos);//鍐欏叆娴佷腑
-//        byte[] bytes = baos.toByteArray();//杞崲鎴愬瓧鑺�
-//        BASE64Encoder encoder = new BASE64Encoder();
-//        String png_base64 = encoder.encodeBuffer(bytes).trim();//杞崲鎴恇ase64涓�
-//        png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");//鍒犻櫎 \r\n
-
-        //        ImageIO.write(bufferedImage, "png", new File("D:/qrcode1.png"));
-//        System.out.println("鍊间负锛�"+"data:image/jpg;base64,"+png_base64);
-        request.getSession().setAttribute(key+"", ivc.getText()); //灏嗛獙璇佺爜鐨勬枃鏈瓨鍦╯ession涓�
-//        ImageVerificationCode.output(image, response.getOutputStream());//灏嗛獙璇佺爜鍥剧墖鍝嶅簲缁欏鎴风
+        System.out.println(ivc.getText() + "----鍔犲瘑鍓嶇殑楠岃瘉鐮�");
+        RedisUtils.getBean().set(key + "", MD5Util.md5(ivc.getText().toUpperCase()), 60);
         String img = getBufferedImageToBase64(image, "JPEG");
-        String session_vcode = (String) request.getSession().getAttribute(key+"");
+
         Map map = new HashMap();
-//        map.put("img", "data:image/jpg;base64,"+png_base64);
         map.put("img", img);
-        map.put("vlue", session_vcode);
         map.put("key", key);
         return map;
+//        return image;
     }
 
+    @AnonymousAccess
     @RequestMapping("/Login_authentication/{key}")
     @ResponseBody
-    public String Login_authentication(HttpServletRequest request, HttpServletResponse response,@PathVariable String key) throws IOException, ServletException {
+    public String Login_authentication(HttpServletRequest request, HttpServletResponse response, @PathVariable String key) throws IOException, ServletException {
         request.setCharacterEncoding("utf-8");
-//        String vcode = (String)map.get("session_vcode");
-//        if(vcode.isEmpty()||vcode==null){
-//            return "楠岃瘉鐮佷笉鑳戒负绌�";
-//        }
+
         String session_vcode = (String) request.getSession().getAttribute(key);    //浠巗ession涓幏鍙栫湡姝g殑楠岃瘉鐮�
-        //姣旇緝杈撳叆鐨勯獙璇佺爜鍜岀湡姝g殑楠岃瘉鐮�
-//        if(StrUtil.equalsIgnoreCase(session_vcode, vcode)){
-//            return "true";
-//        }
         return session_vcode;
     }
 
     /**
-     *  BufferedImage杞垚 base64
+     * BufferedImage杞垚 base64
+     *
      * @param bufferedImage
      * @param imageFormatName
      * @return
      * @throws IOException
      */
-    public static String getBufferedImageToBase64(BufferedImage bufferedImage,String imageFormatName) throws IOException {
-        if(StringUtils.isBlank(imageFormatName)){
+    public static String getBufferedImageToBase64(BufferedImage bufferedImage, String imageFormatName) throws IOException {
+        if (StringUtils.isBlank(imageFormatName)) {
             imageFormatName = "JPEG";
         }
         ByteArrayOutputStream stream = new ByteArrayOutputStream();

--
Gitblit v1.9.3