From c88f44a7d604bf91e22a5cb076018884a01a6261 Mon Sep 17 00:00:00 2001
From: Van333 <van666666@foxmail.com>
Date: 星期六, 19 十一月 2022 15:11:17 +0800
Subject: [PATCH] 替换阿里oss为本地minio,关闭对时存在定时任务时睡眠10min
---
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