From 4590997191b65ead09f8c66abe45ff4e87c0b41e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 07:07:14 +0000 Subject: [PATCH 1/5] Initial plan From cfde76e46bbcf158bd4f57b84731cd004d0a5d44 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 07:15:39 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=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?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com> --- .../weixin/cp/api/WxCpAgentService.java | 15 +++++++ .../cp/api/impl/WxCpAgentServiceImpl.java | 14 +++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 4 ++ .../cp/api/impl/WxCpAgentServiceImplTest.java | 39 +++++++++++++++++++ 4 files changed, 72 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 9eddc0f507..05f06f1da9 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 @@ 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 81628fed82..48fc90cd50 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.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,17 @@ public List list() throws WxErrorException { }.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()); + 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 ad4d4f33f2..ade813ef5c 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 @@ interface Agent { * 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 07438056c3..8fbe05fae3 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 @@ -82,6 +82,20 @@ public void testList() throws WxErrorException { 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(); + me.chanjar.weixin.cp.bean.WxCpTpAdmin adminList = this.wxCpService.getAgentService().getAdminList(agentId); + + assertThat(adminList).isNotNull(); + assertThat(adminList.getErrCode()).isEqualTo(0); + } + /** * The type Mock test. */ @@ -118,6 +132,31 @@ public void testGet() throws Exception { } + /** + * Test get admin list. + * + * @throws Exception the exception + */ + @Test + public void testGetAdminList() throws Exception { + String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"admin\": [{\"userid\": \"zhangsan\"," + + "\"open_userid\": \"woAJ2GCAAAXtWyujaWJHDDGi0mACH71w\",\"auth_type\": 1}," + + "{\"userid\": \"lisi\",\"open_userid\": \"woAJ2GCAAAXtWyujaWJHDDGi0mACH72w\",\"auth_type\": 2}]}"; + final WxCpConfigStorage configStorage = new WxCpDefaultConfigImpl(); + when(wxService.getWxCpConfigStorage()).thenReturn(configStorage); + when(wxService.post(configStorage.getApiUrl(WxCpApiPathConsts.Agent.AGENT_GET_ADMIN_LIST), "{\"agentid\":9}")).thenReturn(returnJson); + when(wxService.getAgentService()).thenReturn(new WxCpAgentServiceImpl(wxService)); + + WxCpAgentService wxAgentService = this.wxService.getAgentService(); + me.chanjar.weixin.cp.bean.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()); + } + } } From a88fc7119d8fc730892101ff3971b9cc627bae70 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 07:20:40 +0000 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=AE=A1=E6=9F=A5=E9=97=AE=E9=A2=98=EF=BC=9A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=A3=80=E6=9F=A5=E5=92=8C=E6=94=B9=E8=BF=9B?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com> --- .../chanjar/weixin/cp/api/impl/WxCpAgentServiceImpl.java | 6 +++++- .../weixin/cp/api/impl/WxCpAgentServiceImplTest.java | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) 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 48fc90cd50..38a16ce8d3 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 @@ -76,7 +76,11 @@ public WxCpTpAdmin getAdminList(Integer agentId) throws WxErrorException { jsonObject.addProperty("agentid", agentId); String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_GET_ADMIN_LIST); String responseContent = this.mainService.post(url, jsonObject.toString()); - return WxCpTpAdmin.fromJson(responseContent); + WxCpTpAdmin result = WxCpTpAdmin.fromJson(responseContent); + if (result.getErrcode() != null && result.getErrcode() != 0) { + throw new WxErrorException(WxError.fromJson(responseContent, WxType.CP)); + } + return result; } } 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 8fbe05fae3..b34fd523aa 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,5 +1,6 @@ package me.chanjar.weixin.cp.api.impl; +import com.google.gson.JsonObject; import com.google.inject.Inject; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.ApiTestModule; @@ -93,7 +94,7 @@ public void testGetAdminList() throws WxErrorException { me.chanjar.weixin.cp.bean.WxCpTpAdmin adminList = this.wxCpService.getAgentService().getAdminList(agentId); assertThat(adminList).isNotNull(); - assertThat(adminList.getErrCode()).isEqualTo(0); + assertThat(adminList.getErrcode()).isEqualTo(0L); } /** @@ -142,15 +143,17 @@ public void testGetAdminList() throws Exception { String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"admin\": [{\"userid\": \"zhangsan\"," + "\"open_userid\": \"woAJ2GCAAAXtWyujaWJHDDGi0mACH71w\",\"auth_type\": 1}," + "{\"userid\": \"lisi\",\"open_userid\": \"woAJ2GCAAAXtWyujaWJHDDGi0mACH72w\",\"auth_type\": 2}]}"; + 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), "{\"agentid\":9}")).thenReturn(returnJson); + 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(); me.chanjar.weixin.cp.bean.WxCpTpAdmin adminList = wxAgentService.getAdminList(9); - assertEquals(0, adminList.getErrCode().intValue()); + assertEquals(0, adminList.getErrcode().intValue()); assertEquals(2, adminList.getAdmin().size()); assertEquals("zhangsan", adminList.getAdmin().get(0).getUserId()); assertEquals("woAJ2GCAAAXtWyujaWJHDDGi0mACH71w", adminList.getAdmin().get(0).getOpenUserId()); From 30608d2e1e331517d393e9e982c686c41ea22d6a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 07:23:31 +0000 Subject: [PATCH 4/5] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E6=80=A7=EF=BC=9A=E4=BD=BF=E7=94=A8GsonParse?= =?UTF-8?q?r=E8=BF=9B=E8=A1=8C=E9=94=99=E8=AF=AF=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8JsonObject=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com> --- .../cp/api/impl/WxCpAgentServiceImpl.java | 6 ++--- .../cp/api/impl/WxCpAgentServiceImplTest.java | 24 ++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) 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 38a16ce8d3..cc08d33bb1 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 @@ -76,11 +76,11 @@ public WxCpTpAdmin getAdminList(Integer agentId) throws WxErrorException { jsonObject.addProperty("agentid", agentId); String url = this.mainService.getWxCpConfigStorage().getApiUrl(AGENT_GET_ADMIN_LIST); String responseContent = this.mainService.post(url, jsonObject.toString()); - WxCpTpAdmin result = WxCpTpAdmin.fromJson(responseContent); - if (result.getErrcode() != null && result.getErrcode() != 0) { + JsonObject respObj = GsonParser.parse(responseContent); + if (respObj.get(WxConsts.ERR_CODE).getAsInt() != 0) { throw new WxErrorException(WxError.fromJson(responseContent, WxType.CP)); } - return result; + return WxCpTpAdmin.fromJson(responseContent); } } 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 b34fd523aa..b72199eb03 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 @@ -140,9 +140,27 @@ public void testGet() throws Exception { */ @Test public void testGetAdminList() throws Exception { - String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"admin\": [{\"userid\": \"zhangsan\"," + - "\"open_userid\": \"woAJ2GCAAAXtWyujaWJHDDGi0mACH71w\",\"auth_type\": 1}," + - "{\"userid\": \"lisi\",\"open_userid\": \"woAJ2GCAAAXtWyujaWJHDDGi0mACH72w\",\"auth_type\": 2}]}"; + // 构建响应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); + + com.google.gson.JsonArray adminArray = new com.google.gson.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(); From bf26d37e49ebbc6358c7c1a00167726dcd43e457 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Dec 2025 07:27:00 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7=EF=BC=9A=E4=BD=BF=E7=94=A8import?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=B1=BB=E8=80=8C=E9=9D=9E=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E9=99=90=E5=AE=9A=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com> --- .../weixin/cp/api/impl/WxCpAgentServiceImplTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 b72199eb03..cbd947b925 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,5 +1,6 @@ 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; @@ -7,6 +8,7 @@ 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; @@ -91,7 +93,7 @@ public void testList() throws WxErrorException { @Test public void testGetAdminList() throws WxErrorException { final Integer agentId = this.wxCpService.getWxCpConfigStorage().getAgentId(); - me.chanjar.weixin.cp.bean.WxCpTpAdmin adminList = this.wxCpService.getAgentService().getAdminList(agentId); + WxCpTpAdmin adminList = this.wxCpService.getAgentService().getAdminList(agentId); assertThat(adminList).isNotNull(); assertThat(adminList.getErrcode()).isEqualTo(0L); @@ -151,7 +153,7 @@ public void testGetAdminList() throws Exception { admin2.addProperty("open_userid", "woAJ2GCAAAXtWyujaWJHDDGi0mACH72w"); admin2.addProperty("auth_type", 2); - com.google.gson.JsonArray adminArray = new com.google.gson.JsonArray(); + JsonArray adminArray = new JsonArray(); adminArray.add(admin1); adminArray.add(admin2); @@ -169,7 +171,7 @@ public void testGetAdminList() throws Exception { when(wxService.getAgentService()).thenReturn(new WxCpAgentServiceImpl(wxService)); WxCpAgentService wxAgentService = this.wxService.getAgentService(); - me.chanjar.weixin.cp.bean.WxCpTpAdmin adminList = wxAgentService.getAdminList(9); + WxCpTpAdmin adminList = wxAgentService.getAdminList(9); assertEquals(0, adminList.getErrcode().intValue()); assertEquals(2, adminList.getAdmin().size());