From 0c97aac57ef013e764f9e919a42596de4cf8a629 Mon Sep 17 00:00:00 2001
From: fwq <582742538@qq.com>
Date: 星期四, 26 十月 2023 11:26:59 +0800
Subject: [PATCH] 获取客户群消息

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

diff --git a/src/main/java/com/hx/mp/util/CorpMpClientUtil.java b/src/main/java/com/hx/mp/util/CorpMpClientUtil.java
index 79badce..f8d1957 100644
--- a/src/main/java/com/hx/mp/util/CorpMpClientUtil.java
+++ b/src/main/java/com/hx/mp/util/CorpMpClientUtil.java
@@ -1,5 +1,9 @@
 package com.hx.mp.util;
 
+import com.hx.exception.TipsException;
+import com.hx.util.StringUtils;
+import com.hz.util.http.HttpHzUtil;
+import com.hz.util.http.dto.HttpHzResponse;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONException;
 import net.sf.json.JSONObject;
@@ -8,6 +12,7 @@
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.util.List;
 
 /**
  * 浼佷笟寰俊瀹㈡埛宸ュ叿
@@ -57,6 +62,18 @@
      * 鑾峰彇鑾峰瀹㈡埛鍒楄〃
      */
     public static final String CUSTOMER_ACQUISITION_CUSTOMER_LIST = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/customer?access_token=";
+
+    /**
+     * 鑾峰彇閰嶇疆杩囧鎴风兢绠$悊鐨勫鎴风兢鍒楄〃
+     */
+    public static final String GROUP_CHAT_LIST = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/list?access_token=";
+
+
+    /**
+     * 閫氳繃瀹㈡埛缇D锛岃幏鍙栬鎯呫�傚寘鎷兢鍚嶃�佺兢鎴愬憳鍒楄〃銆佺兢鎴愬憳鍏ョ兢鏃堕棿銆佸叆缇ゆ柟寮忋�傦紙瀹㈡埛缇ゆ槸鐢卞叿鏈夊鎴风兢浣跨敤鏉冮檺鐨勬垚鍛樺垱寤虹殑澶栭儴缇わ級
+     */
+    public static final String GROUP_CHAT_DETAIL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/get?access_token=";
+
 
     /**
      * 鐢熸垚浼佷笟鎴愬憳鑱旂郴鎴戠殑id-鍗曚汉
@@ -335,4 +352,53 @@
          */
         return HttpURLUtil(CUSTOMER_ACQUISITION_CUSTOMER_LIST + accessToken, data.toString());
     }
+
+
+    /**
+     * 璇ユ帴鍙g敤浜庤幏鍙栭厤缃繃瀹㈡埛缇ょ鐞嗙殑瀹㈡埛缇ゅ垪琛ㄣ��
+     *
+     * @param accessToken  浼佷笟鐨刟ccessToken
+     * @param statusFilter 瀹㈡埛缇よ窡杩涚姸鎬佽繃婊ゃ��0 - 鎵�鏈夊垪琛�(鍗充笉杩囨护) 1 - 绂昏亴寰呯户鎵� 2 - 绂昏亴缁ф壙涓� 3 - 绂昏亴缁ф壙瀹屾垚
+     * @param userIdList   缇や富杩囨护 濡傛灉涓嶅~锛岃〃绀鸿幏鍙栧簲鐢ㄥ彲瑙佽寖鍥村唴鍏ㄩ儴缇や富鐨勬暟鎹彲瑙佽寖鍥翠汉鏁拌秴杩�1000浜猴紝涓轰簡闃叉鏁版嵁鍖呰繃澶э紝浼氭姤閿� 81017 鐢ㄦ埛ID鍒楄〃銆傛渶澶�100涓�
+     * @param cursor       鍒嗛〉涓嬫爣
+     * @param limit        鍒楄〃
+     * @return 杩斿洖
+     */
+    public static HttpHzResponse getGroupChatList(String accessToken, Integer statusFilter, List<String> userIdList, String cursor, Integer limit) {
+        JSONObject bodyData = new JSONObject();
+        bodyData.put("status_filter", statusFilter);
+        //鍒嗛〉涓嬫爣
+        if (StringUtils.noNull(cursor)) {
+            bodyData.put("cursor", cursor);
+        }
+        //榛樿100鏉�
+        if (limit == null) {
+            limit = 100;
+        }
+        bodyData.put("limit", limit);
+        //杩囨护
+        if (userIdList != null && userIdList.size() > 0) {
+            JSONObject filter = new JSONObject();
+            filter.put("userid_list", userIdList);
+            bodyData.put("owner_filter", filter);
+        }
+        return HttpHzUtil.HttpURLUtilJson(GROUP_CHAT_LIST + accessToken, bodyData.toString(), null, null, "GET", null);
+    }
+
+    /**
+     * 閫氳繃瀹㈡埛缇D锛岃幏鍙栬鎯呫�傚寘鎷兢鍚嶃�佺兢鎴愬憳鍒楄〃銆佺兢鎴愬憳鍏ョ兢鏃堕棿銆佸叆缇ゆ柟寮忋�傦紙瀹㈡埛缇ゆ槸鐢卞叿鏈夊鎴风兢浣跨敤鏉冮檺鐨勬垚鍛樺垱寤虹殑澶栭儴缇わ級
+     *
+     * @param chatId   瀹㈡埛缇D
+     * @param needName 鏄惁闇�瑕佽繑鍥炵兢鎴愬憳鐨勫悕瀛�0-涓嶈繑鍥烇紱1-杩斿洖
+     */
+    public static HttpHzResponse getGroupChatDetail(String accessToken, String chatId, Integer needName) {
+        JSONObject bodyData = new JSONObject();
+        bodyData.put("chat_id", chatId);
+        if (needName == null) {
+            needName = 0;
+        }
+        bodyData.put("need_name", needName);
+        return HttpHzUtil.HttpURLUtilJson(GROUP_CHAT_DETAIL + accessToken, bodyData.toString(), null, null, "GET", null);
+    }
+
 }

--
Gitblit v1.8.0