1
0
mirror of synced 2026-02-11 06:07:48 +08:00

#456 企业微信获取部门列表接口方法listAll修改为list,以支持按部分id获取其下属部门列表

This commit is contained in:
Binary Wang
2018-03-18 14:25:22 +08:00
parent e3293d1521
commit 0c7a472a16
4 changed files with 30 additions and 14 deletions

View File

@@ -29,11 +29,12 @@ public interface WxCpDepartmentService {
/**
* <pre>
* 部门管理接口 - 查询所有部门
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
* 部门管理接口 - 查询部门
* 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E9%83%A8%E9%97%A8#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E5.88.97.E8.A1.A8
* </pre>
* @param id 部门id。获取指定部门及其下的子部门。非必需可为null
*/
List<WxCpDepart> listAll() throws WxErrorException;
List<WxCpDepart> list(Integer id) throws WxErrorException;
/**
* <pre>

View File

@@ -48,13 +48,13 @@ public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
}
@Override
public List<WxCpDepart> listAll() throws WxErrorException {
public List<WxCpDepart> list(Integer id) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
if (id != null) {
url += "?id=" + id;
}
String responseContent = this.mainService.get(url, null);
/*
* 操蛋的微信API创建时返回的是 { group : { id : ..., name : ...} }
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
*/
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.INSTANCE.create()
.fromJson(tmpJsonElement.getAsJsonObject().get("department"),