issue #79 增加批量获取用户详情的接口

This commit is contained in:
Daniel Qian
2015-01-24 15:18:31 +08:00
parent 2c218d85c2
commit b8dd3662cd
2 changed files with 40 additions and 0 deletions

View File

@@ -197,7 +197,25 @@ public interface WxCpService {
void departDelete(Integer departId) throws WxErrorException;
/**
* <pre>
* 获取部门成员(详情)
*
* 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
* </pre>
* @param departId 必填。部门id
* @param fetchChild 非必填。1/0是否递归获取子部门下面的成员
* @param status 非必填。0获取全部员工1获取已关注成员列表2获取禁用成员列表4获取未关注成员列表。status可叠加
* @return
* @throws WxErrorException
*/
List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException;
/**
* <pre>
* 获取部门成员
*
* 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
* </pre>
*
* @param departId 必填。部门id
* @param fetchChild 非必填。1/0是否递归获取子部门下面的成员

View File

@@ -226,6 +226,28 @@ public class WxCpServiceImpl implements WxCpService {
return WxCpUser.fromJson(responseContent);
}
@Override
public List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=" + departId;
String params = "";
if (fetchChild != null) {
params += "&fetch_child=" + (fetchChild ? "1" : "0");
}
if (status != null) {
params += "&status=" + status;
} else {
params += "&status=0";
}
String responseContent = get(url, params);
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
return WxCpGsonBuilder.INSTANCE.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("userlist"),
new TypeToken<List<WxCpUser>>() { }.getType()
);
}
@Override
public List<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=" + departId;