| | |
| | | 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; |
| | |
| | | import java.io.OutputStream; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 企业微信客户工具 |
| | |
| | | * 获取员工客户列表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="; |
| | | |
| | | |
| | | /** |
| | | * 通过客户群ID,获取详情。包括群名、群成员列表、群成员入群时间、入群方式。(客户群是由具有客户群使用权限的成员创建的外部群) |
| | | */ |
| | | public static final String GROUP_CHAT_DETAIL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/get?access_token="; |
| | | |
| | | |
| | | /** |
| | | * 生成企业成员联系我的id-单人 |
| | |
| | | |
| | | return HttpURLUtil(CREATE_CONTACT_ID_URL+accessToken,data.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 创建获客链接 |
| | | * |
| | | * @param accessToken 企业的accessToken |
| | | * @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 企业的accessToken |
| | | * @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()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 该接口用于获取配置过客户群管理的客户群列表。 |
| | | * |
| | | * @param accessToken 企业的accessToken |
| | | * @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); |
| | | } |
| | | |
| | | /** |
| | | * 通过客户群ID,获取详情。包括群名、群成员列表、群成员入群时间、入群方式。(客户群是由具有客户群使用权限的成员创建的外部群) |
| | | * |
| | | * @param chatId 客户群ID |
| | | * @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); |
| | | } |
| | | |
| | | } |