From 29c36380f636c0ae22d668c856c03a543bcca1c8 Mon Sep 17 00:00:00 2001
From: fwq <582742538@qq.com>
Date: 星期一, 23 十月 2023 19:25:23 +0800
Subject: [PATCH] 捕获异常判断2007

---
 src/main/java/com/hx/util/QRCodeUtil.java |   42 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/hx/util/QRCodeUtil.java b/src/main/java/com/hx/util/QRCodeUtil.java
index 4ed2f62..25fe7a3 100644
--- a/src/main/java/com/hx/util/QRCodeUtil.java
+++ b/src/main/java/com/hx/util/QRCodeUtil.java
@@ -2,6 +2,7 @@
 
 import java.awt.*;
 import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
@@ -32,7 +33,46 @@
 	}
 
 	/**
-	 * zxing鏂瑰紡鐢熸垚浜岀淮鐮�
+	 * zxing鏂瑰紡鐢熸垚浜岀淮鐮侊紙杩斿洖base64锛�
+	 * 娉ㄦ剰锛�
+	 * 1,鏂囨湰鐢熸垚浜岀淮鐮佺殑鏂规硶鐙珛鍑烘潵,杩斿洖image娴佺殑褰㈠紡,鍙互杈撳嚭鍒伴〉闈�
+	 * 2,璁剧疆瀹归敊鐜囦负鏈�楂�,涓�鑸閿欑巼瓒婇珮,鍥剧墖瓒婁笉娓呮櫚, 浣嗘槸鍙湁灏嗗閿欑巼璁剧疆楂樹竴鐐规墠鑳藉吋瀹筶ogo鍥剧墖
+	 * 3,logo鍥剧墖榛樿鍗犱簩缁寸爜鍥剧墖鐨�20%,璁剧疆澶ぇ浼氬鑷存棤娉曡В鏋�
+	 *
+	 * @param content  浜岀淮鐮佸寘鍚殑鍐呭锛屾枃鏈垨缃戝潃
+	 * @param size     鐢熸垚鐨勪簩缁寸爜鍥剧墖灏哄 鍙互鑷畾涔夋垨鑰呴粯璁わ紙250锛�
+	 * @param logoPath logo鐨勫瓨鏀句綅缃�
+	 */
+	public static String QRCodeCreate(String content, Integer size, String logoPath) {
+		ByteArrayOutputStream bos = null;
+		if(size == null){
+			size = 400;
+		}
+		try{
+			char[] rands = content.toCharArray();
+			//鑾峰彇浜岀淮鐮佹祦鐨勫舰寮忥紝鍐欏叆鍒扮洰褰曟枃浠朵腑
+			BufferedImage image = getBufferedImage(content, size, logoPath);
+			bos = new ByteArrayOutputStream();
+			ImageIO.write(image, "JPEG", bos);
+			byte[] buf = bos.toByteArray();
+			return "data:image/png;base64,"+Base64.getEncoder().encodeToString(buf);
+		}catch (Exception e){
+			e.printStackTrace();
+		}finally {
+			if(bos != null) {
+				try {
+					bos.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+				bos = null;
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * zxing鏂瑰紡鐢熸垚浜岀淮鐮侊紙杩斿洖璺緞锛�
 	 * 娉ㄦ剰锛�
 	 * 1,鏂囨湰鐢熸垚浜岀淮鐮佺殑鏂规硶鐙珛鍑烘潵,杩斿洖image娴佺殑褰㈠紡,鍙互杈撳嚭鍒伴〉闈�
 	 * 2,璁剧疆瀹归敊鐜囦负鏈�楂�,涓�鑸閿欑巼瓒婇珮,鍥剧墖瓒婁笉娓呮櫚, 浣嗘槸鍙湁灏嗗閿欑巼璁剧疆楂樹竴鐐规墠鑳藉吋瀹筶ogo鍥剧墖

--
Gitblit v1.8.0