diff --git a/cloud-common-dingding/pom.xml b/cloud-common-dingding/pom.xml index cb6a362..1bc5179 100644 --- a/cloud-common-dingding/pom.xml +++ b/cloud-common-dingding/pom.xml @@ -22,7 +22,7 @@ com.aliyun alibaba-dingtalk-service-sdk - 1.0.1 + 2.0.0 diff --git a/cloud-common-dingding/src/main/java/com/cm/common/dingding/controller/api/DemoController.java b/cloud-common-dingding/src/main/java/com/cm/common/dingding/controller/api/DemoController.java index 7adb48b..d08c105 100644 --- a/cloud-common-dingding/src/main/java/com/cm/common/dingding/controller/api/DemoController.java +++ b/cloud-common-dingding/src/main/java/com/cm/common/dingding/controller/api/DemoController.java @@ -1,8 +1,11 @@ package com.cm.common.dingding.controller.api; +import com.alibaba.fastjson.JSONObject; import com.cm.common.constants.ISystemConstant; +import com.cm.common.dingding.service.IDingDingAppDepartmentService; import com.cm.common.dingding.service.IDingDingMessageService; import com.cm.common.result.SuccessResult; +import com.taobao.api.ApiException; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -27,10 +30,17 @@ public class DemoController { @Autowired private IDingDingMessageService dingDingMessageService; + @Autowired + private IDingDingAppDepartmentService dingDingAppDepartmentService; @GetMapping("sendmessage/{phone}") - private SuccessResult sendMessage(@PathVariable("phone") String phone) { + public SuccessResult sendMessage(@PathVariable("phone") String phone) { return dingDingMessageService.send(phone, "测试"); } + @GetMapping("list") + public JSONObject list() throws ApiException { + return dingDingAppDepartmentService.list(); + } + } diff --git a/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppDepartmentService.java b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppDepartmentService.java new file mode 100644 index 0000000..c7700a2 --- /dev/null +++ b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppDepartmentService.java @@ -0,0 +1,17 @@ +package com.cm.common.dingding.service; + +import com.alibaba.fastjson.JSONObject; +import com.taobao.api.ApiException; + +/** + * @ClassName: IDingDingAppDepartmentService + * @Description: 钉钉部门 + * @Author: wanggeng + * @Date: 2021/7/21 9:42 上午 + * @Version: 1.0 + */ +public interface IDingDingAppDepartmentService { + + JSONObject list() throws ApiException; + +} diff --git a/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppDepartmentServiceImpl.java b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppDepartmentServiceImpl.java new file mode 100644 index 0000000..4247f81 --- /dev/null +++ b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppDepartmentServiceImpl.java @@ -0,0 +1,34 @@ +package com.cm.common.dingding.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.cm.common.base.AbstractService; +import com.cm.common.dingding.manager.app.DingDingAppManager; +import com.cm.common.dingding.service.IDingDingAppDepartmentService; +import com.dingtalk.api.DefaultDingTalkClient; +import com.dingtalk.api.DingTalkClient; +import com.dingtalk.api.request.OapiV2DepartmentListsubRequest; +import com.dingtalk.api.response.OapiV2DepartmentListsubResponse; +import com.taobao.api.ApiException; +import org.springframework.stereotype.Service; + +/** + * @ClassName: DingDingAppDepartmentServiceImpl + * @Description: 钉钉部门管理,需要开放钉钉应用:权限管理 -> 通讯录管理 -> 通讯录部门信息读权限 + * @Author: wanggeng + * @Date: 2021/7/21 9:42 上午 + * @Version: 1.0 + */ +@Service +public class DingDingAppDepartmentServiceImpl extends AbstractService implements IDingDingAppDepartmentService { + @Override + public JSONObject list() throws ApiException { + DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub"); + OapiV2DepartmentListsubRequest oapiV2DepartmentListsubRequest = new OapiV2DepartmentListsubRequest(); + oapiV2DepartmentListsubRequest.setDeptId(1L); + oapiV2DepartmentListsubRequest.setLanguage("zh_CN"); + OapiV2DepartmentListsubResponse rsp = client.execute(oapiV2DepartmentListsubRequest, DingDingAppManager.getInstance().getAccessToken()); + System.out.println(rsp.getBody()); + return JSON.parseObject(rsp.getBody()); + } +}