Skip to content

Commit cfde76e

Browse files
Copilotbinarywang
andcommitted
添加获取应用管理员列表接口
Co-authored-by: binarywang <[email protected]>
1 parent 4590997 commit cfde76e

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import me.chanjar.weixin.common.error.WxErrorException;
44
import me.chanjar.weixin.cp.bean.WxCpAgent;
5+
import me.chanjar.weixin.cp.bean.WxCpTpAdmin;
56

67
import java.util.List;
78

@@ -52,4 +53,18 @@ public interface WxCpAgentService {
5253
*/
5354
List<WxCpAgent> list() throws WxErrorException;
5455

56+
/**
57+
* <pre>
58+
* 获取应用管理员列表
59+
* 第三方服务商可以用此接口获取授权企业中某个第三方应用或者代开发应用的管理员列表(不包括外部管理员),
60+
* 以便服务商在用户进入应用主页之后根据是否管理员身份做权限的区分。
61+
* 详情请见: <a href="https://developer.work.weixin.qq.com/document/path/90506">文档</a>
62+
* </pre>
63+
*
64+
* @param agentId 应用id
65+
* @return admin list
66+
* @throws WxErrorException the wx error exception
67+
*/
68+
WxCpTpAdmin getAdminList(Integer agentId) throws WxErrorException;
69+
5570
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import me.chanjar.weixin.cp.api.WxCpAgentService;
1212
import me.chanjar.weixin.cp.api.WxCpService;
1313
import me.chanjar.weixin.cp.bean.WxCpAgent;
14+
import me.chanjar.weixin.cp.bean.WxCpTpAdmin;
1415
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
1516

1617
import java.util.List;
@@ -65,4 +66,17 @@ public List<WxCpAgent> list() throws WxErrorException {
6566
}.getType());
6667
}
6768

69+
@Override
70+
public WxCpTpAdmin getAdminList(Integer agentId) throws WxErrorException {
71+
if (agentId == null) {
72+
throw new IllegalArgumentException("缺少agentid参数");
73+
}
74+
75+
JsonObject jsonObject = new JsonObject();
76+
jsonObject.addProperty("agentid", agentId);
77+
String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_GET_ADMIN_LIST);
78+
String responseContent = this.mainService.post(url, jsonObject.toString());
79+
return WxCpTpAdmin.fromJson(responseContent);
80+
}
81+
6882
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ interface Agent {
112112
* The constant AGENT_LIST.
113113
*/
114114
String AGENT_LIST = "/cgi-bin/agent/list";
115+
/**
116+
* The constant AGENT_GET_ADMIN_LIST.
117+
*/
118+
String AGENT_GET_ADMIN_LIST = "/cgi-bin/agent/get_admin_list";
115119
}
116120

117121
/**

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ public void testList() throws WxErrorException {
8282
assertThat(list.get(0).getSquareLogoUrl()).isNotEmpty();
8383
}
8484

85+
/**
86+
* Test get admin list.
87+
*
88+
* @throws WxErrorException the wx error exception
89+
*/
90+
@Test
91+
public void testGetAdminList() throws WxErrorException {
92+
final Integer agentId = this.wxCpService.getWxCpConfigStorage().getAgentId();
93+
me.chanjar.weixin.cp.bean.WxCpTpAdmin adminList = this.wxCpService.getAgentService().getAdminList(agentId);
94+
95+
assertThat(adminList).isNotNull();
96+
assertThat(adminList.getErrCode()).isEqualTo(0);
97+
}
98+
8599
/**
86100
* The type Mock test.
87101
*/
@@ -118,6 +132,31 @@ public void testGet() throws Exception {
118132

119133
}
120134

135+
/**
136+
* Test get admin list.
137+
*
138+
* @throws Exception the exception
139+
*/
140+
@Test
141+
public void testGetAdminList() throws Exception {
142+
String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"admin\": [{\"userid\": \"zhangsan\"," +
143+
"\"open_userid\": \"woAJ2GCAAAXtWyujaWJHDDGi0mACH71w\",\"auth_type\": 1}," +
144+
"{\"userid\": \"lisi\",\"open_userid\": \"woAJ2GCAAAXtWyujaWJHDDGi0mACH72w\",\"auth_type\": 2}]}";
145+
final WxCpConfigStorage configStorage = new WxCpDefaultConfigImpl();
146+
when(wxService.getWxCpConfigStorage()).thenReturn(configStorage);
147+
when(wxService.post(configStorage.getApiUrl(WxCpApiPathConsts.Agent.AGENT_GET_ADMIN_LIST), "{\"agentid\":9}")).thenReturn(returnJson);
148+
when(wxService.getAgentService()).thenReturn(new WxCpAgentServiceImpl(wxService));
149+
150+
WxCpAgentService wxAgentService = this.wxService.getAgentService();
151+
me.chanjar.weixin.cp.bean.WxCpTpAdmin adminList = wxAgentService.getAdminList(9);
152+
153+
assertEquals(0, adminList.getErrCode().intValue());
154+
assertEquals(2, adminList.getAdmin().size());
155+
assertEquals("zhangsan", adminList.getAdmin().get(0).getUserId());
156+
assertEquals("woAJ2GCAAAXtWyujaWJHDDGi0mACH71w", adminList.getAdmin().get(0).getOpenUserId());
157+
assertEquals(1, adminList.getAdmin().get(0).getAuthType().intValue());
158+
}
159+
121160
}
122161

123162
}

0 commit comments

Comments
 (0)