From 4484acb56810d06ef5c2f78190a93688a61f83a7 Mon Sep 17 00:00:00 2001
From: chenjiahe <763432473@qq.com>
Date: 星期二, 28 六月 2022 16:16:48 +0800
Subject: [PATCH] 修改包名称

---
 src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 109 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java b/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java
index 260fc88..e3e2562 100644
--- a/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java
+++ b/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java
@@ -162,14 +162,15 @@
 	 * @return
 	 */
 	public static File createLimitedQrCode(String at, String page, int width, boolean autoColor,
-										   JSONObject lineColor, boolean isHyaline) throws IOException {
+										   JSONObject lineColor, boolean isHyaline) {
 		String imgUrl = null;
 		InputStream in = null;
 		HttpURLConnection conn = null;
 
 		//鍒涘缓涓存椂鏂囦欢
-		File file = File.createTempFile("temp", ".jpg");
+		File file = null;
 		try {
+			file = File.createTempFile("temp", ".jpg");
 			//鐢熸垚鍙戦�佹暟鎹�
 			JSONObject obj = new JSONObject();
 			obj.put("width", width);
@@ -245,7 +246,9 @@
 				conn = null;
 			}
 		}finally {
-			file.deleteOnExit();
+			if(file != null){
+				file.deleteOnExit();
+			}
 		}
 		return file;
 	}
@@ -602,4 +605,107 @@
 		return obj;
 	}
 
+
+
+	/**鐢熸垚鏃犻檺浜岀淮鐮�,杩斿洖涓存椂鏂�
+	 * @param at 寰俊token
+	 * @param scene 鍙傛暟锛屽彧鑳�32浣嶏紝鏈�濂戒笉瑕佷腑鏂�
+	 * @param page 璺宠浆閾炬帴
+	 * @param width 瀹藉害
+	 * @param autoColor 榛樿false
+	 * @param lineColor 榛樿null
+	 * @param isHyaline 榛樿false
+	 * @return
+	 */
+	public static File createUnlimitQrCode(String at, String scene, String page, int width, boolean autoColor,
+										   JSONObject lineColor, boolean isHyaline, String env_version) throws IOException {
+		String imgUrl = null;
+		InputStream in = null;
+		HttpURLConnection conn = null;
+
+		//鍒涘缓涓存椂鏂囦欢
+		File file = File.createTempFile("temp", ".jpg");
+
+		try {
+			//鐢熸垚鍙戦�佹暟鎹�
+			JSONObject obj = new JSONObject();
+			obj.put("scene", scene);
+			obj.put("width", width);
+			obj.put("page", page);
+			obj.put("auto_color", autoColor);
+			obj.put("line_color", lineColor);
+			obj.put("is_hyaline", isHyaline);
+			obj.put("env_version", env_version);
+			// 鍒涘缓url璧勬簮
+			URL url = new URL(StringUtils.format(URL_UNLIMIT_SQUARE, at));
+			// 寤虹珛http杩炴帴
+			conn = (HttpURLConnection) url.openConnection();
+			// 璁剧疆鍏佽杈撳嚭
+			conn.setDoOutput(true);
+			conn.setDoInput(true);
+			// 璁剧疆涓嶇敤缂撳瓨
+			conn.setUseCaches(false);
+			// 璁剧疆浼犻�掓柟寮�
+			conn.setRequestMethod("POST");
+			// 璁剧疆缁存寔闀胯繛鎺�
+			conn.setRequestProperty("Connection", "Keep-Alive");
+			// 璁剧疆鏂囦欢瀛楃闆�:
+			conn.setRequestProperty("Charset", "UTF-8");
+			// 璁剧疆鏂囦欢绫诲瀷:
+			conn.setRequestProperty("contentType", "application/json");
+			// 寮�濮嬭繛鎺ヨ姹�
+			conn.connect();
+			OutputStream out = conn.getOutputStream();
+			// 鍐欏叆璇锋眰鐨勫瓧绗︿覆
+			out.write((obj.toString()).getBytes());
+			out.flush();
+			out.close();
+
+			// 璇锋眰杩斿洖鐨勭姸鎬�
+			if (conn.getResponseCode() == 200) {
+				// 璇锋眰杩斿洖鐨勬暟鎹�
+				in = conn.getInputStream();
+				//杈撳叆鍒颁复鏃舵枃浠�
+				/*OutputStream os = new FileOutputStream(file);
+				int bytesRead = 0;
+				byte[] buffer = new byte[8192];
+				while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
+					os.write(buffer, 0, bytesRead);
+				}*/
+				FileUtils.copyInputStreamToFile(in, file);
+
+				conn.disconnect();
+				conn = null;
+			}
+
+			if (in != null) {
+				in.close();
+				in = null;
+			}
+
+			if (conn != null) {
+				conn.disconnect();
+				conn = null;
+			}
+		}catch (Exception e) {
+			e.printStackTrace();
+			if (in != null) {
+				try {
+					in.close();
+				}catch (Exception ep) {
+					ep.printStackTrace();
+				}
+				in = null;
+			}
+
+			if (conn != null) {
+				conn.disconnect();
+				conn = null;
+			}
+		}finally {
+			file.deleteOnExit();
+		}
+		return file;
+	}
+
 }

--
Gitblit v1.8.0