From ab2050c3493afa22619e5bb9c0bfb7b48990f96c Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期一, 17 二月 2025 15:18:38 +0800
Subject: [PATCH] 111
---
server/services/src/main/java/com/doumee/core/dingding/DingDingNotice.java | 108 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 98 insertions(+), 10 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 2eab145..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,9 +1,13 @@
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;
import com.doumee.dao.business.model.BikeRepair;
+import com.doumee.dao.business.model.Sites;
import com.doumee.dao.business.web.request.RepairRequest;
import org.apache.commons.codec.binary.Base64;
@@ -12,6 +16,7 @@
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
@@ -55,26 +60,109 @@
content.put("text",text);
HttpsUtil.post(ddUrl+"×tamp="+timestamp+"&sign="+getSign(timestamp,secret), JSONObject.toJSONString(content),"application/json",false);
}
+ /**
+ * 閽夐拤閫氱煡 - 绔欑偣閫氫俊寮傚父涓婃姤
+ * @param ddUrl
+ * @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<>();
+ String desc = "";
+ if(siteList.size() == 1){
+ desc = "銆愮珯鐐瑰紓甯镐笂鎶ャ�戠珯鐐广��"+siteList.get(0).getId()+"銆戯紝鑷��"+ DateUtil.getPlusTime2(siteList.get(0).getLastLinkDate())+"銆戝悗鏈敹鍒伴�氳璇锋眰,璇峰強鏃舵煡鐪嬪鐞哱n";
+ }else{
+ 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+"×tamp="+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+"×tamp="+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