From b7ab9f397ef2322fa0e79ab51fc16cbd77399835 Mon Sep 17 00:00:00 2001
From: E1ED922C1E9526DD63272D7EC5C6CB77 <E1ED922C1E9526DD63272D7EC5C6CB77@i-search.com.cn>
Date: 星期五, 16 四月 2021 11:53:32 +0800
Subject: [PATCH] 添加小程序红包接口

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

diff --git a/src/main/java/com/hx/util/HttpUtil.java b/src/main/java/com/hx/util/HttpUtil.java
index 3222ba1..a043cf0 100644
--- a/src/main/java/com/hx/util/HttpUtil.java
+++ b/src/main/java/com/hx/util/HttpUtil.java
@@ -162,6 +162,48 @@
         return result;
     }
 
+    /**
+     * 甯eader鐨刧et璇锋眰
+     * @param generalUrl
+     * @param header
+     * @return
+     * @throws Exception
+     */
+    public static String get(String generalUrl, Map<String, String> header)
+            throws Exception {
+        URL url = new URL(generalUrl);
+        // 鎵撳紑鍜孶RL涔嬮棿鐨勮繛鎺�
+        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+        connection.setRequestMethod("GET");
+        // 璁剧疆閫氱敤鐨勮姹傚睘鎬�
+        connection.setRequestProperty("Connection", "Keep-Alive");
+        if(header != null)
+        {
+            for(String key : header.keySet())
+            {
+                connection.setRequestProperty(key, header.get(key));
+            }
+        }
+
+        connection.setUseCaches(false);
+        connection.setDoOutput(true);
+        connection.setDoInput(true);
+
+        // 寤虹珛瀹為檯鐨勮繛鎺�
+        connection.connect();
+        // 瀹氫箟 BufferedReader杈撳叆娴佹潵璇诲彇URL鐨勫搷搴�
+        BufferedReader in = null;
+        in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
+        String result = "";
+        String getLine;
+        while ((getLine = in.readLine()) != null) {
+            result += getLine;
+        }
+        in.close();
+
+        return result;
+    }
+
     /** 璇锋眰http鍗忚 鑾峰彇淇℃伅宸ュ叿 **/
     public static JSONObject HttpURLUtil(String url, String data) {
         HttpURLConnection con = null;

--
Gitblit v1.8.0