Skip to content

Commit 1849890

Browse files
author
alucardxh
authored
🆕 #1817 企业微信增加批量获取外部联系人详情的接口,同时修复外部联系人中listGroupChat参数失效问题
1 parent 08bb399 commit 1849890

File tree

4 files changed

+214
-4
lines changed

4 files changed

+214
-4
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,31 @@ public interface WxCpExternalContactService {
132132
*/
133133
WxCpUserExternalContactInfo getContactDetail(String userId) throws WxErrorException;
134134

135+
/**
136+
* 批量获取客户详情.
137+
* <pre>
138+
*
139+
* 企业/第三方可通过此接口获取指定成员添加的客户信息列表。
140+
*
141+
* 请求方式:POST(HTTPS)
142+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/batch/get_by_user?access_token=ACCESS_TOKEN
143+
*
144+
* 权限说明:
145+
*
146+
* 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?);
147+
* 第三方/自建应用调用时,返回的跟进人follow_user仅包含应用可见范围之内的成员。
148+
* </pre>
149+
*
150+
* @param userId 企业成员的userid,注意不是外部联系人的帐号
151+
* @param cursor the cursor
152+
* @param limit the limit
153+
* @return wx cp user external contact batch info
154+
* @throws WxErrorException .
155+
*/
156+
WxCpUserExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
157+
Integer limit)
158+
throws WxErrorException;
159+
135160
/**
136161
* 修改客户备注信息.
137162
* <pre>

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,27 @@ public WxCpUserExternalContactInfo getContactDetail(String userId) throws WxErro
104104
return WxCpUserExternalContactInfo.fromJson(responseContent);
105105
}
106106

107+
@Override
108+
public WxCpUserExternalContactBatchInfo getContactDetailBatch(String userId,
109+
String cursor,
110+
Integer limit)
111+
throws WxErrorException {
112+
final String url =
113+
this.mainService
114+
.getWxCpConfigStorage()
115+
.getApiUrl(GET_CONTACT_DETAIL_BATCH);
116+
JsonObject json = new JsonObject();
117+
json.addProperty("userid", userId);
118+
if (StringUtils.isNotBlank(cursor)) {
119+
json.addProperty("cursor", cursor);
120+
}
121+
if (limit != null) {
122+
json.addProperty("limit", limit);
123+
}
124+
String responseContent = this.mainService.post(url, json.toString());
125+
return WxCpUserExternalContactBatchInfo.fromJson(responseContent);
126+
}
127+
107128
@Override
108129
public void updateRemark(WxCpUpdateRemarkRequest request) throws WxErrorException {
109130
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_REMARK);
@@ -162,10 +183,10 @@ public WxCpUserExternalGroupChatList listGroupChat(Integer pageIndex, Integer pa
162183
if (ArrayUtils.isNotEmpty(userIds) || ArrayUtils.isNotEmpty(partyIds)) {
163184
JsonObject ownerFilter = new JsonObject();
164185
if (ArrayUtils.isNotEmpty(userIds)) {
165-
json.add("userid_list", new Gson().toJsonTree(userIds).getAsJsonArray());
186+
ownerFilter.add("userid_list", new Gson().toJsonTree(userIds).getAsJsonArray());
166187
}
167188
if (ArrayUtils.isNotEmpty(partyIds)) {
168-
json.add("partyid_list", new Gson().toJsonTree(partyIds).getAsJsonArray());
189+
ownerFilter.add("partyid_list", new Gson().toJsonTree(partyIds).getAsJsonArray());
169190
}
170191
json.add("owner_filter", ownerFilter);
171192
}
@@ -212,10 +233,10 @@ public WxCpUserExternalGroupChatStatistic getGroupChatStatistic(Date startTime,
212233
if (ArrayUtils.isNotEmpty(userIds) || ArrayUtils.isNotEmpty(partyIds)) {
213234
JsonObject ownerFilter = new JsonObject();
214235
if (ArrayUtils.isNotEmpty(userIds)) {
215-
json.add("userid_list", new Gson().toJsonTree(userIds).getAsJsonArray());
236+
ownerFilter.add("userid_list", new Gson().toJsonTree(userIds).getAsJsonArray());
216237
}
217238
if (ArrayUtils.isNotEmpty(partyIds)) {
218-
json.add("partyid_list", new Gson().toJsonTree(partyIds).getAsJsonArray());
239+
ownerFilter.add("partyid_list", new Gson().toJsonTree(partyIds).getAsJsonArray());
219240
}
220241
json.add("owner_filter", ownerFilter);
221242
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import java.io.Serializable;
5+
import java.util.List;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Builder;
8+
import lombok.Data;
9+
import lombok.Getter;
10+
import lombok.NoArgsConstructor;
11+
import lombok.Setter;
12+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
13+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
14+
15+
/**
16+
* <pre>
17+
* 批量获取客户详情
18+
* Created by Binary Wang on 2020/10/22.
19+
* 参考文档:https://work.weixin.qq.com/api/doc/90000/90135/92994
20+
* </pre>
21+
*
22+
* @author <a href="https://github.com/alucardxh">alucardxh</a>
23+
*/
24+
@Getter
25+
@Setter
26+
public class WxCpUserExternalContactBatchInfo extends WxCpBaseResp implements Serializable {
27+
private static final long serialVersionUID = -5166048319463473186L;
28+
29+
@SerializedName("external_contact_list")
30+
private List<ExternalContactInfo> externalContactList;
31+
32+
@SerializedName("next_cursor")
33+
private String nextCursor;
34+
35+
@Getter
36+
@Setter
37+
public static class ExternalContactInfo {
38+
@SerializedName("external_contact")
39+
private ExternalContact externalContact;
40+
41+
@SerializedName("follow_info")
42+
private FollowedUser followInfo;
43+
}
44+
45+
@Getter
46+
@Setter
47+
public static class ExternalContact {
48+
@SerializedName("external_userid")
49+
private String externalUserId;
50+
51+
@SerializedName("position")
52+
private String position;
53+
54+
@SerializedName("name")
55+
private String name;
56+
57+
@SerializedName("avatar")
58+
private String avatar;
59+
60+
@SerializedName("corp_name")
61+
private String corpName;
62+
63+
@SerializedName("corp_full_name")
64+
private String corpFullName;
65+
66+
@SerializedName("type")
67+
private Integer type;
68+
69+
@SerializedName("gender")
70+
private Integer gender;
71+
72+
@SerializedName("unionid")
73+
private String unionId;
74+
75+
@SerializedName("external_profile")
76+
private ExternalProfile externalProfile;
77+
}
78+
79+
@Setter
80+
@Getter
81+
public static class ExternalProfile {
82+
@SerializedName("external_attr")
83+
private List<ExternalAttribute> externalAttrs;
84+
}
85+
86+
@Data
87+
@Builder
88+
@NoArgsConstructor
89+
@AllArgsConstructor
90+
public static class ExternalAttribute {
91+
@Setter
92+
@Getter
93+
public static class Text {
94+
private String value;
95+
}
96+
97+
@Setter
98+
@Getter
99+
public static class Web {
100+
private String title;
101+
private String url;
102+
}
103+
104+
@Setter
105+
@Getter
106+
public static class MiniProgram {
107+
@SerializedName("pagepath")
108+
private String pagePath;
109+
private String appid;
110+
private String title;
111+
}
112+
113+
private int type;
114+
115+
private String name;
116+
117+
private Text text;
118+
119+
private Web web;
120+
121+
@SerializedName("miniprogram")
122+
private MiniProgram miniProgram;
123+
}
124+
125+
@Setter
126+
@Getter
127+
public static class FollowedUser {
128+
@SerializedName("userid")
129+
private String userId;
130+
private String remark;
131+
private String description;
132+
@SerializedName("createtime")
133+
private Long createTime;
134+
private String state;
135+
@SerializedName("remark_company")
136+
private String remarkCompany;
137+
@SerializedName("remark_mobiles")
138+
private String[] remarkMobiles;
139+
private Tag[] tags;
140+
@SerializedName("remark_corp_name")
141+
private String remarkCorpName;
142+
@SerializedName("add_way")
143+
private String addWay;
144+
@SerializedName("oper_userid")
145+
private String operUserId;
146+
147+
}
148+
149+
public static WxCpUserExternalContactBatchInfo fromJson(String json) {
150+
return WxCpGsonBuilder.create().fromJson(json, WxCpUserExternalContactBatchInfo.class);
151+
}
152+
153+
@Setter
154+
@Getter
155+
public static class Tag {
156+
@SerializedName("group_name")
157+
private String groupName;
158+
@SerializedName("tag_name")
159+
private String tagName;
160+
private int type;
161+
}
162+
163+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public static class ExternalContact {
171171
public static final String CLOSE_TEMP_CHAT = "/cgi-bin/externalcontact/close_temp_chat";
172172
public static final String GET_FOLLOW_USER_LIST = "/cgi-bin/externalcontact/get_follow_user_list";
173173
public static final String GET_CONTACT_DETAIL = "/cgi-bin/externalcontact/get?external_userid=";
174+
public static final String GET_CONTACT_DETAIL_BATCH = "/cgi-bin/externalcontact/batch/get_by_user?";
174175
public static final String UPDATE_REMARK = "/cgi-bin/externalcontact/remark";
175176
public static final String LIST_EXTERNAL_CONTACT = "/cgi-bin/externalcontact/list?userid=";
176177
public static final String LIST_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/get_unassigned_list";

0 commit comments

Comments
 (0)