From d1eb76ad5d3095c6495bdc831adb2d2a546b97cb Mon Sep 17 00:00:00 2001
From: E1ED922C1E9526DD63272D7EC5C6CB77 <E1ED922C1E9526DD63272D7EC5C6CB77@i-search.com.cn>
Date: 星期二, 29 十二月 2020 14:21:12 +0800
Subject: [PATCH] Merge branch 'master' of https://gitee.com/huoxiong/hx_common

---
 src/main/java/com/hx/util/COSUtil.java             |    4 
 src/main/java/com/hx/mp/util/CorpMpUtil.java       |   18 +++++-
 src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java |  103 ++++++++++++++++++++++++++++++++++
 3 files changed, 120 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/hx/mp/util/CorpMpUtil.java b/src/main/java/com/hx/mp/util/CorpMpUtil.java
index bd83c76..ccd4824 100644
--- a/src/main/java/com/hx/mp/util/CorpMpUtil.java
+++ b/src/main/java/com/hx/mp/util/CorpMpUtil.java
@@ -103,7 +103,7 @@
     /**
      * 鍒犻櫎宸ヤ綔浜哄憳
      * @param at 璁块棶at
-     * @param userId 鐢ㄦ埛id
+     * @param userId 浼佷笟鐢ㄦ埛id
      * @return 杩斿洖
      */
     public static int deleteUser(String at, String userId) {
@@ -128,14 +128,26 @@
         obj.put("userid", userId);
 
         obj = HttpURLUtil(MessageFormat.format(URL_INFO_USER, at,userId), obj.toString());
-        System.out.println("userId:"+userId);
-        System.out.println("obj:"+obj.toString());
+
         if(obj != null) {
             return obj.optInt("errcode", -1);
         }
         return -1;
     }
 
+    /**
+     * 鑾峰彇浼佷笟鐢ㄦ埛淇℃伅
+     * @param at 璁块棶at
+     * @param userId 鐢ㄦ埛id
+     * @return 杩斿洖
+     */
+    public static JSONObject userData(String at, String userId) {
+        JSONObject obj = new JSONObject();
+        obj.put("userid", userId);
+
+        return obj = HttpURLUtil(MessageFormat.format(URL_INFO_USER, at,userId), obj.toString());
+    }
+
 
     /**
      * 娣诲姞閮ㄩ棬
diff --git a/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java b/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java
index fcec5f9..2e0c414 100644
--- a/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java
+++ b/src/main/java/com/hx/mp/util/MPWeixinBaseUtil.java
@@ -6,6 +6,7 @@
 import net.sf.json.JSONException;
 import net.sf.json.JSONObject;
 import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.springframework.stereotype.Component;
 
@@ -151,6 +152,108 @@
 		return imgUrl;
 	}
 
+	/**鐢熸垚鏃犻檺浜岀淮鐮�,杩斿洖涓存椂鏂�
+	 * @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) 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);
+
+			// 鍒涘缓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;
+	}
+
+
 	/**鐢熸垚灏忕▼搴忎簩缁寸爜宸ュ叿锛堟柟褰級
 	 * path 浜岀淮鐮佽烦杞摼鎺�
 	 * width 浜岀淮鐮佸搴�,榛樿鏄�430
diff --git a/src/main/java/com/hx/util/COSUtil.java b/src/main/java/com/hx/util/COSUtil.java
index f0ae88f..0137cac 100644
--- a/src/main/java/com/hx/util/COSUtil.java
+++ b/src/main/java/com/hx/util/COSUtil.java
@@ -48,7 +48,7 @@
 		//寮�濮嬩笂浼�
 		ObjectMetadata objectMetadata = new ObjectMetadata();
 		// 璁剧疆杈撳叆娴侀暱搴︿负500
-		objectMetadata.setContentLength(500);
+		objectMetadata.setContentLength(localFile.getSize());
 		// 璁剧疆 Content type, 榛樿鏄� application/octet-stream,瀵逛簬鏈湴鏂囦欢涓婁紶锛岄粯璁ゆ牴鎹湰鍦版枃浠剁殑鍚庣紑杩涜鏄犲皠
 		// 锛屼緥濡� jpg 鏂囦欢鏄犲皠 涓篿mage/jpeg瀵逛簬娴佸紡涓婁紶 榛樿鏄� application/octet-stream
 		//objectMetadata.setContentType("application/pdf");
@@ -57,7 +57,7 @@
 
 		//鎷兼帴璺緞
 		StringBuilder imgUrl = new StringBuilder();
-		imgUrl.append("https://"+bucketName+"-"+secretId+".cos."+regionName+".myqcloud.com");
+		imgUrl.append("https://"+bucketName+".cos."+regionName+".myqcloud.com");
 		if(key.startsWith("/")){
 			imgUrl.append(key);
 		}else{

--
Gitblit v1.8.0