From ff57ace362af07655f54eea90c4d2f63b05f5b66 Mon Sep 17 00:00:00 2001 From: Andru <769883346@qq.com> Date: 星期五, 27 十月 2023 15:59:51 +0800 Subject: [PATCH] 添加参数 --- src/main/java/com/hx/mp/util/CorpMpClientUtil.java | 185 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 183 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hx/mp/util/CorpMpClientUtil.java b/src/main/java/com/hx/mp/util/CorpMpClientUtil.java index 32d0670..87b0919 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; /** * 浼佷笟寰俊瀹㈡埛宸ュ叿 @@ -43,6 +48,32 @@ */ public static final String RELATION_TAG = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token="; + /** + * 鑾峰彇鍛樺伐瀹㈡埛鍒楄〃url + */ + public static final String EXTERNAL_CONTACT_LIST = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list"; + + /** + * 鍒涘缓鑾峰閾炬帴url + */ + public static final String CUSTOMER_ACQUISITION_CREATE_LINK = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/customer_acquisition/create_link?access_token="; + + /** + * 鑾峰彇鑾峰瀹㈡埛鍒楄〃 + */ + 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-鍗曚汉 @@ -76,6 +107,16 @@ } /** + * 鑾峰彇瀹㈡埛鍒楄〃 + * @param accessToken 浼佷笟鐨刟ccessToken + * @param userId 浼佷笟鎴愬憳鐨剈serId + * @return 杩斿洖 + */ + public static JSONObject getExternalContactList(String accessToken, String userId) { + return HttpURLUtil(EXTERNAL_CONTACT_LIST + "?access_token=" + accessToken + "&userid=" + userId, null); + } + + /** * 鑾峰彇浼佷笟瀹㈡埛璇︽儏淇℃伅 * * @param accessToken 浼佷笟鐨刟ccessToken @@ -83,7 +124,6 @@ * @return 杩斿洖 */ public static JSONObject getClientData(String accessToken, String externalUserId) { - return HttpURLUtil(GET_CLIENT_DETAIL_URL + "?access_token=" + accessToken + "&external_userid=" + externalUserId, null); } @@ -179,7 +219,6 @@ return HttpURLUtil(RELATION_TAG + accessToken, data.toString()); } - /** * 璇锋眰http鍗忚 鑾峰彇淇℃伅宸ュ叿 **/ @@ -226,4 +265,146 @@ } return obj; } + + /**鐢熸垚浼佷笟鎴愬憳鑱旂郴鎴戠殑id-鍗曚汉 + * @param accessToken 浼佷笟鐨刟ccessToken + * @param userId 浼佷笟鎴愬憳鐨剈serId + * @param scene 鍦烘櫙锛�1-鍦ㄥ皬绋嬪簭涓仈绯伙紝2-閫氳繃浜岀淮鐮佽仈绯� + * @param state 浼佷笟鑷畾涔夌殑state鍙傛暟锛岀敤浜庡尯鍒嗕笉鍚岀殑娣诲姞娓犻亾锛屽湪璋冪敤鈥滆幏鍙栧閮ㄨ仈绯讳汉璇︽儏鈥濇椂浼氳繑鍥炶鍙傛暟鍊硷紝涓嶈秴杩�30涓瓧绗� + * @param remark 鑱旂郴鏂瑰紡鐨勫娉ㄤ俊鎭紝鐢ㄤ簬鍔╄锛屼笉瓒呰繃30涓瓧绗� + * @return 杩斿洖 + */ + public static JSONObject createContactId(String accessToken,String userId,int scene,String state,String remark){ + String configId = null; + JSONObject data = new JSONObject(); + data.put("type",1); + data.put("scene",scene); + data.put("state",state); + data.put("remark",remark); + JSONArray userIds = new JSONArray(); + userIds.add(userId); + data.put("user",userIds); + + //璇锋眰锛岃繑鍥炴牸寮� + /*{ + "errcode": 0, + "errmsg": "ok", + "config_id":"42b34949e138eb6e027c123cba77fAAA"銆�銆� + }*/ + + return HttpURLUtil(CREATE_CONTACT_ID_URL+accessToken,data.toString()); + } + + /** + * 鍒涘缓鑾峰閾炬帴 + * + * @param accessToken 浼佷笟鐨刟ccessToken + * @param linkName 閾炬帴鍚嶇О + * @param userList 鍛樺伐鐢ㄦ埛userId + * @return 杩斿洖 + */ + public static JSONObject createCustomerAcquisitionLink(String accessToken, String linkName, JSONArray userList) { + JSONObject data = new JSONObject(); + data.put("link_name", linkName); + JSONObject subData = new JSONObject(); + subData.accumulate("user_list", userList); + data.put("range", subData); + /** 杩斿洖鏁版嵁 + * { + * "link_id":"LINK_ID", + * "link_name":"鑾峰閾炬帴1鍙�", + * "range": + * { + * "user_list":["zhangsan","lisi"], + * "department_list":[2,3] + * }, + * "skip_verify":true + * } + */ + return HttpURLUtil(CUSTOMER_ACQUISITION_CREATE_LINK + accessToken, data.toString()); + } + + /** + * 鑾峰彇鑾峰瀹㈡埛鍒楄〃 + * + * @param accessToken 浼佷笟鐨刟ccessToken + * @param linkId 閾炬帴id + * @param cursor 鍒嗛〉娓告爣 + * @return 杩斿洖 + */ + public static JSONObject getCustomerAcquisitionCustomerList(String accessToken, String linkId, String cursor) { + JSONObject data = new JSONObject(); + data.put("link_id", linkId); + data.put("limit", 1000); + // 鍒嗛〉娓告爣 + if (!StringUtils.isEmpty(cursor)) { + data.put("cursor", cursor); + } + /** 杩斿洖鏁版嵁 + * { + * "errcode": 0, + * "errmsg": "ok", + * "customer_list": + * [ + * { + * "external_userid":"woAJ2GCAAAXtWyujaWJHDDGi0mACAAA", + * "userid":"zhangsan", + * "chat_status":0, + * "state":"CHANNEL_A" + * } + * ], + * "next_cursor":"CURSOR" + * } + */ + 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