| | |
| | | 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; |
| | | |
| | | /** |
| | | * 企业微信客户工具 |
| | |
| | | * 获取员工客户列表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="; |
| | | |
| | | /** |
| | | * 企业微信发送普通邮件 |
| | | */ |
| | | public static final String GROUP_SENT_EMAIL = "https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token="; |
| | | |
| | | /** |
| | | * 客户群「加入群聊」查看 |
| | | */ |
| | | public static final String GROUP_JOIN_WAY_SEE = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/get_join_way?access_token="; |
| | | /** |
| | | * 客户群「加入群聊」新增 |
| | | * 企业可调用此接口来生成并配置「加入群聊」的二维码或者小程序按钮 |
| | | * 客户通过扫描二维码或点击小程序上的按钮,即可加入特定的客户群 |
| | | */ |
| | | public static final String GROUP_JOIN_WAY_ADD = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/add_join_way?access_token="; |
| | | /** |
| | | * 客户群「加入群聊」修改 |
| | | */ |
| | | public static final String GROUP_JOIN_WAY_EDIT = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/update_join_way?access_token="; |
| | | /** |
| | | * 客户群「加入群聊」删除 |
| | | */ |
| | | public static final String GROUP_JOIN_WAY_EDL= "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/del_join_way?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); |
| | | } |
| | | |
| | | /** |
| | | * 企业微信发送普通邮件 |
| | | * 接口地址: 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()); |
| | | } |
| | | |
| | | /** |
| | | * 客户群「加入群聊」查看详情 |
| | | * @param config_id 联系方式配置ID |
| | | * */ |
| | | public static HttpHzResponse groupJoinSee(String accessToken, String config_id) { |
| | | JSONObject bodyData = new JSONObject(); |
| | | bodyData.put("config_id", config_id); |
| | | return HttpHzUtil.HttpURLUtilJson(GROUP_JOIN_WAY_SEE + accessToken, bodyData.toString(), null, null, "POST", null); |
| | | } |
| | | |
| | | /** |
| | | * 客户群「加入群聊」新增 |
| | | * @param scene 场景。1 - 群的小程序插件, 2 - 群的二维码插件 |
| | | * @param remark 联系方式的备注信息,用于助记,超过30个字符将被截断 |
| | | * @param auto_create_room 当群满了后,是否自动新建群。0-否;1-是。 默认为1 |
| | | * @param room_base_name 自动建群的群名前缀,当auto_create_room为1时有效。最长40个utf8字符 |
| | | * @param room_base_id 自动建群的群起始序号,当auto_create_room为1时有效 |
| | | * @param chat_id_list 使用该配置的客户群ID列表,最多支持5个 |
| | | * */ |
| | | public static HttpHzResponse groupJoinAdd(String accessToken, Integer scene, String remark |
| | | ,Integer auto_create_room,String room_base_name,Integer room_base_id,List<String> chat_id_list,String state) { |
| | | JSONObject bodyData = new JSONObject(); |
| | | bodyData.put("scene", scene); |
| | | bodyData.put("remark", remark); |
| | | bodyData.put("auto_create_room", auto_create_room); |
| | | bodyData.put("room_base_name", room_base_name); |
| | | bodyData.put("room_base_id", room_base_id); |
| | | bodyData.put("chat_id_list", chat_id_list); |
| | | bodyData.put("state", state); |
| | | return HttpHzUtil.HttpURLUtilJson(GROUP_JOIN_WAY_ADD + accessToken, bodyData.toString(), null, null, "POST", null); |
| | | } |
| | | |
| | | /** |
| | | * 客户群「加入群聊」修改 |
| | | * @param config_id 联系方式配置ID |
| | | * @param scene 场景。1 - 群的小程序插件, 2 - 群的二维码插件 |
| | | * @param remark 联系方式的备注信息,用于助记,超过30个字符将被截断 |
| | | * @param auto_create_room 当群满了后,是否自动新建群。0-否;1-是。 默认为1 |
| | | * @param room_base_name 自动建群的群名前缀,当auto_create_room为1时有效。最长40个utf8字符 |
| | | * @param room_base_id 自动建群的群起始序号,当auto_create_room为1时有效 |
| | | * @param chat_id_list 使用该配置的客户群ID列表,最多支持5个 |
| | | * */ |
| | | public static HttpHzResponse groupJoinEdit(String accessToken,String config_id, Integer scene, String remark |
| | | ,Integer auto_create_room,String room_base_name,Integer room_base_id,List<String> chat_id_list,String state) { |
| | | JSONObject bodyData = new JSONObject(); |
| | | bodyData.put("config_id", config_id); |
| | | bodyData.put("scene", scene); |
| | | bodyData.put("remark", remark); |
| | | bodyData.put("auto_create_room", auto_create_room); |
| | | bodyData.put("room_base_name", room_base_name); |
| | | bodyData.put("room_base_id", room_base_id); |
| | | bodyData.put("chat_id_list", chat_id_list); |
| | | bodyData.put("state", state); |
| | | return HttpHzUtil.HttpURLUtilJson(GROUP_JOIN_WAY_EDIT + accessToken, bodyData.toString(), null, null, "POST", null); |
| | | } |
| | | |
| | | /** |
| | | * 客户群「加入群聊」删除 |
| | | * @param config_id 联系方式配置ID |
| | | * */ |
| | | public static HttpHzResponse groupJoinDel(String accessToken, String config_id) { |
| | | JSONObject bodyData = new JSONObject(); |
| | | bodyData.put("config_id", config_id); |
| | | return HttpHzUtil.HttpURLUtilJson(GROUP_JOIN_WAY_EDL + accessToken, bodyData.toString(), null, null, "POST", null); |
| | | } |
| | | |
| | | |
| | | |
| | | } |