From dd5f54f84fdae40267ed76d714f863ccf5a61967 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期一, 17 二月 2025 18:27:22 +0800
Subject: [PATCH] jtt808初始化

---
 server/services/src/main/java/com/doumee/core/dingding/DingDingNotice.java |   89 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 75 insertions(+), 14 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/core/dingding/DingDingNotice.java b/server/services/src/main/java/com/doumee/core/dingding/DingDingNotice.java
index a739834..cd4c44a 100644
--- a/server/services/src/main/java/com/doumee/core/dingding/DingDingNotice.java
+++ b/server/services/src/main/java/com/doumee/core/dingding/DingDingNotice.java
@@ -1,6 +1,8 @@
 package com.doumee.core.dingding;
 
 import com.alibaba.fastjson.JSONObject;
+import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponse;
+import com.aliyun.tea.TeaException;
 import com.doumee.core.constants.Constants;
 import com.doumee.core.utils.DateUtil;
 import com.doumee.core.utils.HttpsUtil;
@@ -63,45 +65,104 @@
      * @param ddUrl
      * @throws Exception
      */
-    public static void siteNoLink(List<Sites> siteList, String ddUrl , String secret)  throws Exception{
+    public static void siteNoLink(List<Sites> siteList,String token,String robotCode,String chatToken)  throws Exception{
+
         Long timestamp = System.currentTimeMillis();
         Map<String,Object> content = new HashMap<>();
-        content.put("msgtype","text");
-        Map<String,String> text = new HashMap<>();
         String  desc = "";
         if(siteList.size() == 1){
             desc = "銆愮珯鐐瑰紓甯镐笂鎶ャ�戠珯鐐广��"+siteList.get(0).getId()+"銆戯紝鑷��"+ DateUtil.getPlusTime2(siteList.get(0).getLastLinkDate())+"銆戝悗鏈敹鍒伴�氳璇锋眰,璇峰強鏃舵煡鐪嬪鐞哱n";
         }else{
-               desc = "銆愮珯鐐瑰紓甯镐笂鎶ャ�� 浠ヤ笅绔欑偣閫氳鍙戠敓寮傚父锛岃鍙婃椂鏌ョ湅澶勭悊锛歕n";
+            desc = "銆愮珯鐐瑰紓甯镐笂鎶ャ�� 浠ヤ笅绔欑偣閫氳鍙戠敓寮傚父锛岃鍙婃椂鏌ョ湅澶勭悊锛歕n";
             for (Sites site : siteList){
                 desc += "绔欑偣銆�"+site.getId()+"銆戯紝鑷��"+ DateUtil.getPlusTime2(site.getLastLinkDate())+"銆戝悗鏈敹鍒伴�氳璇锋眰\n";
             }
         }
 
+  /*       //鍋滅敤鏃х増鏈�氱煡
+        Map<String,String> text = new HashMap<>();
         text.put("content",desc);
+        content.put("msgtype","text");
+
         content.put("text",text);
         HttpsUtil.post(ddUrl+"&timestamp="+timestamp+"&sign="+getSign(timestamp,secret), JSONObject.toJSONString(content),"application/json",false);
+     */   //浣跨敤鏂扮増鏈�氱煡
+
+        sendNoticeNew(desc,token,robotCode,chatToken);
     }
 
 
     /**
      * 閽夐拤閫氱煡 - 绔欑偣鍌ㄨ溅鍛婅
      * @param siteName
-     * @param ddUrl
-     * @param secret
      * @param type 0=瓒呭嚭 1=浣庝簬
      * @param warnVal 鎶ヨ鍊�
      * @throws Exception
      */
-    public static void reservesNotice(String siteName, String ddUrl , String secret, Integer type, BigDecimal warnVal)  throws Exception{
+    public static void reservesNotice(String siteName, Integer type, BigDecimal warnVal,String token,String robotCode,String chatToken)  throws Exception{
         Long timestamp = System.currentTimeMillis();
-        Map<String,Object> content = new HashMap<>();
-        content.put("msgtype","text");
-        Map<String,String> text = new HashMap<>();
-        //text.put("content","銆愮珯鐐瑰偍杞﹀憡璀︺��"+siteName+"锛屽偍杞﹂噺瓒呰繃80%/浣庝簬20%锛岃鍙婃椂杩涜杞﹁締璋冮厤");
+        String desc ="銆愮珯鐐瑰偍杞﹀憡璀︺��"+siteName+"锛屽偍杞﹂噺"+(type.equals(Constants.ZERO)?"瓒呭嚭":"浣庝簬")+warnVal+"%锛岃鍙婃椂杩涜杞﹁締璋冮厤";
+        sendNoticeNew(desc,token,robotCode,chatToken);
+    }
 
-        text.put("content","銆愮珯鐐瑰偍杞﹀憡璀︺��"+siteName+"锛屽偍杞﹂噺"+(type.equals(Constants.ZERO)?"瓒呭嚭":"浣庝簬")+warnVal+"%锛岃鍙婃椂杩涜杞﹁締璋冮厤");
-        content.put("text",text);
-        HttpsUtil.post(ddUrl+"&timestamp="+timestamp+"&sign="+getSign(timestamp,secret), JSONObject.toJSONString(content),"application/json",false);
+
+    public static void sendNoticeNew( String notice,String token,String robotCode,String chatToken) throws Exception {
+        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
+        config.protocol = "https";
+        config.regionId = "central";
+        com.aliyun.dingtalkrobot_1_0.Client client = new com.aliyun.dingtalkrobot_1_0.Client(config);
+        com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendHeaders orgGroupSendHeaders = new com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendHeaders();
+        orgGroupSendHeaders.xAcsDingtalkAccessToken = token;
+        com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendRequest orgGroupSendRequest = new com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendRequest()
+                .setMsgParam("{\"content\":\""+notice+"\"}")
+                .setMsgKey("sampleText")
+                .setRobotCode(robotCode)
+                .setToken(chatToken);
+        try {
+            client.orgGroupSendWithOptions(orgGroupSendRequest, orgGroupSendHeaders, new com.aliyun.teautil.models.RuntimeOptions());
+        } catch (TeaException err) {
+            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                // err 涓惈鏈� code 鍜� message 灞炴�э紝鍙府鍔╁紑鍙戝畾浣嶉棶棰�
+            }
+
+        } catch (Exception _err) {
+            TeaException err = new TeaException(_err.getMessage(), _err);
+            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                // err 涓惈鏈� code 鍜� message 灞炴�э紝鍙府鍔╁紑鍙戝畾浣嶉棶棰�
+            }
+
+        }
+    }
+
+    public static String getToken(String appKey,String appSecret) throws Exception {
+
+        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
+        config.protocol = "https";
+        config.regionId = "central";
+        com.aliyun.dingtalkoauth2_1_0.Client client = new com.aliyun.dingtalkoauth2_1_0.Client(config);
+        com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest getAccessTokenRequest = new com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest();
+        getAccessTokenRequest.setAppKey(appKey);
+        getAccessTokenRequest.setAppSecret(appSecret);
+        try {
+            GetAccessTokenResponse response =  client.getAccessToken(getAccessTokenRequest);
+            return response.getBody().getAccessToken();
+        } catch (TeaException err) {
+            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                // err 涓惈鏈� code 鍜� message 灞炴�э紝鍙府鍔╁紑鍙戝畾浣嶉棶棰�
+            }
+        } catch (Exception _err) {
+            TeaException err = new TeaException(_err.getMessage(), _err);
+            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                // err 涓惈鏈� code 鍜� message 灞炴�э紝鍙府鍔╁紑鍙戝畾浣嶉棶棰�
+            }
+
+        }
+        return  null;
+    }
+
+    public static void main(String[] args) throws Exception {
+
+        String token = "ddedf254eb76334184ab7c98d8bde50a";
+
     }
 }

--
Gitblit v1.9.3