Skip to content

Commit f4fa24f

Browse files
committed
Fix issue binarywang#2295: 批量获取外部客户详情支持多个userId
微信官方文档链接: https://work.weixin.qq.com/api/doc/90000/90135/92994
1 parent 2a36ebf commit f4fa24f

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 .
@@ -174,13 +175,13 @@ public interface WxCpExternalContactService {
174175
* 第三方/自建应用调用时,返回的跟进人follow_user仅包含应用可见范围之内的成员。
175176
* </pre>
176177
*
177-
* @param userId 企业成员的userid,注意不是外部联系人的帐号
178-
* @param cursor the cursor
179-
* @param limit the limit
178+
* @param userIdList 企业成员的userid列表,注意不是外部联系人的帐号
179+
* @param cursor the cursor
180+
* @param limit the limit
180181
* @return wx cp user external contact batch info
181182
* @throws WxErrorException .
182183
*/
183-
WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
184+
WxCpExternalContactBatchInfo getContactDetailBatch(String[] userIdList, String cursor,
184185
Integer limit)
185186
throws WxErrorException;
186187

@@ -250,24 +251,25 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
250251
* @param takeOverUserid the take over userid
251252
* @return wx cp base resp
252253
* @throws WxErrorException the wx error exception
253-
* @deprecated 此后续将不再更新维护,建议使用 {@link #transferCustomer(WxCpUserTransferCustomerReq)}
254+
* @deprecated 此后续将不再更新维护, 建议使用 {@link #transferCustomer(WxCpUserTransferCustomerReq)}
254255
*/
255256
@Deprecated
256257
WxCpBaseResp transferExternalContact(String externalUserid, String handOverUserid, String takeOverUserid) throws WxErrorException;
257258

258259
/**
259260
* 企业可通过此接口,转接在职成员的客户给其他成员。
260-
* <per>
261+
* <per>
261262
* external_userid必须是handover_userid的客户(即配置了客户联系功能的成员所添加的联系人)。
262263
* 在职成员的每位客户最多被分配2次。客户被转接成功后,将有90个自然日的服务关系保护期,保护期内的客户无法再次被分配。
263-
*
264+
* <p>
264265
* 权限说明:
265-
* * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
266+
* * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
266267
* 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限
267268
* 接替成员必须在此第三方应用或自建应用的可见范围内。
268269
* 接替成员需要配置了客户联系功能。
269270
* 接替成员需要在企业微信激活且已经过实名认证。
270-
* </per>
271+
* </per>
272+
*
271273
* @param req 转接在职成员的客户给其他成员请求实体
272274
* @return wx cp base resp
273275
* @throws WxErrorException the wx error exception
@@ -277,35 +279,37 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
277279
/**
278280
* 企业和第三方可通过此接口查询在职成员的客户转接情况。
279281
* <per>
280-
* 权限说明:
281-
*
282+
* 权限说明:
283+
* <p>
282284
* 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
283285
* 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限
284286
* 接替成员必须在此第三方应用或自建应用的可见范围内。
285287
* </per>
288+
*
286289
* @param handOverUserid 原添加成员的userid
287290
* @param takeOverUserid 接替成员的userid
288-
* @param cursor 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页;
291+
* @param cursor 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页;
289292
* @return 客户转接接口实体
290293
* @throws WxErrorException the wx error exception
291294
*/
292-
WxCpUserTransferResultResp transferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException;
295+
WxCpUserTransferResultResp transferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException;
293296

294297
/**
295298
* 企业可通过此接口,分配离职成员的客户给其他成员。
296-
* <per>
299+
* <per>
297300
* handover_userid必须是已离职用户。
298301
* external_userid必须是handover_userid的客户(即配置了客户联系功能的成员所添加的联系人)。
299302
* 在职成员的每位客户最多被分配2次。客户被转接成功后,将有90个自然日的服务关系保护期,保护期内的客户无法再次被分配。
300-
*
303+
* <p>
301304
* 权限说明:
302-
*
305+
* <p>
303306
* 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
304307
* 第三方应用需拥有“企业客户权限->客户联系->离职分配”权限
305308
* 接替成员必须在此第三方应用或自建应用的可见范围内。
306309
* 接替成员需要配置了客户联系功能。
307310
* 接替成员需要在企业微信激活且已经过实名认证。
308-
* </per>
311+
* </per>
312+
*
309313
* @param req 转接在职成员的客户给其他成员请求实体
310314
* @return wx cp base resp
311315
* @throws WxErrorException the wx error exception
@@ -316,18 +320,19 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
316320
* 企业和第三方可通过此接口查询离职成员的客户分配情况。
317321
* <per>
318322
* 权限说明:
319-
*
323+
* <p>
320324
* 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
321325
* 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限
322326
* 接替成员必须在此第三方应用或自建应用的可见范围内。
323327
* </per>
328+
*
324329
* @param handOverUserid 原添加成员的userid
325330
* @param takeOverUserid 接替成员的userid
326-
* @param cursor 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页;
331+
* @param cursor 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页;
327332
* @return 客户转接接口实体
328333
* @throws WxErrorException the wx error exception
329334
*/
330-
WxCpUserTransferResultResp resignedTransferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException;
335+
WxCpUserTransferResultResp resignedTransferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException;
331336

332337
/**
333338
* <pre>
@@ -337,14 +342,14 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
337342
* 微信文档:https://work.weixin.qq.com/api/doc/90000/90135/92119
338343
* </pre>
339344
*
340-
* @deprecated 请使用 {@link WxCpExternalContactService#listGroupChat(Integer, String, int, String[])}
341345
* @param pageIndex the page index
342346
* @param pageSize the page size
343347
* @param status the status
344348
* @param userIds the user ids
345349
* @param partyIds the party ids
346350
* @return the wx cp user external group chat list
347351
* @throws WxErrorException the wx error exception
352+
* @deprecated 请使用 {@link WxCpExternalContactService#listGroupChat(Integer, String, int, String[])}
348353
*/
349354
@Deprecated
350355
WxCpUserExternalGroupChatList listGroupChat(Integer pageIndex, Integer pageSize, int status, String[] userIds, String[] partyIds) throws WxErrorException;
@@ -357,10 +362,10 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
357362
* 微信文档:https://work.weixin.qq.com/api/doc/90000/90135/92119
358363
* </pre>
359364
*
360-
* @param limit 分页,预期请求的数据量,取值范围 1 ~ 1000
361-
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用不填
362-
* @param status 客户群跟进状态过滤。0 - 所有列表(即不过滤) 1 - 离职待继承 2 - 离职继承中 3 - 离职继承完成 默认为0
363-
* @param userIds 群主过滤。如果不填,表示获取应用可见范围内全部群主的数据(但是不建议这么用,如果可见范围人数超过1000人,为了防止数据包过大,会报错 81017);用户ID列表。最多100个
365+
* @param limit 分页,预期请求的数据量,取值范围 1 ~ 1000
366+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用不填
367+
* @param status 客户群跟进状态过滤。0 - 所有列表(即不过滤) 1 - 离职待继承 2 - 离职继承中 3 - 离职继承完成 默认为0
368+
* @param userIds 群主过滤。如果不填,表示获取应用可见范围内全部群主的数据(但是不建议这么用,如果可见范围人数超过1000人,为了防止数据包过大,会报错 81017);用户ID列表。最多100个
364369
* @return the wx cp user external group chat list
365370
* @throws WxErrorException the wx error exception
366371
*/
@@ -381,30 +386,30 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
381386
WxCpUserExternalGroupChatInfo getGroupChat(String chatId, Integer needName) throws WxErrorException;
382387

383388
/**
384-
*
385389
* 企业可通过此接口,将已离职成员为群主的群,分配给另一个客服成员。
386390
*
387391
* <per>
388392
* 注意::
389-
*
393+
* <p>
390394
* 群主离职了的客户群,才可继承
391395
* 继承给的新群主,必须是配置了客户联系功能的成员
392396
* 继承给的新群主,必须有设置实名
393397
* 继承给的新群主,必须有激活企业微信
394398
* 同一个人的群,限制每天最多分配300个给新群主
395-
*
399+
* <p>
396400
* 权限说明:
397-
*
401+
* <p>
398402
* 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。
399403
* 第三方应用需拥有“企业客户权限->客户联系->分配离职成员的客户群”权限
400404
* 对于第三方/自建应用,群主必须在应用的可见范围。
401405
* </per>
402-
* @param chatIds 需要转群主的客户群ID列表。取值范围: 1 ~ 100
403-
* @param newOwner 新群主ID
406+
*
407+
* @param chatIds 需要转群主的客户群ID列表。取值范围: 1 ~ 100
408+
* @param newOwner 新群主ID
404409
* @return 分配结果,主要是分配失败的群列表
405-
* @throws WxErrorException the wx error exception
410+
* @throws WxErrorException the wx error exception
406411
*/
407-
WxCpUserExternalGroupChatTransferResp transferGroupChat(String[] chatIds, String newOwner) throws WxErrorException;
412+
WxCpUserExternalGroupChatTransferResp transferGroupChat(String[] chatIds, String newOwner) throws WxErrorException;
408413

409414
/**
410415
* <pre>
@@ -497,7 +502,7 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor,
497502
* 同时传递tag_id和group_id时,忽略tag_id,仅以group_id作为过滤条件。
498503
* </pre>
499504
*
500-
* @param tagId the tag id
505+
* @param tagId the tag id
501506
* @param groupId the tagGroup id
502507
* @return corp tag list
503508
* @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
@@ -138,7 +138,7 @@ public String convertToOpenid(@NotNull String externalUserId) throws WxErrorExce
138138
}
139139

140140
@Override
141-
public WxCpExternalContactBatchInfo getContactDetailBatch(String userId,
141+
public WxCpExternalContactBatchInfo getContactDetailBatch(String[] userIdList,
142142
String cursor,
143143
Integer limit)
144144
throws WxErrorException {
@@ -147,7 +147,7 @@ public WxCpExternalContactBatchInfo getContactDetailBatch(String userId,
147147
.getWxCpConfigStorage()
148148
.getApiUrl(GET_CONTACT_DETAIL_BATCH);
149149
JsonObject json = new JsonObject();
150-
json.addProperty("userid", userId);
150+
json.add("userid_list", new Gson().toJsonTree(userIdList).getAsJsonArray());
151151
if (StringUtils.isNotBlank(cursor)) {
152152
json.addProperty("cursor", cursor);
153153
}

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)