DingDingTest.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import cn.hutool.core.util.StrUtil;
  2. import com.alibaba.fastjson.JSON;
  3. import com.aliyun.dingtalkoauth2_1_0.Client;
  4. import com.aliyun.dingtalkoauth2_1_0.models.GetCorpAccessTokenRequest;
  5. import com.aliyun.dingtalkoauth2_1_0.models.GetCorpAccessTokenResponseBody;
  6. import com.aliyun.tea.TeaException;
  7. import com.aliyun.teaopenapi.models.Config;
  8. import com.fjhx.admin.BytesailingApplication;
  9. import com.fjhx.dingding.constant.Constant;
  10. import com.fjhx.dingding.service.DingService;
  11. import com.ruoyi.common.annotation.TenantIgnore;
  12. import com.ruoyi.common.exception.ServiceException;
  13. import com.ruoyi.framework.mybatis.holder.TenantHolder;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.junit.Test;
  16. import org.junit.runner.RunWith;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.boot.test.context.SpringBootTest;
  19. import org.springframework.test.context.junit4.SpringRunner;
  20. @RunWith(SpringRunner.class)
  21. @SpringBootTest(classes = BytesailingApplication.class)
  22. @Slf4j
  23. public class DingDingTest {
  24. @Autowired
  25. private DingService dingService;
  26. @TenantIgnore
  27. @Test
  28. public void test1() {
  29. TenantHolder.setIgnore(true);
  30. String a = "{ \"bizData\":[\n" +
  31. " {\n" +
  32. " \"gmt_create\":1683798054000,\n" +
  33. " \"biz_type\":4,\n" +
  34. " \"open_cursor\":0,\n" +
  35. " \"subscribe_id\":\"30319001_0\",\n" +
  36. " \"id\":19960,\n" +
  37. " \"gmt_modified\":1683798054000,\n" +
  38. " \"biz_id\":\"30319001\",\n" +
  39. " \"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____&corpId=dingc265ea6f59c8a65524f2f5cc6abecb85&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" +
  40. " \"corp_id\":\"dingc265ea6f59c8a65524f2f5cc6abecb85\",\n" +
  41. " \"status\":0\n" +
  42. " },\n" +
  43. " {\n" +
  44. " \"gmt_create\":1683798959000,\n" +
  45. " \"biz_type\":4,\n" +
  46. " \"open_cursor\":0,\n" +
  47. " \"subscribe_id\":\"30319001_0\",\n" +
  48. " \"id\":19966,\n" +
  49. " \"gmt_modified\":1683798959000,\n" +
  50. " \"biz_id\":\"30319001\",\n" +
  51. " \"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____&corpId=ding53d823e205604918a39a90f97fcb1e09&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" +
  52. " \"corp_id\":\"ding53d823e205604918a39a90f97fcb1e09\",\n" +
  53. " \"status\":0\n" +
  54. " },\n" +
  55. " {\n" +
  56. " \"gmt_create\":1683799205000,\n" +
  57. " \"biz_type\":4,\n" +
  58. " \"open_cursor\":0,\n" +
  59. " \"subscribe_id\":\"30319001_0\",\n" +
  60. " \"id\":19970,\n" +
  61. " \"gmt_modified\":1683799205000,\n" +
  62. " \"biz_id\":\"30319001\",\n" +
  63. " \"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____&corpId=dingb543e6dc430497bbee0f45d8e4f7c288&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" +
  64. " \"corp_id\":\"dingb543e6dc430497bbee0f45d8e4f7c288\",\n" +
  65. " \"status\":0\n" +
  66. " },\n" +
  67. " {\n" +
  68. " \"gmt_create\":1683810014000,\n" +
  69. " \"biz_type\":4,\n" +
  70. " \"open_cursor\":0,\n" +
  71. " \"subscribe_id\":\"30319001_0\",\n" +
  72. " \"id\":19981,\n" +
  73. " \"gmt_modified\":1683810014000,\n" +
  74. " \"biz_id\":\"30319001\",\n" +
  75. " \"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____&corpId=ding379d86d92b0c876eee0f45d8e4f7c288&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" +
  76. " \"corp_id\":\"ding379d86d92b0c876eee0f45d8e4f7c288\",\n" +
  77. " \"status\":0\n" +
  78. " },\n" +
  79. " {\n" +
  80. " \"gmt_create\":1683854166000,\n" +
  81. " \"biz_type\":4,\n" +
  82. " \"open_cursor\":0,\n" +
  83. " \"subscribe_id\":\"30319001_0\",\n" +
  84. " \"id\":19993,\n" +
  85. " \"gmt_modified\":1683854166000,\n" +
  86. " \"biz_id\":\"30319001\",\n" +
  87. " \"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____&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\\\":\\\"844DD3DFE04AAD2F91E6B2AEE5\\\"}\",\n" +
  88. " \"corp_id\":\"ding3f327504d104ac1cf2c783f7214b6d69\",\n" +
  89. " \"status\":0\n" +
  90. " },\n" +
  91. " {\n" +
  92. " \"gmt_create\":1683854404000,\n" +
  93. " \"biz_type\":2,\n" +
  94. " \"open_cursor\":0,\n" +
  95. " \"subscribe_id\":\"30319001_0\",\n" +
  96. " \"id\":19994,\n" +
  97. " \"gmt_modified\":1683854404000,\n" +
  98. " \"biz_id\":\"30319001\",\n" +
  99. " \"biz_data\":\"{\\\"eventId\\\":\\\"e50ed7cdf209448fa567e523bfc52b83\\\",\\\"syncAction\\\":\\\"suite_ticket\\\",\\\"suiteTicket\\\":\\\"2SwvImnFmDGqrCpEdmHeOjwBpBBj0o30nJmsqzMGUD3HJ2zMqckkTwlzM40GycbsjBKE0h2wUQHb3AQMrRtzCl\\\",\\\"syncSeq\\\":\\\"2AEA5DA284BB85DEE8CA8D33A9\\\"}\",\n" +
  100. " \"corp_id\":\"ding53d823e205604918a39a90f97fcb1e09\",\n" +
  101. " \"status\":0\n" +
  102. " }\n" +
  103. " ]}";
  104. dingService.pushHigh(JSON.parseObject(a));
  105. System.out.println();
  106. }
  107. public static void main(String[] args) {
  108. String a = "{ \"bizData\":[ {\n" +
  109. " \"gmt_create\":1683854404000,\n" +
  110. " \"biz_type\":2,\n" +
  111. " \"open_cursor\":0,\n" +
  112. " \"subscribe_id\":\"30319001_0\",\n" +
  113. " \"id\":19994,\n" +
  114. " \"gmt_modified\":1683854404000,\n" +
  115. " \"biz_id\":\"30319001\",\n" +
  116. " \"biz_data\":\"{\\\"eventId\\\":\\\"e50ed7cdf209448fa567e523bfc52b83\\\",\\\"syncAction\\\":\\\"suite_ticket\\\",\\\"suiteTicket\\\":\\\"2SwvImnFmDGqrCpEdmHeOjwBpBBj0o30nJmsqzMGUD3HJ2zMqckkTwlzM40GycbsjBKE0h2wUQHb3AQMrRtzCl\\\",\\\"syncSeq\\\":\\\"2AEA5DA284BB85DEE8CA8D33A9\\\"}\",\n" +
  117. " \"corp_id\":\"ding53d823e205604918a39a90f97fcb1e09\",\n" +
  118. " \"status\":0\n" +
  119. " }]}";
  120. System.out.println(JSON.parse(a));
  121. }
  122. private static String test1(String corpId) {
  123. GetCorpAccessTokenRequest getCorpAccessTokenRequest = new GetCorpAccessTokenRequest()
  124. .setSuiteKey(Constant.SUITE_KEY)
  125. .setSuiteSecret(Constant.SUITE_SECRET)
  126. .setAuthCorpId(corpId)
  127. .setSuiteTicket("2SwvImnFmDGqrCpEdmHeOjwBpBBj0o30nJmsqzMGUD3HJ2zMqckkTwlzM40GycbsjBKE0h2wUQHb3AQMrRtzCl");
  128. try {
  129. Client client = getClient2();
  130. GetCorpAccessTokenResponseBody body = client.getCorpAccessToken(getCorpAccessTokenRequest).getBody();
  131. return body.getAccessToken();
  132. } catch (Exception e) {
  133. TeaException teaException;
  134. if (e instanceof TeaException) {
  135. teaException = (TeaException) e;
  136. } else {
  137. teaException = new TeaException(e.getMessage(), e);
  138. }
  139. String errCode = teaException.getCode();
  140. String errMsg = teaException.getMessage();
  141. if (StrUtil.isAllNotBlank(errCode, errMsg)) {
  142. log.error("钉钉授权认证失败: code:{},message:{}", errCode, errMsg);
  143. throw new ServiceException(errMsg);
  144. } else {
  145. log.error("钉钉授权认证失败", teaException);
  146. throw new ServiceException("发生未知异常,钉钉授权认证失败");
  147. }
  148. }
  149. }
  150. private static com.aliyun.dingtalkoauth2_1_0.Client getClient2() throws Exception {
  151. Config config = new Config();
  152. config.protocol = "https";
  153. config.regionId = "central";
  154. return new com.aliyun.dingtalkoauth2_1_0.Client(config);
  155. }
  156. }