From 6504f5d82cf6ee87f6839b42b697201eda7f443b Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 16:14:20 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#3823=20=E3=80=90=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E3=80=91=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E7=AE=A1=E7=90=86=E5=91=98=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/cp/api/WxCpAgentService.java | 15 +++++ .../cp/api/impl/WxCpAgentServiceImpl.java | 18 ++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 4 ++ .../cp/api/impl/WxCpAgentServiceImplTest.java | 62 +++++++++++++++++++ 4 files changed, 99 insertions(+) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java index 9eddc0f50..05f06f1da 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpAgentService.java @@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.api; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.bean.WxCpAgent; +import me.chanjar.weixin.cp.bean.WxCpTpAdmin; import java.util.List; @@ -52,4 +53,18 @@ public interface WxCpAgentService { */ List list() throws WxErrorException; + /** + *
+   * 获取应用管理员列表
+   * 第三方服务商可以用此接口获取授权企业中某个第三方应用或者代开发应用的管理员列表(不包括外部管理员),
+   * 以便服务商在用户进入应用主页之后根据是否管理员身份做权限的区分。
+   * 详情请见: 文档
+   * 
+ * + * @param agentId 应用id + * @return admin list + * @throws WxErrorException the wx error exception + */ + WxCpTpAdmin getAdminList(Integer agentId) throws WxErrorException; + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java index 81628fed8..cc08d33bb 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java @@ -11,6 +11,7 @@ import me.chanjar.weixin.common.util.json.GsonParser; 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.util.json.WxCpGsonBuilder; import java.util.List; @@ -65,4 +66,21 @@ public class WxCpAgentServiceImpl implements WxCpAgentService { }.getType()); } + @Override + public WxCpTpAdmin getAdminList(Integer agentId) throws WxErrorException { + if (agentId == null) { + throw new IllegalArgumentException("缺少agentid参数"); + } + + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("agentid", agentId); + String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_GET_ADMIN_LIST); + String responseContent = this.mainService.post(url, jsonObject.toString()); + JsonObject respObj = GsonParser.parse(responseContent); + if (respObj.get(WxConsts.ERR_CODE).getAsInt() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.CP)); + } + return WxCpTpAdmin.fromJson(responseContent); + } + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index ad4d4f33f..ade813ef5 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -112,6 +112,10 @@ public interface WxCpApiPathConsts { * The constant AGENT_LIST. */ String AGENT_LIST = "/cgi-bin/agent/list"; + /** + * The constant AGENT_GET_ADMIN_LIST. + */ + String AGENT_GET_ADMIN_LIST = "/cgi-bin/agent/get_admin_list"; } /** diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java index 07438056c..cbd947b92 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpAgentServiceImplTest.java @@ -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()); + } + } }