Skip to content

Commit ba99224

Browse files
🎨 #2295 【企业微信】批量获取外部客户详情接口支持多个userId
1 parent b06cc90 commit ba99224

File tree

3 files changed

+53
-39
lines changed

3 files changed

+53
-39
lines changed

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

+39-34
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public interface WxCpExternalContactService {
153153

154154
/**
155155
* 企业和服务商可通过此接口,将微信外部联系人的userid转为微信openid,用于调用支付相关接口。暂不支持企业微信外部联系人(ExternalUserid为wo开头)的userid转openid。
156+
*
156157
* @param externalUserid 微信外部联系人的userid
157158
* @return 该企业的外部联系人openid
158159
* @throws WxErrorException .
@@ -197,13 +198,13 @@ public interface WxCpExternalContactService {
197198
* 第三方/自建应用调用时,返回的跟进人follow_user仅包含应用可见范围之内的成员。
198199
* </pre>
199200
*
200-
* @param userId 企业成员的userid,注意不是外部联系人的帐号
201-
* @param cursor the cursor
202-
* @param limit the limit
201+
* @param userIdList 企业成员的userid列表,注意不是外部联系人的帐号
202+
* @param cursor the cursor
203+
* @param limit the limit
203204
* @return wx cp user external contact batch info
204205
* @throws WxErrorException .
205206
*/
206-
WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
207+
WxCpExternalContactBatchInfo getContactDetailBatch(String[] userIdList, String cursor,
207208
Integer limit)
208209
throws WxErrorException;
209210

@@ -273,24 +274,25 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
273274
* @param takeOverUserid the take over userid
274275
* @return wx cp base resp
275276
* @throws WxErrorException the wx error exception
276-
* @deprecated 此后续将不再更新维护,建议使用 {@link #transferCustomer(WxCpUserTransferCustomerReq)}
277+
* @deprecated 此后续将不再更新维护, 建议使用 {@link #transferCustomer(WxCpUserTransferCustomerReq)}
277278
*/
278279
@Deprecated
279280
WxCpBaseResp transferExternalContact(String externalUserid, String handOverUserid, String takeOverUserid) throws WxErrorException;
280281

281282
/**
282283
* 企业可通过此接口,转接在职成员的客户给其他成员。
283-
* <per>
284+
* <per>
284285
* external_userid必须是handover_userid的客户(即配置了客户联系功能的成员所添加的联系人)。
285286
* 在职成员的每位客户最多被分配2次。客户被转接成功后,将有90个自然日的服务关系保护期,保护期内的客户无法再次被分配。
286-
*
287+
* <p>
287288
* 权限说明:
288-
* * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
289+
* * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
289290
* 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限
290291
* 接替成员必须在此第三方应用或自建应用的可见范围内。
291292
* 接替成员需要配置了客户联系功能。
292293
* 接替成员需要在企业微信激活且已经过实名认证。
293-
* </per>
294+
* </per>
295+
*
294296
* @param req 转接在职成员的客户给其他成员请求实体
295297
* @return wx cp base resp
296298
* @throws WxErrorException the wx error exception
@@ -300,35 +302,37 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
300302
/**
301303
* 企业和第三方可通过此接口查询在职成员的客户转接情况。
302304
* <per>
303-
* 权限说明:
304-
*
305+
* 权限说明:
306+
* <p>
305307
* 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
306308
* 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限
307309
* 接替成员必须在此第三方应用或自建应用的可见范围内。
308310
* </per>
311+
*
309312
* @param handOverUserid 原添加成员的userid
310313
* @param takeOverUserid 接替成员的userid
311-
* @param cursor 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页;
314+
* @param cursor 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页;
312315
* @return 客户转接接口实体
313316
* @throws WxErrorException the wx error exception
314317
*/
315-
WxCpUserTransferResultResp transferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException;
318+
WxCpUserTransferResultResp transferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException;
316319

317320
/**
318321
* 企业可通过此接口,分配离职成员的客户给其他成员。
319-
* <per>
322+
* <per>
320323
* handover_userid必须是已离职用户。
321324
* external_userid必须是handover_userid的客户(即配置了客户联系功能的成员所添加的联系人)。
322325
* 在职成员的每位客户最多被分配2次。客户被转接成功后,将有90个自然日的服务关系保护期,保护期内的客户无法再次被分配。
323-
*
326+
* <p>
324327
* 权限说明:
325-
*
328+
* <p>
326329
* 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
327330
* 第三方应用需拥有“企业客户权限->客户联系->离职分配”权限
328331
* 接替成员必须在此第三方应用或自建应用的可见范围内。
329332
* 接替成员需要配置了客户联系功能。
330333
* 接替成员需要在企业微信激活且已经过实名认证。
331-
* </per>
334+
* </per>
335+
*
332336
* @param req 转接在职成员的客户给其他成员请求实体
333337
* @return wx cp base resp
334338
* @throws WxErrorException the wx error exception
@@ -339,18 +343,19 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
339343
* 企业和第三方可通过此接口查询离职成员的客户分配情况。
340344
* <per>
341345
* 权限说明:
342-
*
346+
* <p>
343347
* 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
344348
* 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限
345349
* 接替成员必须在此第三方应用或自建应用的可见范围内。
346350
* </per>
351+
*
347352
* @param handOverUserid 原添加成员的userid
348353
* @param takeOverUserid 接替成员的userid
349-
* @param cursor 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页;
354+
* @param cursor 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页;
350355
* @return 客户转接接口实体
351356
* @throws WxErrorException the wx error exception
352357
*/
353-
WxCpUserTransferResultResp resignedTransferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException;
358+
WxCpUserTransferResultResp resignedTransferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException;
354359

355360
/**
356361
* <pre>
@@ -360,14 +365,14 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
360365
* 微信文档:https://work.weixin.qq.com/api/doc/90000/90135/92119
361366
* </pre>
362367
*
363-
* @deprecated 请使用 {@link WxCpExternalContactService#listGroupChat(Integer, String, int, String[])}
364368
* @param pageIndex the page index
365369
* @param pageSize the page size
366370
* @param status the status
367371
* @param userIds the user ids
368372
* @param partyIds the party ids
369373
* @return the wx cp user external group chat list
370374
* @throws WxErrorException the wx error exception
375+
* @deprecated 请使用 {@link WxCpExternalContactService#listGroupChat(Integer, String, int, String[])}
371376
*/
372377
@Deprecated
373378
WxCpUserExternalGroupChatList listGroupChat(Integer pageIndex, Integer pageSize, int status, String[] userIds, String[] partyIds) throws WxErrorException;
@@ -380,10 +385,10 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
380385
* 微信文档:https://work.weixin.qq.com/api/doc/90000/90135/92119
381386
* </pre>
382387
*
383-
* @param limit 分页,预期请求的数据量,取值范围 1 ~ 1000
384-
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用不填
385-
* @param status 客户群跟进状态过滤。0 - 所有列表(即不过滤) 1 - 离职待继承 2 - 离职继承中 3 - 离职继承完成 默认为0
386-
* @param userIds 群主过滤。如果不填,表示获取应用可见范围内全部群主的数据(但是不建议这么用,如果可见范围人数超过1000人,为了防止数据包过大,会报错 81017);用户ID列表。最多100个
388+
* @param limit 分页,预期请求的数据量,取值范围 1 ~ 1000
389+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用不填
390+
* @param status 客户群跟进状态过滤。0 - 所有列表(即不过滤) 1 - 离职待继承 2 - 离职继承中 3 - 离职继承完成 默认为0
391+
* @param userIds 群主过滤。如果不填,表示获取应用可见范围内全部群主的数据(但是不建议这么用,如果可见范围人数超过1000人,为了防止数据包过大,会报错 81017);用户ID列表。最多100个
387392
* @return the wx cp user external group chat list
388393
* @throws WxErrorException the wx error exception
389394
*/
@@ -404,30 +409,30 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
404409
WxCpUserExternalGroupChatInfo getGroupChat(String chatId, Integer needName) throws WxErrorException;
405410

406411
/**
407-
*
408412
* 企业可通过此接口,将已离职成员为群主的群,分配给另一个客服成员。
409413
*
410414
* <per>
411415
* 注意::
412-
*
416+
* <p>
413417
* 群主离职了的客户群,才可继承
414418
* 继承给的新群主,必须是配置了客户联系功能的成员
415419
* 继承给的新群主,必须有设置实名
416420
* 继承给的新群主,必须有激活企业微信
417421
* 同一个人的群,限制每天最多分配300个给新群主
418-
*
422+
* <p>
419423
* 权限说明:
420-
*
424+
* <p>
421425
* 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
422426
* 第三方应用需拥有“企业客户权限->客户联系->分配离职成员的客户群”权限
423427
* 对于第三方/自建应用,群主必须在应用的可见范围。
424428
* </per>
425-
* @param chatIds 需要转群主的客户群ID列表。取值范围: 1 ~ 100
426-
* @param newOwner 新群主ID
429+
*
430+
* @param chatIds 需要转群主的客户群ID列表。取值范围: 1 ~ 100
431+
* @param newOwner 新群主ID
427432
* @return 分配结果,主要是分配失败的群列表
428-
* @throws WxErrorException the wx error exception
433+
* @throws WxErrorException the wx error exception
429434
*/
430-
WxCpUserExternalGroupChatTransferResp transferGroupChat(String[] chatIds, String newOwner) throws WxErrorException;
435+
WxCpUserExternalGroupChatTransferResp transferGroupChat(String[] chatIds, String newOwner) throws WxErrorException;
431436

432437
/**
433438
* <pre>
@@ -520,7 +525,7 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
520525
* 同时传递tag_id和group_id时,忽略tag_id,仅以group_id作为过滤条件。
521526
* </pre>
522527
*
523-
* @param tagId the tag id
528+
* @param tagId the tag id
524529
* @param groupId the tagGroup id
525530
* @return corp tag list
526531
* @throws WxErrorException the wx error exception

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public String unionidToExternalUserid(@NotNull String unionid) throws WxErrorExc
148148
}
149149

150150
@Override
151-
public WxCpExternalContactBatchInfo getContactDetailBatch(String userId,
151+
public WxCpExternalContactBatchInfo getContactDetailBatch(String[] userIdList,
152152
String cursor,
153153
Integer limit)
154154
throws WxErrorException {
@@ -157,7 +157,7 @@ public WxCpExternalContactBatchInfo getContactDetailBatch(String userId,
157157
.getWxCpConfigStorage()
158158
.getApiUrl(GET_CONTACT_DETAIL_BATCH);
159159
JsonObject json = new JsonObject();
160-
json.addProperty("userid", userId);
160+
json.add("userid_list", new Gson().toJsonTree(userIdList).getAsJsonArray());
161161
if (StringUtils.isNotBlank(cursor)) {
162162
json.addProperty("cursor", cursor);
163163
}

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import me.chanjar.weixin.cp.api.WxCpService;
88
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
99
import me.chanjar.weixin.cp.bean.external.*;
10+
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactBatchInfo;
1011
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
1112
import me.chanjar.weixin.cp.bean.external.msg.Attachment;
1213
import me.chanjar.weixin.cp.bean.external.msg.Image;
@@ -115,6 +116,14 @@ public void testGetContactDetail() throws WxErrorException {
115116
assertNotNull(result);
116117
}
117118

119+
@Test
120+
public void testGetContactDetailBatch() throws WxErrorException {
121+
String userId = this.configStorage.getUserId();
122+
WxCpExternalContactBatchInfo result = this.wxCpService.getExternalContactService().getContactDetailBatch(new String[]{userId}, "", 100);
123+
System.out.println(result);
124+
assertNotNull(result);
125+
}
126+
118127
@Test
119128
public void testGetCorpTagList() throws WxErrorException {
120129
String[] tag = {};
@@ -236,14 +245,14 @@ public void testresignedTrnsferResult() throws WxErrorException {
236245

237246
@Test
238247
public void testListGroupChat() throws WxErrorException {
239-
WxCpUserExternalGroupChatList result = this.wxCpService.getExternalContactService().listGroupChat(0, 100 ,0,new String[1],new String[1]);
248+
WxCpUserExternalGroupChatList result = this.wxCpService.getExternalContactService().listGroupChat(0, 100, 0, new String[1], new String[1]);
240249
System.out.println(result);
241250
assertNotNull(result);
242251
}
243252

244253
@Test
245254
public void testListGroupChatV3() throws WxErrorException {
246-
WxCpUserExternalGroupChatList result = this.wxCpService.getExternalContactService().listGroupChat(100, "" ,0,new String[1]);
255+
WxCpUserExternalGroupChatList result = this.wxCpService.getExternalContactService().listGroupChat(100, "", 0, new String[1]);
247256
System.out.println(result);
248257
assertNotNull(result);
249258
}
@@ -301,7 +310,7 @@ public void testUpdateRemark() throws WxErrorException {
301310
.externalUserId("aaa")
302311
.remark("aa")
303312
.remarkCompany("aaa")
304-
.remarkMobiles(new String[]{"111","222"})
313+
.remarkMobiles(new String[]{"111", "222"})
305314
.remarkPicMediaId("aaa")
306315
.build());
307316
}

0 commit comments

Comments
 (0)