Skip to content

Commit b8dd366

Browse files
committed
issue #79 增加批量获取用户详情的接口
1 parent 2c218d8 commit b8dd366

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,25 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
197197
void departDelete(Integer departId) throws WxErrorException;
198198

199199
/**
200+
* <pre>
201+
* 获取部门成员(详情)
202+
*
203+
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98.28.E8.AF.A6.E6.83.85.29
204+
* </pre>
205+
* @param departId 必填。部门id
206+
* @param fetchChild 非必填。1/0:是否递归获取子部门下面的成员
207+
* @param status 非必填。0获取全部员工,1获取已关注成员列表,2获取禁用成员列表,4获取未关注成员列表。status可叠加
208+
* @return
209+
* @throws WxErrorException
210+
*/
211+
List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException;
212+
213+
/**
214+
* <pre>
215+
* 获取部门成员
216+
*
200217
* http://qydev.weixin.qq.com/wiki/index.php?title=管理成员#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E6.88.90.E5.91.98
218+
* </pre>
201219
*
202220
* @param departId 必填。部门id
203221
* @param fetchChild 非必填。1/0:是否递归获取子部门下面的成员

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,28 @@ public WxCpUser userGet(String userid) throws WxErrorException {
226226
return WxCpUser.fromJson(responseContent);
227227
}
228228

229+
@Override
230+
public List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
231+
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=" + departId;
232+
String params = "";
233+
if (fetchChild != null) {
234+
params += "&fetch_child=" + (fetchChild ? "1" : "0");
235+
}
236+
if (status != null) {
237+
params += "&status=" + status;
238+
} else {
239+
params += "&status=0";
240+
}
241+
242+
String responseContent = get(url, params);
243+
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
244+
return WxCpGsonBuilder.INSTANCE.create()
245+
.fromJson(
246+
tmpJsonElement.getAsJsonObject().get("userlist"),
247+
new TypeToken<List<WxCpUser>>() { }.getType()
248+
);
249+
}
250+
229251
@Override
230252
public List<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
231253
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=" + departId;

0 commit comments

Comments
 (0)