Skip to content

Commit 62645a4

Browse files
0katekate0binarywang
authored andcommitted
🎨 #2563 【企业微信】优化获取待分配离职成员列表的接口,增加分页查询游标参数
1 parent 1893790 commit 62645a4

File tree

4 files changed

+81
-11
lines changed

4 files changed

+81
-11
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,19 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String[] userIdList, String c
361361
List<String> listFollowers() throws WxErrorException;
362362

363363
/**
364-
* 企业和第三方可通过此接口,获取所有离职成员的客户列表,并可进一步调用离职成员的外部联系人再分配接口将这些客户重新分配给其他企业成员。
364+
* 获取待分配的离职成员列表
365+
* 企业和第三方可通过此接口,获取所有离职成员的客户列表,并可进一步调用分配离职成员的客户接口将这些客户重新分配给其他企业成员。
365366
*
366-
* @param page the page
367-
* @param pageSize the page size
368-
* @return wx cp user external unassign list
369-
* @throws WxErrorException the wx error exception
367+
* 请求方式:POST(HTTPS)
368+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_unassigned_list?access_token=ACCESS_TOKEN
369+
*
370+
* @param pageId 分页查询,要查询页号,从0开始
371+
* @param cursor 分页查询游标,字符串类型,适用于数据量较大的情况,如果使用该参数则无需填写page_id,该参数由上一次调用返回
372+
* @param pageSize 每次返回的最大记录数,默认为1000,最大值为1000
373+
* @return
374+
* @throws WxErrorException
370375
*/
371-
WxCpUserExternalUnassignList listUnassignedList(Integer page, Integer pageSize) throws WxErrorException;
376+
WxCpUserExternalUnassignList listUnassignedList(Integer pageId, String cursor, Integer pageSize) throws WxErrorException;
372377

373378
/**
374379
* 企业可通过此接口,将已离职成员的外部联系人分配给另一个成员接替联系。

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.ExternalContact.*;
3333

3434
/**
35-
* @author 曹祖鹏 & yuanqixun & Mr.Pan
35+
* @author 曹祖鹏 & yuanqixun & Mr.Pan & Wang_Wong
3636
*/
3737
@RequiredArgsConstructor
3838
public class WxCpExternalContactServiceImpl implements WxCpExternalContactService {
@@ -245,10 +245,13 @@ public List<String> listFollowers() throws WxErrorException {
245245
}
246246

247247
@Override
248-
public WxCpUserExternalUnassignList listUnassignedList(Integer pageIndex, Integer pageSize) throws WxErrorException {
248+
public WxCpUserExternalUnassignList listUnassignedList(Integer pageIndex, String cursor, Integer pageSize) throws WxErrorException {
249249
JsonObject json = new JsonObject();
250-
json.addProperty("page_id", pageIndex == null ? 0 : pageIndex);
251-
json.addProperty("page_size", pageSize == null ? 100 : pageSize);
250+
if(pageIndex != null){
251+
json.addProperty("page_id", pageIndex);
252+
}
253+
json.addProperty("cursor", StringUtils.isEmpty(cursor) ? "" : cursor);
254+
json.addProperty("page_size", pageSize == null ? 1000 : pageSize);
252255
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_UNASSIGNED_CONTACT);
253256
final String result = this.mainService.post(url, json.toString());
254257
return WxCpUserExternalUnassignList.fromJson(result);

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserExternalUnassignList.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* 离职员工外部联系人列表
1414
*
15-
* @author yqx
15+
* @author yqx & Wang_Wong
1616
* @date 2020/3/15
1717
*/
1818
@Getter
@@ -25,6 +25,9 @@ public class WxCpUserExternalUnassignList extends WxCpBaseResp {
2525
@SerializedName("is_last")
2626
private boolean isLast;
2727

28+
@SerializedName("next_cursor")
29+
private String nextCursor;
30+
2831
@Getter
2932
@Setter
3033
public static class UnassignInfo implements Serializable {
@@ -52,4 +55,9 @@ public static class UnassignInfo implements Serializable {
5255
public static WxCpUserExternalUnassignList fromJson(String json) {
5356
return WxCpGsonBuilder.create().fromJson(json, WxCpUserExternalUnassignList.class);
5457
}
58+
59+
public String toJson() {
60+
return WxCpGsonBuilder.create().toJson(this);
61+
}
62+
5563
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import com.google.common.collect.Lists;
4+
import com.google.inject.Inject;
5+
import lombok.extern.slf4j.Slf4j;
6+
import me.chanjar.weixin.common.error.WxErrorException;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.bean.external.*;
9+
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactBatchInfo;
10+
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
11+
import me.chanjar.weixin.cp.bean.external.msg.Attachment;
12+
import me.chanjar.weixin.cp.bean.external.msg.Image;
13+
import me.chanjar.weixin.cp.bean.external.msg.Video;
14+
import org.apache.commons.lang3.time.DateFormatUtils;
15+
import org.testng.annotations.Guice;
16+
import org.testng.annotations.Test;
17+
import org.testng.collections.CollectionUtils;
18+
19+
import java.util.ArrayList;
20+
import java.util.Collections;
21+
import java.util.Date;
22+
import java.util.List;
23+
24+
import static org.testng.Assert.assertNotNull;
25+
26+
/**
27+
* 离职继承测试类
28+
*
29+
* 官方文档:
30+
* https://developer.work.weixin.qq.com/document/path/92124
31+
*/
32+
@Slf4j
33+
@Guice(modules = ApiTestModule.class)
34+
public class WxCpExternalContactTest {
35+
36+
@Inject
37+
private WxCpService wxCpService;
38+
@Inject
39+
protected ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage;
40+
41+
@Test
42+
public void testGetExternalContact() throws WxErrorException {
43+
String externalUserId = this.configStorage.getExternalUserId();
44+
WxCpUserExternalUnassignList unassignList = this.wxCpService.getExternalContactService().listUnassignedList(null, null, 100);
45+
log.info(unassignList.toJson());
46+
47+
// test str
48+
String result = "{\"errcode\":0,\"errmsg\":\"ok\",\"info\":[{\"handover_userid\":\"zhangsan\",\"external_userid\":\"woAJ2GCAAAd4uL12hdfsdasassdDmAAAAA\",\"dimission_time\":1550838571},{\"handover_userid\":\"lisi\",\"external_userid\":\"wmAJ2GCAAAzLTI123ghsdfoGZNqqAAAA\",\"dimission_time\":1550661468}],\"is_last\":false,\"next_cursor\":\"aSfwejksvhToiMMfFeIGZZ\"}";
49+
WxCpUserExternalUnassignList json = WxCpUserExternalUnassignList.fromJson(result);
50+
log.info(json.toJson());
51+
52+
}
53+
54+
}

0 commit comments

Comments
 (0)