| | |
| | | package com.hx.mp.util; |
| | | |
| | | 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; |
| | | |
| | | /** |
| | | * 企业微信客户工具 |
| | |
| | | * 获取获客客户列表 |
| | | */ |
| | | 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="; |
| | | |
| | | /** |
| | | * 企业微信发送普通邮件 |
| | | */ |
| | | public static final String GROUP_SENT_EMAIL = "https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token="; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 生成企业成员联系我的id-单人 |
| | |
| | | * |
| | | * @param accessToken 企业的accessToken |
| | | * @param linkId 链接id |
| | | * @param cursor 分页游标 |
| | | * @return 返回 |
| | | */ |
| | | public static JSONObject getCustomerAcquisitionCustomerList(String accessToken, String linkId) { |
| | | 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, |
| | |
| | | */ |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 企业微信发送普通邮件 |
| | | * 接口地址: https://developer.work.weixin.qq.com/document/path/97445 |
| | | * @param bodyData 参数 |
| | | */ |
| | | public static JSONObject sentEmail(String accessToken, JSONObject bodyData) { |
| | | return HttpURLUtil(GROUP_SENT_EMAIL + accessToken, bodyData.toString()); |
| | | } |
| | | } |