24282 2 年之前
父節點
當前提交
145cc84422

+ 12 - 0
hx-admin/pom.xml

@@ -89,6 +89,18 @@
             <artifactId>hx-ehsd</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 179 - 0
hx-admin/src/test/java/DingDingTest.java

@@ -0,0 +1,179 @@
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.aliyun.dingtalkoauth2_1_0.Client;
+import com.aliyun.dingtalkoauth2_1_0.models.GetCorpAccessTokenRequest;
+import com.aliyun.dingtalkoauth2_1_0.models.GetCorpAccessTokenResponseBody;
+import com.aliyun.tea.TeaException;
+import com.aliyun.teaopenapi.models.Config;
+import com.fjhx.admin.BytesailingApplication;
+import com.fjhx.dingding.constant.Constant;
+import com.fjhx.dingding.service.DingService;
+import com.ruoyi.common.annotation.TenantIgnore;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.framework.mybatis.holder.TenantHolder;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = BytesailingApplication.class)
+@Slf4j
+public class DingDingTest {
+
+
+    @Autowired
+    private DingService dingService;
+
+    @TenantIgnore
+    @Test
+    public void test1() {
+
+        TenantHolder.setIgnore(true);
+
+        String a = "{ \"bizData\":[\n" +
+                "        {\n" +
+                "            \"gmt_create\":1683798054000,\n" +
+                "            \"biz_type\":4,\n" +
+                "            \"open_cursor\":0,\n" +
+                "            \"subscribe_id\":\"30319001_0\",\n" +
+                "            \"id\":19960,\n" +
+                "            \"gmt_modified\":1683798054000,\n" +
+                "            \"biz_id\":\"30319001\",\n" +
+                "            \"biz_data\":\"{\\\"auth_user_info\\\":{\\\"userId\\\":\\\"manager2795\\\"},\\\"eventId\\\":\\\"e18758c115604987bb7ba2b4621ab34e\\\",\\\"auth_corp_info\\\":{\\\"corp_type\\\":0,\\\"corpid\\\":\\\"dingc265ea6f59c8a65524f2f5cc6abecb85\\\",\\\"auth_level\\\":0,\\\"corp_city\\\":\\\"吉隆坡\\\",\\\"auth_channel\\\":\\\"4\\\",\\\"industry\\\":\\\"影音视频\\\",\\\"full_corp_name\\\":\\\"宏星钉测\\\",\\\"corp_name\\\":\\\"宏星钉测\\\",\\\"corp_province\\\":\\\"吉隆坡\\\",\\\"is_ecological_corp\\\":false,\\\"invite_url\\\":\\\"https://wx-in-i.dingtalk.com/invite-page/weixin.html?bizSource=____source____&amp;corpId=dingc265ea6f59c8a65524f2f5cc6abecb85&amp;inviteCode=LWeFQxRHOfULrKM\\\",\\\"auth_channel_type\\\":\\\"\\\",\\\"corp_type_v2\\\":0,\\\"invite_code\\\":\\\"\\\",\\\"is_authenticated\\\":false,\\\"license_code\\\":\\\"\\\",\\\"corp_logo_url\\\":\\\"\\\"},\\\"syncAction\\\":\\\"org_suite_auth\\\",\\\"auth_scope\\\":{\\\"errcode\\\":0,\\\"condition_field\\\":[],\\\"auth_user_field\\\":[\\\"jobnumber\\\",\\\"isLeader\\\",\\\"name\\\",\\\"isAdmin\\\",\\\"avatar\\\",\\\"position\\\",\\\"department\\\",\\\"userid\\\",\\\"deviceId\\\",\\\"isHide\\\"],\\\"auth_org_scopes\\\":{\\\"authed_user\\\":[],\\\"authed_dept\\\":[1]},\\\"errmsg\\\":\\\"ok\\\"},\\\"auth_info\\\":{\\\"agent\\\":[{\\\"agentid\\\":2581464649,\\\"agent_name\\\":\\\"byteSailing_test\\\",\\\"logo_url\\\":\\\"https://static-legacy.dingtalk.com/media/lALPDfJ6cdfiyqfNAZDNAZA_400_400.png\\\",\\\"appid\\\":131175,\\\"use_app_role\\\":false,\\\"admin_list\\\":[\\\"manager2795\\\",\\\"231344025724080775\\\",\\\"1244061748905460\\\"]}]},\\\"permanent_code\\\":\\\"MGUG4eSzQWXajGqyCKlVxeZDly-fIhvIsg-Oe_9RiDAuVZselpxX3utY7KBYJLNx\\\",\\\"syncSeq\\\":\\\"8C4DD3DFE04AAE2FB1E6B2AEF7\\\"}\",\n" +
+                "            \"corp_id\":\"dingc265ea6f59c8a65524f2f5cc6abecb85\",\n" +
+                "            \"status\":0\n" +
+                "        },\n" +
+                "        {\n" +
+                "            \"gmt_create\":1683798959000,\n" +
+                "            \"biz_type\":4,\n" +
+                "            \"open_cursor\":0,\n" +
+                "            \"subscribe_id\":\"30319001_0\",\n" +
+                "            \"id\":19966,\n" +
+                "            \"gmt_modified\":1683798959000,\n" +
+                "            \"biz_id\":\"30319001\",\n" +
+                "            \"biz_data\":\"{\\\"auth_user_info\\\":{\\\"userId\\\":\\\"0146512911051043578\\\"},\\\"eventId\\\":\\\"04a9b05f50334f9fa51293892e20ed95\\\",\\\"auth_corp_info\\\":{\\\"corp_type\\\":0,\\\"corpid\\\":\\\"ding53d823e205604918a39a90f97fcb1e09\\\",\\\"auth_level\\\":1,\\\"corp_city\\\":\\\"福州\\\",\\\"auth_channel\\\":\\\"4\\\",\\\"industry\\\":\\\"计算机软件\\\",\\\"full_corp_name\\\":\\\"福建数字云帆科技有限公司\\\",\\\"corp_name\\\":\\\"福建数字云帆科技有限公司\\\",\\\"corp_province\\\":\\\"福建\\\",\\\"is_ecological_corp\\\":false,\\\"invite_url\\\":\\\"https://wx-in-i.dingtalk.com/invite-page/weixin.html?bizSource=____source____&amp;corpId=ding53d823e205604918a39a90f97fcb1e09&amp;inviteCode=NxLoVevdvDloXGi\\\",\\\"auth_channel_type\\\":\\\"\\\",\\\"corp_type_v2\\\":0,\\\"invite_code\\\":\\\"\\\",\\\"is_authenticated\\\":true,\\\"license_code\\\":\\\"\\\",\\\"corp_logo_url\\\":\\\"\\\"},\\\"syncAction\\\":\\\"org_suite_auth\\\",\\\"auth_scope\\\":{\\\"errcode\\\":0,\\\"condition_field\\\":[],\\\"auth_user_field\\\":[\\\"jobnumber\\\",\\\"isLeader\\\",\\\"name\\\",\\\"isAdmin\\\",\\\"avatar\\\",\\\"position\\\",\\\"department\\\",\\\"userid\\\",\\\"deviceId\\\",\\\"isHide\\\"],\\\"auth_org_scopes\\\":{\\\"authed_user\\\":[],\\\"authed_dept\\\":[1]},\\\"errmsg\\\":\\\"ok\\\"},\\\"auth_info\\\":{\\\"agent\\\":[{\\\"agentid\\\":2581336572,\\\"agent_name\\\":\\\"byteSailing_test\\\",\\\"logo_url\\\":\\\"https://static-legacy.dingtalk.com/media/lALPDfJ6cdfiyqfNAZDNAZA_400_400.png\\\",\\\"appid\\\":131175,\\\"use_app_role\\\":false,\\\"admin_list\\\":[\\\"01392913111186905\\\",\\\"0146512911051043578\\\"]}]},\\\"permanent_code\\\":\\\"-icZLdi8NmOL2Rte7Sh3CqdbBcIOGf6eZtJhFNMRBkBugTISTm7zbP21uspckibW\\\",\\\"syncSeq\\\":\\\"844DD3DFE04AAE2FB1E6B2AEA0\\\"}\",\n" +
+                "            \"corp_id\":\"ding53d823e205604918a39a90f97fcb1e09\",\n" +
+                "            \"status\":0\n" +
+                "        },\n" +
+                "        {\n" +
+                "            \"gmt_create\":1683799205000,\n" +
+                "            \"biz_type\":4,\n" +
+                "            \"open_cursor\":0,\n" +
+                "            \"subscribe_id\":\"30319001_0\",\n" +
+                "            \"id\":19970,\n" +
+                "            \"gmt_modified\":1683799205000,\n" +
+                "            \"biz_id\":\"30319001\",\n" +
+                "            \"biz_data\":\"{\\\"auth_user_info\\\":{\\\"userId\\\":\\\"manager6338\\\"},\\\"eventId\\\":\\\"025ca5fb30c9472c8a7ea8211adf78ef\\\",\\\"auth_corp_info\\\":{\\\"corp_type\\\":0,\\\"corpid\\\":\\\"dingb543e6dc430497bbee0f45d8e4f7c288\\\",\\\"auth_level\\\":0,\\\"auth_channel\\\":\\\"4\\\",\\\"industry\\\":\\\"\\\",\\\"full_corp_name\\\":\\\"hffff 测试\\\",\\\"corp_name\\\":\\\"hffff 测试\\\",\\\"is_ecological_corp\\\":false,\\\"invite_url\\\":\\\"https://wx-in-i.dingtalk.com/invite-page/weixin.html?bizSource=____source____&amp;corpId=dingb543e6dc430497bbee0f45d8e4f7c288&amp;inviteCode=DVwNu9mv9AowRNZ\\\",\\\"auth_channel_type\\\":\\\"\\\",\\\"corp_type_v2\\\":0,\\\"invite_code\\\":\\\"\\\",\\\"is_authenticated\\\":false,\\\"license_code\\\":\\\"\\\",\\\"corp_logo_url\\\":\\\"\\\"},\\\"syncAction\\\":\\\"org_suite_auth\\\",\\\"auth_scope\\\":{\\\"errcode\\\":0,\\\"condition_field\\\":[],\\\"auth_user_field\\\":[\\\"jobnumber\\\",\\\"isLeader\\\",\\\"name\\\",\\\"isAdmin\\\",\\\"avatar\\\",\\\"position\\\",\\\"department\\\",\\\"userid\\\",\\\"deviceId\\\",\\\"isHide\\\"],\\\"auth_org_scopes\\\":{\\\"authed_user\\\":[],\\\"authed_dept\\\":[1]},\\\"errmsg\\\":\\\"ok\\\"},\\\"auth_info\\\":{\\\"agent\\\":[{\\\"agentid\\\":2581242807,\\\"agent_name\\\":\\\"byteSailing_test\\\",\\\"logo_url\\\":\\\"https://static-legacy.dingtalk.com/media/lALPDfJ6cdfiyqfNAZDNAZA_400_400.png\\\",\\\"appid\\\":131175,\\\"use_app_role\\\":false,\\\"admin_list\\\":[\\\"manager6338\\\"]}]},\\\"permanent_code\\\":\\\"oVS5wid1S_B5JPXGZtiNH_gu0N0Diev6SLWHSaEpvHvClNEua_eIINRMOw2JIUC4\\\",\\\"syncSeq\\\":\\\"874DD3DFE04AA32FA1E6B2AEA5\\\"}\",\n" +
+                "            \"corp_id\":\"dingb543e6dc430497bbee0f45d8e4f7c288\",\n" +
+                "            \"status\":0\n" +
+                "        },\n" +
+                "        {\n" +
+                "            \"gmt_create\":1683810014000,\n" +
+                "            \"biz_type\":4,\n" +
+                "            \"open_cursor\":0,\n" +
+                "            \"subscribe_id\":\"30319001_0\",\n" +
+                "            \"id\":19981,\n" +
+                "            \"gmt_modified\":1683810014000,\n" +
+                "            \"biz_id\":\"30319001\",\n" +
+                "            \"biz_data\":\"{\\\"auth_user_info\\\":{\\\"userId\\\":\\\"manager8063\\\"},\\\"eventId\\\":\\\"9cee61dc4e3e4226a424b0f07c593a0e\\\",\\\"auth_corp_info\\\":{\\\"corp_type\\\":0,\\\"corpid\\\":\\\"ding379d86d92b0c876eee0f45d8e4f7c288\\\",\\\"auth_level\\\":0,\\\"auth_channel\\\":\\\"4\\\",\\\"industry\\\":\\\"\\\",\\\"full_corp_name\\\":\\\"中星华宸\\\",\\\"corp_name\\\":\\\"中星华宸\\\",\\\"is_ecological_corp\\\":false,\\\"invite_url\\\":\\\"https://wx-in-i.dingtalk.com/invite-page/weixin.html?bizSource=____source____&amp;corpId=ding379d86d92b0c876eee0f45d8e4f7c288&amp;inviteCode=r1zJSofuiKs5eDA\\\",\\\"auth_channel_type\\\":\\\"\\\",\\\"corp_type_v2\\\":0,\\\"invite_code\\\":\\\"\\\",\\\"is_authenticated\\\":false,\\\"license_code\\\":\\\"\\\",\\\"corp_logo_url\\\":\\\"\\\"},\\\"syncAction\\\":\\\"org_suite_auth\\\",\\\"auth_scope\\\":{\\\"errcode\\\":0,\\\"condition_field\\\":[],\\\"auth_user_field\\\":[\\\"jobnumber\\\",\\\"isLeader\\\",\\\"name\\\",\\\"isAdmin\\\",\\\"avatar\\\",\\\"position\\\",\\\"department\\\",\\\"userid\\\",\\\"deviceId\\\",\\\"isHide\\\"],\\\"auth_org_scopes\\\":{\\\"authed_user\\\":[],\\\"authed_dept\\\":[1]},\\\"errmsg\\\":\\\"ok\\\"},\\\"auth_info\\\":{\\\"agent\\\":[{\\\"agentid\\\":2581402962,\\\"agent_name\\\":\\\"byteSailing_test\\\",\\\"logo_url\\\":\\\"https://static-legacy.dingtalk.com/media/lALPDfJ6cdfiyqfNAZDNAZA_400_400.png\\\",\\\"appid\\\":131175,\\\"use_app_role\\\":false,\\\"admin_list\\\":[\\\"manager8063\\\"]}]},\\\"permanent_code\\\":\\\"jZa3L6vaNTyEhmg5ZmAT2Ym9-NUrUjTIp8wSNek2SO8O3bZPGzn9pfDUE0N5E82k\\\",\\\"syncSeq\\\":\\\"804DD3DFE04AAF2F01E6B2AE67\\\"}\",\n" +
+                "            \"corp_id\":\"ding379d86d92b0c876eee0f45d8e4f7c288\",\n" +
+                "            \"status\":0\n" +
+                "        },\n" +
+                "        {\n" +
+                "            \"gmt_create\":1683854166000,\n" +
+                "            \"biz_type\":4,\n" +
+                "            \"open_cursor\":0,\n" +
+                "            \"subscribe_id\":\"30319001_0\",\n" +
+                "            \"id\":19993,\n" +
+                "            \"gmt_modified\":1683854166000,\n" +
+                "            \"biz_id\":\"30319001\",\n" +
+                "            \"biz_data\":\"{\\\"auth_user_info\\\":{\\\"userId\\\":\\\"manager7560\\\"},\\\"eventId\\\":\\\"8f508ef39eab4a37b643c0195e8ec862\\\",\\\"auth_corp_info\\\":{\\\"corp_type\\\":0,\\\"corpid\\\":\\\"ding3f327504d104ac1cf2c783f7214b6d69\\\",\\\"auth_level\\\":0,\\\"corp_city\\\":\\\"福州\\\",\\\"auth_channel\\\":\\\"4\\\",\\\"industry\\\":\\\"计算机软件\\\",\\\"full_corp_name\\\":\\\"hf测试\\\",\\\"corp_name\\\":\\\"hf测试\\\",\\\"corp_province\\\":\\\"福建\\\",\\\"is_ecological_corp\\\":false,\\\"invite_url\\\":\\\"https://wx-in-i.dingtalk.com/invite-page/weixin.html?bizSource=____source____&amp;corpId=ding3f327504d104ac1cf2c783f7214b6d69&amp;inviteCode=i8yWYDEytZJIkIa\\\",\\\"auth_channel_type\\\":\\\"\\\",\\\"corp_type_v2\\\":0,\\\"invite_code\\\":\\\"\\\",\\\"is_authenticated\\\":false,\\\"license_code\\\":\\\"\\\",\\\"corp_logo_url\\\":\\\"\\\"},\\\"syncAction\\\":\\\"org_suite_auth\\\",\\\"auth_scope\\\":{\\\"errcode\\\":0,\\\"condition_field\\\":[],\\\"auth_user_field\\\":[\\\"jobnumber\\\",\\\"isLeader\\\",\\\"name\\\",\\\"isAdmin\\\",\\\"avatar\\\",\\\"position\\\",\\\"department\\\",\\\"userid\\\",\\\"deviceId\\\",\\\"isHide\\\"],\\\"auth_org_scopes\\\":{\\\"authed_user\\\":[],\\\"authed_dept\\\":[1]},\\\"errmsg\\\":\\\"ok\\\"},\\\"auth_info\\\":{\\\"agent\\\":[{\\\"agentid\\\":2581273014,\\\"agent_name\\\":\\\"byteSailing_test\\\",\\\"logo_url\\\":\\\"https://static-legacy.dingtalk.com/media/lALPDfJ6cdfiyqfNAZDNAZA_400_400.png\\\",\\\"appid\\\":131175,\\\"use_app_role\\\":false,\\\"admin_list\\\":[\\\"manager7560\\\"]}]},\\\"permanent_code\\\":\\\"caY2fuNclujXwRXlDOuctE-4HlOY6hWfgBTnMDbOaCPGQ-yzWQBxE6-axKq9XSJy\\\",\\\"syncSeq\\\":\\\"844DD3DFE04AAD2F91E6B2AEE5\\\"}\",\n" +
+                "            \"corp_id\":\"ding3f327504d104ac1cf2c783f7214b6d69\",\n" +
+                "            \"status\":0\n" +
+                "        },\n" +
+                "        {\n" +
+                "            \"gmt_create\":1683854404000,\n" +
+                "            \"biz_type\":2,\n" +
+                "            \"open_cursor\":0,\n" +
+                "            \"subscribe_id\":\"30319001_0\",\n" +
+                "            \"id\":19994,\n" +
+                "            \"gmt_modified\":1683854404000,\n" +
+                "            \"biz_id\":\"30319001\",\n" +
+                "            \"biz_data\":\"{\\\"eventId\\\":\\\"e50ed7cdf209448fa567e523bfc52b83\\\",\\\"syncAction\\\":\\\"suite_ticket\\\",\\\"suiteTicket\\\":\\\"2SwvImnFmDGqrCpEdmHeOjwBpBBj0o30nJmsqzMGUD3HJ2zMqckkTwlzM40GycbsjBKE0h2wUQHb3AQMrRtzCl\\\",\\\"syncSeq\\\":\\\"2AEA5DA284BB85DEE8CA8D33A9\\\"}\",\n" +
+                "            \"corp_id\":\"ding53d823e205604918a39a90f97fcb1e09\",\n" +
+                "            \"status\":0\n" +
+                "        }\n" +
+                "    ]}";
+
+
+        dingService.pushHigh(JSON.parseObject(a));
+
+        System.out.println();
+
+    }
+
+    public static void main(String[] args) {
+        String a = "{ \"bizData\":[        {\n" +
+                "            \"gmt_create\":1683854404000,\n" +
+                "            \"biz_type\":2,\n" +
+                "            \"open_cursor\":0,\n" +
+                "            \"subscribe_id\":\"30319001_0\",\n" +
+                "            \"id\":19994,\n" +
+                "            \"gmt_modified\":1683854404000,\n" +
+                "            \"biz_id\":\"30319001\",\n" +
+                "            \"biz_data\":\"{\\\"eventId\\\":\\\"e50ed7cdf209448fa567e523bfc52b83\\\",\\\"syncAction\\\":\\\"suite_ticket\\\",\\\"suiteTicket\\\":\\\"2SwvImnFmDGqrCpEdmHeOjwBpBBj0o30nJmsqzMGUD3HJ2zMqckkTwlzM40GycbsjBKE0h2wUQHb3AQMrRtzCl\\\",\\\"syncSeq\\\":\\\"2AEA5DA284BB85DEE8CA8D33A9\\\"}\",\n" +
+                "            \"corp_id\":\"ding53d823e205604918a39a90f97fcb1e09\",\n" +
+                "            \"status\":0\n" +
+                "        }]}";
+        System.out.println(JSON.parse(a));
+    }
+
+
+    private static String test1(String corpId) {
+        GetCorpAccessTokenRequest getCorpAccessTokenRequest = new GetCorpAccessTokenRequest()
+                .setSuiteKey(Constant.SUITE_KEY)
+                .setSuiteSecret(Constant.SUITE_SECRET)
+                .setAuthCorpId(corpId)
+                .setSuiteTicket("2SwvImnFmDGqrCpEdmHeOjwBpBBj0o30nJmsqzMGUD3HJ2zMqckkTwlzM40GycbsjBKE0h2wUQHb3AQMrRtzCl");
+
+        try {
+            Client client = getClient2();
+            GetCorpAccessTokenResponseBody body = client.getCorpAccessToken(getCorpAccessTokenRequest).getBody();
+            return body.getAccessToken();
+        } catch (Exception e) {
+
+            TeaException teaException;
+
+            if (e instanceof TeaException) {
+                teaException = (TeaException) e;
+            } else {
+                teaException = new TeaException(e.getMessage(), e);
+            }
+
+            String errCode = teaException.getCode();
+            String errMsg = teaException.getMessage();
+
+            if (StrUtil.isAllNotBlank(errCode, errMsg)) {
+                log.error("钉钉授权认证失败: code:{},message:{}", errCode, errMsg);
+                throw new ServiceException(errMsg);
+            } else {
+                log.error("钉钉授权认证失败", teaException);
+                throw new ServiceException("发生未知异常,钉钉授权认证失败");
+            }
+
+        }
+    }
+
+
+    private static com.aliyun.dingtalkoauth2_1_0.Client getClient2() throws Exception {
+        Config config = new Config();
+        config.protocol = "https";
+        config.regionId = "central";
+        return new com.aliyun.dingtalkoauth2_1_0.Client(config);
+    }
+
+}

+ 2 - 34
hx-dingding/src/main/java/com/fjhx/dingding/controller/DingController.java

@@ -2,10 +2,6 @@ package com.fjhx.dingding.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.aliyun.dingtalkoauth2_1_0.Client;
-import com.aliyun.dingtalkoauth2_1_0.models.GetCorpAccessTokenRequest;
-import com.aliyun.dingtalkoauth2_1_0.models.GetCorpAccessTokenResponseBody;
-import com.aliyun.teaopenapi.models.Config;
 import com.dingtalk.api.response.OapiV2UserGetuserinfoResponse;
 import com.dingtalk.oapi.lib.aes.DingTalkEncryptor;
 import com.fjhx.dingding.constant.Constant;
@@ -14,7 +10,6 @@ import com.fjhx.dingding.service.DingService;
 import com.fjhx.dingding.utils.DingUtil;
 import com.ruoyi.common.annotation.NonInterception;
 import com.ruoyi.common.annotation.TenantIgnore;
-import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -25,29 +20,6 @@ import java.util.LinkedHashMap;
 @RestController
 @RequestMapping("/open")
 public class DingController {
-    @SneakyThrows
-    public static void main(String[] args) {
-
-        String corpId = "ding53d823e205604918a39a90f97fcb1e09";
-
-        GetCorpAccessTokenRequest getCorpAccessTokenRequest = new GetCorpAccessTokenRequest()
-                .setSuiteKey(Constant.SUITE_KEY)
-                .setSuiteSecret(Constant.SUITE_SECRET)
-                .setAuthCorpId(corpId)
-                .setSuiteTicket("UzdBkwbfymMvKF514ISMaftifCn9Cxb1K2l9pRgUKiJf7k7IRPxEuWvLAXxxQmAWzLxwcxXiGkYppry0NKQiWQ");
-
-        Client client = getClient2();
-        GetCorpAccessTokenResponseBody body = client.getCorpAccessToken(getCorpAccessTokenRequest).getBody();
-        String accessToken = body.getAccessToken();
-        System.out.println(accessToken);
-    }
-
-    private static com.aliyun.dingtalkoauth2_1_0.Client getClient2() throws Exception {
-        Config config = new Config();
-        config.protocol = "https";
-        config.regionId = "central";
-        return new com.aliyun.dingtalkoauth2_1_0.Client(config);
-    }
 
     @Autowired
     private DingService dingService;
@@ -110,7 +82,7 @@ public class DingController {
                 default:
                     // 其他类型事件处理
                     log.info("其他回调:" + plainText);
-                    dingService.saveCallback(callBackContent);
+                    // dingService.saveCallback(callBackContent);
             }
 
             // 返回success的加密信息表示回调处理成功
@@ -125,14 +97,10 @@ public class DingController {
 
     @PostMapping(value = "/dingApi/getUserToken")
     public LinkedHashMap<String, Object> getUserToken(@RequestBody GetUserTokenDto dto) {
-        String corpAccessToken = DingUtil.getCorpAccessToken();
-        OapiV2UserGetuserinfoResponse.UserGetByCodeResponse userInfo = DingUtil.getUserInfo(corpAccessToken, dto.getCode());
-
+        OapiV2UserGetuserinfoResponse.UserGetByCodeResponse userInfo = DingUtil.getUserInfo(dto.getCorpId(), dto.getCode());
         LinkedHashMap<String, Object> map = new LinkedHashMap<>();
-        map.put("tokenInfo", corpAccessToken);
         map.put("userInfo", userInfo);
         return map;
     }
 
-
 }

+ 0 - 2
hx-dingding/src/main/java/com/fjhx/dingding/service/DingService.java

@@ -4,8 +4,6 @@ import com.alibaba.fastjson.JSONObject;
 
 public interface DingService {
 
-    void saveCallback(JSONObject callBackContent);
-
     void pushHigh(JSONObject callBackContent);
 
 }

+ 11 - 39
hx-dingding/src/main/java/com/fjhx/dingding/service/impl/DingServiceImpl.java

@@ -10,7 +10,6 @@ import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
 import com.fjhx.common.constant.SourceConstant;
-import com.fjhx.dingding.entity.suite.po.SuiteTicketInfo;
 import com.fjhx.dingding.service.DingService;
 import com.fjhx.dingding.service.suite.SuiteTicketInfoService;
 import com.fjhx.dingding.utils.DingUtil;
@@ -23,6 +22,7 @@ import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.system.service.ISysUserService;
+import com.ruoyi.system.utils.ConfigUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -61,36 +61,28 @@ public class DingServiceImpl implements DingService {
      * https://open.dingtalk.com/document/isvapp/data-formats
      */
     @Override
-    public void saveCallback(JSONObject callBackContent) {
-
-        JSONObject bizData = callBackContent.getJSONObject("bizData");
-
-    }
-
-    @Override
     public void pushHigh(JSONObject callBackContent) {
         JSONArray bizData = callBackContent.getJSONArray("bizData");
 
         for (JSONObject jsonObject : bizData.toJavaList(JSONObject.class)) {
-
             switch (jsonObject.getInteger("biz_type")) {
-
                 case 2:
                     saveSuiteTicketInfo(jsonObject);
                     break;
-
                 case 4:
                     corpAuthorization(jsonObject);
                     break;
-
             }
-
         }
 
     }
 
-    public static void main(String[] args) {
-        System.out.println("{\"auth_user_info\":{\"userId\":\"manager7560\"},\"eventId\":\"b542e727bad741d6b16de878676c363e\",\"auth_corp_info\":{\"corp_type\":0,\"corpid\":\"ding3f327504d104ac1cf2c783f7214b6d69\",\"auth_level\":0,\"corp_city\":\"福州\",\"auth_channel\":\"4\",\"industry\":\"计算机软件\",\"full_corp_name\":\"hf测试\",\"corp_name\":\"hf测试\",\"corp_province\":\"福建\",\"is_ecological_corp\":false,\"invite_url\":\"https://wx-in-i.dingtalk.com/invite-page/weixin.html?bizSource=____source____&corpId=ding3f327504d104ac1cf2c783f7214b6d69&inviteCode=i8yWYDEytZJIkIa\",\"auth_channel_type\":\"\",\"corp_type_v2\":0,\"invite_code\":\"\",\"is_authenticated\":false,\"license_code\":\"\",\"corp_logo_url\":\"\"},\"syncAction\":\"org_suite_auth\",\"auth_scope\":{\"errcode\":0,\"condition_field\":[],\"auth_user_field\":[\"jobnumber\",\"isLeader\",\"name\",\"isAdmin\",\"avatar\",\"position\",\"department\",\"userid\",\"deviceId\",\"isHide\"],\"auth_org_scopes\":{\"authed_user\":[],\"authed_dept\":[1]},\"errmsg\":\"ok\"},\"auth_info\":{\"agent\":[{\"agentid\":2581273014,\"agent_name\":\"byteSailing_test\",\"logo_url\":\"https://static-legacy.dingtalk.com/media/lALPDfJ6cdfiyqfNAZDNAZA_400_400.png\",\"appid\":131175,\"use_app_role\":false,\"admin_list\":[\"manager7560\"]}]},\"permanent_code\":\"caY2fuNclujXwRXlDOuctE-4HlOY6hWfgBTnMDbOaCPGQ-yzWQBxE6-axKq9XSJy\",\"syncSeq\":\"8F4DD3DFE04AA32FF1E6B2AE55\"}");
+    /**
+     * 保存 suite_ticket
+     */
+    private void saveSuiteTicketInfo(JSONObject bizData) {
+        String suiteTicket = bizData.getJSONObject("biz_data").getString("suiteTicket");
+        ConfigUtil.set("dd_suite_ticket", suiteTicket);
     }
 
     /**
@@ -127,26 +119,6 @@ public class DingServiceImpl implements DingService {
     }
 
     /**
-     * 保存 suite_ticket
-     */
-    private void saveSuiteTicketInfo(JSONObject bizData) {
-        String corpId = bizData.getString("corp_id");
-        String suiteTicket = bizData.getJSONObject("biz_data").getString("suiteTicket");
-        boolean update = suiteTicketInfoService.update(q -> q
-                .eq(SuiteTicketInfo::getCorpId, corpId)
-                .set(SuiteTicketInfo::getSuiteTicket, suiteTicket)
-                .set(SuiteTicketInfo::getUpdateTime, new Date()));
-
-        if (!update) {
-            SuiteTicketInfo suiteTicketInfo = new SuiteTicketInfo();
-            suiteTicketInfo.setCorpId(corpId);
-            suiteTicketInfo.setSuiteTicket(suiteTicket);
-            suiteTicketInfoService.save(suiteTicketInfo);
-        }
-
-    }
-
-    /**
      * 企业授权
      */
     private void orgSuiteAuth(JSONObject bizData) {
@@ -193,7 +165,7 @@ public class DingServiceImpl implements DingService {
         tenantInfo.setCorpid(corpid);
 
         // 创建部门
-        ArrayList<SysDept> deptList = new ArrayList<>();
+        List<SysDept> deptList = new ArrayList<>();
         addDeptList(corpid, deptList, tenantId, 1L, 0L);
 
         // 创建用户
@@ -204,10 +176,9 @@ public class DingServiceImpl implements DingService {
         sysUser.setNickName(corpName + "管理员");
         sysUser.setPassword(SecurityUtils.encryptPassword(RandomUtil.randomString(6)));
         sysUser.setStatus("0");
-        sysUser.setCreateBy(SecurityUtils.getUsername());
         sysUser.setCreateTime(new Date());
+        sysUser.setUpdateTime(new Date());
         sysUser.setDdUserId(bizData.getJSONObject("auth_user_info").getString("userId"));
-        sysUserService.save(sysUser);
 
         log.info("钉钉回调创建租户,tenantInfo:{}", JSON.toJSONString(tenantInfo));
         log.info("钉钉回调创建部门,deptList:{}", JSON.toJSONString(deptList));
@@ -215,11 +186,12 @@ public class DingServiceImpl implements DingService {
 
         TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
         try {
-
             // 保存租户
             tenantInfoService.save(tenantInfo);
             // 保存部门
             sysDeptService.saveBatch(deptList);
+            // 保存用户
+            sysUserService.save(sysUser);
             // 提交事务
             platformTransactionManager.commit(transactionStatus);
 

+ 11 - 25
hx-dingding/src/main/java/com/fjhx/dingding/utils/DingUtil.java

@@ -15,10 +15,9 @@ import com.dingtalk.api.request.OapiV2UserGetuserinfoRequest;
 import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
 import com.dingtalk.api.response.OapiV2UserGetuserinfoResponse;
 import com.fjhx.dingding.constant.Constant;
-import com.fjhx.dingding.entity.suite.po.SuiteTicketInfo;
-import com.fjhx.dingding.service.suite.SuiteTicketInfoService;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.system.utils.ConfigUtil;
 import lombok.extern.slf4j.Slf4j;
 
 import java.util.List;
@@ -39,34 +38,31 @@ import java.util.concurrent.TimeUnit;
 public class DingUtil {
 
     private static final RedisCache redisCache = SpringUtil.getBean(RedisCache.class);
-
-    private static final SuiteTicketInfoService suiteTicketInfoService = SpringUtil.getBean(SuiteTicketInfoService.class);
-
     private static final String corpAccessTokenRedisKey = "corpAccessToken:";
 
     /**
      * 获取第三方应用授权企业的accessToken
      * https://open.dingtalk.com/document/isvapp/obtain-the-access_token-of-the-authorized-enterprise
      */
-    public static String getCorpAccessToken() {
-        String corpId = "ding53d823e205604918a39a90f97fcb1e09";
+    public static String getCorpAccessToken(String corpId) {
+
         String redisKey = corpAccessTokenRedisKey + corpId;
         String corpAccessToken = redisCache.getCacheObject(redisKey);
         if (StrUtil.isNotBlank(corpAccessToken)) {
             return corpAccessToken;
         }
 
-        SuiteTicketInfo suiteTicketInfo = suiteTicketInfoService.getOne(q -> q.eq(SuiteTicketInfo::getCorpId, corpId));
+        String suiteTicket = ConfigUtil.get("dd_suite_ticket");
 
-        if (suiteTicketInfo == null) {
-            throw new ServiceException("没有找到对应的corp_id");
+        if (StrUtil.isBlank(suiteTicket)) {
+            throw new ServiceException("没有找到suite_ticket");
         }
 
         GetCorpAccessTokenRequest getCorpAccessTokenRequest = new GetCorpAccessTokenRequest()
                 .setSuiteKey(Constant.SUITE_KEY)
                 .setSuiteSecret(Constant.SUITE_SECRET)
                 .setAuthCorpId(corpId)
-                .setSuiteTicket(suiteTicketInfo.getSuiteTicket());
+                .setSuiteTicket(suiteTicket);
 
         try {
             Client client = getClient2();
@@ -101,11 +97,12 @@ public class DingUtil {
      * 通过免登码获取用户信息
      * https://open.dingtalk.com/document/isvapp/obtain-the-userid-of-a-user-by-using-the-log-free
      */
-    public static OapiV2UserGetuserinfoResponse.UserGetByCodeResponse getUserInfo(String corpAccessToken, String code) {
+    public static OapiV2UserGetuserinfoResponse.UserGetByCodeResponse getUserInfo(String corpId, String code) {
         try {
             DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo");
             OapiV2UserGetuserinfoRequest req = new OapiV2UserGetuserinfoRequest();
             req.setCode(code);
+            String corpAccessToken = getCorpAccessToken(corpId);
             OapiV2UserGetuserinfoResponse rsp = client.execute(req, corpAccessToken);
             return rsp.getResult();
         } catch (Exception e) {
@@ -120,7 +117,8 @@ public class DingUtil {
             OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
             req.setDeptId(deptId);
             req.setLanguage("zh_CN");
-            OapiV2DepartmentListsubResponse rsp = client.execute(req, getCorpAccessToken());
+            String corpAccessToken = getCorpAccessToken(corpId);
+            OapiV2DepartmentListsubResponse rsp = client.execute(req, corpAccessToken);
             return rsp.getResult();
         } catch (Exception e) {
             log.error("获取用户部门失败", e);
@@ -128,18 +126,6 @@ public class DingUtil {
         }
     }
 
-    // public static void main(String[] args) {
-    //     List<OapiV2DepartmentListsubResponse.DeptBaseResponse> deptList = getDeptList("", 1L);
-    //     System.out.println(deptList);
-    // }
-
-    private static com.aliyun.dingtalkcontact_1_0.Client getClient1() throws Exception {
-        Config config = new Config();
-        config.protocol = "https";
-        config.regionId = "central";
-        return new com.aliyun.dingtalkcontact_1_0.Client(config);
-    }
-
     private static com.aliyun.dingtalkoauth2_1_0.Client getClient2() throws Exception {
         Config config = new Config();
         config.protocol = "https";