diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java index c86816b7f..b8e43cbdc 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpDepartmentService.java @@ -28,6 +28,18 @@ public interface WxCpDepartmentService { */ Long create(WxCpDepart depart) throws WxErrorException; + /** + *
+   * 部门管理接口 - 获取单个部门详情.
+   * 详情请见: https://developer.work.weixin.qq.com/document/path/95351
+   * 
+ * + * @param id 部门id + * @return 部门信息 + * @throws WxErrorException 异常 + */ + WxCpDepart get(Long id) throws WxErrorException; + /** *
    * 部门管理接口 - 获取部门列表.
@@ -40,6 +52,18 @@ public interface WxCpDepartmentService {
    */
   List list(Long id) throws WxErrorException;
 
+  /**
+   * 
+   * 部门管理接口 - 获取子部门ID列表.
+   * 详情请见: https://developer.work.weixin.qq.com/document/path/95350
+   * 
+ * + * @param id 部门id。获取指定部门及其下的子部门(以及子部门的子部门等等,递归)。 如果不填,默认获取全量组织架构 + * @return 子部门ID列表 + * @throws WxErrorException 异常 + */ + List simpleList(Long id) throws WxErrorException; + /** *
    * 部门管理接口 - 更新部门.
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
index 3a5ef8798..b6d9cf29b 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
@@ -35,6 +35,18 @@ public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
     return GsonHelper.getAsLong(tmpJsonObject.get("id"));
   }
 
+  @Override
+  public WxCpDepart get(Long id) throws WxErrorException {
+    String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_GET), id);
+    String responseContent = this.mainService.get(url, null);
+    JsonObject tmpJsonObject = GsonParser.parse(responseContent);
+    return WxCpGsonBuilder.create()
+      .fromJson(tmpJsonObject.get("department"),
+        new TypeToken() {
+        }.getType()
+      );
+  }
+
   @Override
   public void update(WxCpDepart group) throws WxErrorException {
     String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_UPDATE);
@@ -62,4 +74,20 @@ public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
         }.getType()
       );
   }
+
+  @Override
+  public List simpleList(Long id) throws WxErrorException {
+    String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_SIMPLE_LIST);
+    if (id != null) {
+      url += "?id=" + id;
+    }
+
+    String responseContent = this.mainService.get(url, null);
+    JsonObject tmpJsonObject = GsonParser.parse(responseContent);
+    return WxCpGsonBuilder.create()
+      .fromJson(tmpJsonObject.get("department_id"),
+        new TypeToken>() {
+        }.getType()
+      );
+  }
 }
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 1b803cfdd..2155b4c61 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
@@ -71,8 +71,10 @@ public interface WxCpApiPathConsts {
   interface Department {
     String DEPARTMENT_CREATE = "/cgi-bin/department/create";
     String DEPARTMENT_UPDATE = "/cgi-bin/department/update";
+    String DEPARTMENT_GET = "/cgi-bin/department/get?id=%d";
     String DEPARTMENT_DELETE = "/cgi-bin/department/delete?id=%d";
     String DEPARTMENT_LIST = "/cgi-bin/department/list";
+    String DEPARTMENT_SIMPLE_LIST = "/cgi-bin/department/simplelist";
   }
 
   interface Media {
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java
index 57957d3fb..7417f8055 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java
@@ -1,13 +1,15 @@
 package me.chanjar.weixin.cp.api.impl;
 
-import java.util.List;
-
-import org.testng.annotations.*;
-
 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.WxCpService;
 import me.chanjar.weixin.cp.bean.WxCpDepart;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+import java.util.List;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -36,11 +38,11 @@ public class WxCpDepartmentServiceImplTest {
   }
 
   @DataProvider
-  public Object[][] departIds(){
+  public Object[][] departIds() {
     return new Object[][]{
       {null},
-      {1},
-      {5}
+      {12L},
+      {5L}
     };
   }
 
@@ -70,4 +72,22 @@ public class WxCpDepartmentServiceImplTest {
     this.wxCpService.getDepartmentService().delete(this.depart.getId());
   }
 
+  @Test(dataProvider = "departIds")
+  public void testSimpleList(Long id) throws WxErrorException {
+    System.out.println("=================获取子部门ID列表");
+    List departList = this.wxCpService.getDepartmentService().simpleList(id);
+    assertThat(departList).isNotEmpty();
+    departList.forEach(System.out::println);
+  }
+
+  @Test(dataProvider = "departIds")
+  public void testGet(Long id) throws WxErrorException {
+    if (id == null) {
+      return;
+    }
+
+    WxCpDepart depart = this.wxCpService.getDepartmentService().get(id);
+    assertThat(depart).isNotNull();
+    System.out.println(depart);
+  }
 }