1
0
mirror of synced 2026-02-11 14:17:48 +08:00

🆕 #3823 【企业微信】添加获取应用管理员列表的接口

This commit is contained in:
Copilot
2025-12-24 16:14:20 +08:00
committed by GitHub
parent 912ba354e9
commit 6504f5d82c
4 changed files with 99 additions and 0 deletions

View File

@@ -1,11 +1,14 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.inject.Inject;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.ApiTestModule;
import me.chanjar.weixin.cp.api.WxCpAgentService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpAgent;
import me.chanjar.weixin.cp.bean.WxCpTpAdmin;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
@@ -82,6 +85,20 @@ public class WxCpAgentServiceImplTest {
assertThat(list.get(0).getSquareLogoUrl()).isNotEmpty();
}
/**
* Test get admin list.
*
* @throws WxErrorException the wx error exception
*/
@Test
public void testGetAdminList() throws WxErrorException {
final Integer agentId = this.wxCpService.getWxCpConfigStorage().getAgentId();
WxCpTpAdmin adminList = this.wxCpService.getAgentService().getAdminList(agentId);
assertThat(adminList).isNotNull();
assertThat(adminList.getErrcode()).isEqualTo(0L);
}
/**
* The type Mock test.
*/
@@ -118,6 +135,51 @@ public class WxCpAgentServiceImplTest {
}
/**
* Test get admin list.
*
* @throws Exception the exception
*/
@Test
public void testGetAdminList() throws Exception {
// 构建响应JSON
JsonObject admin1 = new JsonObject();
admin1.addProperty("userid", "zhangsan");
admin1.addProperty("open_userid", "woAJ2GCAAAXtWyujaWJHDDGi0mACH71w");
admin1.addProperty("auth_type", 1);
JsonObject admin2 = new JsonObject();
admin2.addProperty("userid", "lisi");
admin2.addProperty("open_userid", "woAJ2GCAAAXtWyujaWJHDDGi0mACH72w");
admin2.addProperty("auth_type", 2);
JsonArray adminArray = new JsonArray();
adminArray.add(admin1);
adminArray.add(admin2);
JsonObject returnJsonObj = new JsonObject();
returnJsonObj.addProperty("errcode", 0);
returnJsonObj.addProperty("errmsg", "ok");
returnJsonObj.add("admin", adminArray);
String returnJson = returnJsonObj.toString();
JsonObject requestJson = new JsonObject();
requestJson.addProperty("agentid", 9);
final WxCpConfigStorage configStorage = new WxCpDefaultConfigImpl();
when(wxService.getWxCpConfigStorage()).thenReturn(configStorage);
when(wxService.post(configStorage.getApiUrl(WxCpApiPathConsts.Agent.AGENT_GET_ADMIN_LIST), requestJson.toString())).thenReturn(returnJson);
when(wxService.getAgentService()).thenReturn(new WxCpAgentServiceImpl(wxService));
WxCpAgentService wxAgentService = this.wxService.getAgentService();
WxCpTpAdmin adminList = wxAgentService.getAdminList(9);
assertEquals(0, adminList.getErrcode().intValue());
assertEquals(2, adminList.getAdmin().size());
assertEquals("zhangsan", adminList.getAdmin().get(0).getUserId());
assertEquals("woAJ2GCAAAXtWyujaWJHDDGi0mACH71w", adminList.getAdmin().get(0).getOpenUserId());
assertEquals(1, adminList.getAdmin().get(0).getAuthType().intValue());
}
}
}