Bladeren bron

feat:添加钉钉和企业微信消息通知

荭琪枫 2 jaren geleden
bovenliggende
commit
2b29d500cf
20 gewijzigde bestanden met toevoegingen van 155 en 60 verwijderingen
  1. 0 9
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java
  2. 0 9
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java
  3. 0 16
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/DingTalkEventListener.java
  4. 0 16
      iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/QyWechatEventListener.java
  5. 0 1
      iot-common/iot-message-bus/pom.xml
  6. 0 0
      iot-common/iot-message-notify/messageCenter.md
  7. 11 7
      iot-common/iot-message-notify/pom.xml
  8. 0 0
      iot-common/iot-message-notify/readme.md
  9. 37 0
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java
  10. 3 1
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java
  11. 5 1
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java
  12. 26 0
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java
  13. 34 0
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/DingTalkEventListener.java
  14. 0 0
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventListener.java
  15. 0 0
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventManager.java
  16. 0 0
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventType.java
  17. 0 0
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/MessageEventListener.java
  18. 38 0
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/QyWechatEventListener.java
  19. 0 0
      iot-common/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java
  20. 1 0
      iot-common/pom.xml

+ 0 - 9
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java

@@ -1,9 +0,0 @@
-package cc.iotkit.message.model;
-
-/**
- * author: 石恒
- * date: 2023-05-08 15:58
- * description:
- **/
-public class DingTalkMessage extends Message{
-}

+ 0 - 9
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java

@@ -1,9 +0,0 @@
-package cc.iotkit.message.model;
-
-/**
- * author: 石恒
- * date: 2023-05-08 15:58
- * description:
- **/
-public class QyWechatMessage extends Message{
-}

+ 0 - 16
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/DingTalkEventListener.java

@@ -1,16 +0,0 @@
-package cc.iotkit.message.notify;
-
-import cc.iotkit.message.model.Message;
-
-/**
- * author: 石恒
- * date: 2023-05-08 15:09
- * description:
- **/
-public class DingTalkEventListener implements EventListener{
-
-    @Override
-    public void doEvent(Message message) {
-
-    }
-}

+ 0 - 16
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/QyWechatEventListener.java

@@ -1,16 +0,0 @@
-package cc.iotkit.message.notify;
-
-import cc.iotkit.message.model.Message;
-
-/**
- * author: 石恒
- * date: 2023-05-08 15:09
- * description:
- **/
-public class QyWechatEventListener implements EventListener{
-
-    @Override
-    public void doEvent(Message message) {
-
-    }
-}

+ 0 - 1
iot-common/iot-message-bus/pom.xml

@@ -19,7 +19,6 @@
         <module>iot-message-core</module>
         <module>iot-vertx-event-bus</module>
         <module>iot-message-rocketmq</module>
-        <module>iot-message-notify</module>
     </modules>
 
     <dependencies>

+ 0 - 0
iot-common/iot-message-bus/iot-message-notify/messageCenter.md → iot-common/iot-message-notify/messageCenter.md


+ 11 - 7
iot-common/iot-message-bus/iot-message-notify/pom.xml → iot-common/iot-message-notify/pom.xml

@@ -3,7 +3,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <parent>
-        <artifactId>iot-message-bus</artifactId>
+        <artifactId>iot-common</artifactId>
         <groupId>cc.iotkit</groupId>
         <version>${revision}</version>
     </parent>
@@ -14,20 +14,24 @@
     <dependencies>
 
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-autoconfigure</artifactId>
+            <groupId>io.vertx</groupId>
+            <artifactId>vertx-web-client</artifactId>
         </dependency>
 
         <dependency>
-            <groupId>cc.iotkit</groupId>
-            <artifactId>iot-model</artifactId>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
 
         <dependency>
-            <groupId>cc.iotkit</groupId>
-            <artifactId>iot-message-core</artifactId>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 0 - 0
iot-common/iot-message-bus/iot-message-notify/readme.md → iot-common/iot-message-notify/readme.md


+ 37 - 0
iot-common/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java

@@ -0,0 +1,37 @@
+package cc.iotkit.message.model;
+
+import lombok.Builder;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:58
+ * description:
+ **/
+@Data
+@Builder
+public class DingTalkMessage implements Serializable {
+
+    /**
+     * 消息文本类型 目前只支持文本
+     */
+    private String msgtype;
+
+    /**
+     * 文本消息
+     */
+    private MessageContent text;
+
+    @Data
+    @Builder
+    public static class MessageContent {
+
+        /**
+         * 文本内容
+         */
+        private String content;
+
+    }
+}

+ 3 - 1
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java → iot-common/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java

@@ -1,9 +1,11 @@
 package cc.iotkit.message.model;
 
+import java.io.Serializable;
+
 /**
  * author: 石恒
  * date: 2023-05-08 15:58
  * description:
  **/
-public class EmailMessage extends Message {
+public class EmailMessage implements Serializable {
 }

+ 5 - 1
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java → iot-common/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java

@@ -1,10 +1,14 @@
 package cc.iotkit.message.model;
 
+import lombok.Data;
+
 /**
  * author: 石恒
  * date: 2023-05-08 15:15
  * description:
  **/
-public abstract class Message {
+@Data
+public class Message {
+    private String key;
     private String content;
 }

+ 26 - 0
iot-common/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java

@@ -0,0 +1,26 @@
+package cc.iotkit.message.model;
+
+import lombok.Builder;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:58
+ * description:
+ **/
+@Data
+@Builder
+public class QyWechatMessage implements Serializable {
+
+    private String msgtype;
+
+    private MessageContent text;
+
+    @Data
+    @Builder
+    public static class MessageContent{
+        private String content;
+    }
+}

+ 34 - 0
iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/DingTalkEventListener.java

@@ -0,0 +1,34 @@
+package cc.iotkit.message.notify;
+
+import cc.iotkit.message.model.DingTalkMessage;
+import cc.iotkit.message.model.Message;
+import io.vertx.core.Vertx;
+import io.vertx.ext.web.client.WebClient;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:09
+ * description:
+ **/
+@Slf4j
+public class DingTalkEventListener implements EventListener{
+    private String baseUrl = "https://oapi.dingtalk.com/robot/send?access_token=%s";
+    @Override
+    public void doEvent(Message message) {
+        WebClient client = WebClient.create(Vertx.vertx());
+        String url = String.format(baseUrl, message.getKey());
+        DingTalkMessage qyWechatMessage = DingTalkMessage.builder()
+                .msgtype("text")
+                .text(DingTalkMessage.MessageContent.builder().content(message.getContent()).build())
+                .build();
+        client.post(url).sendJson(qyWechatMessage, rs -> {
+            if (rs.succeeded()) {
+                log.info("发送成功.");
+            }
+            if (rs.failed()) {
+                log.info("发送失败.");
+            }
+        });
+    }
+}

+ 0 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventListener.java → iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventListener.java


+ 0 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventManager.java → iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventManager.java


+ 0 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventType.java → iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventType.java


+ 0 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/MessageEventListener.java → iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/MessageEventListener.java


+ 38 - 0
iot-common/iot-message-notify/src/main/java/cc/iotkit/message/notify/QyWechatEventListener.java

@@ -0,0 +1,38 @@
+package cc.iotkit.message.notify;
+
+import cc.iotkit.message.model.Message;
+import cc.iotkit.message.model.QyWechatMessage;
+import io.vertx.core.Vertx;
+import io.vertx.ext.web.client.WebClient;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * author: 石恒
+ * date: 2023-05-08 15:09
+ * description:
+ **/
+@Slf4j
+@Component
+public class QyWechatEventListener implements EventListener {
+
+    private String baseUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=%s";
+
+    @Override
+    public void doEvent(Message message) {
+        WebClient client = WebClient.create(Vertx.vertx());
+        String url = String.format(baseUrl, message.getKey());
+        QyWechatMessage qyWechatMessage = QyWechatMessage.builder()
+                .msgtype("text")
+                .text(QyWechatMessage.MessageContent.builder().content(message.getContent()).build())
+                .build();
+        client.post(url).sendJson(qyWechatMessage, rs -> {
+            if (rs.succeeded()) {
+                log.info("发送成功.");
+            }
+            if (rs.failed()) {
+                log.info("发送失败.");
+            }
+        });
+    }
+}

+ 0 - 0
iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java → iot-common/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java


+ 1 - 0
iot-common/pom.xml

@@ -21,6 +21,7 @@
         <module>iot-common-core</module>
         <module>iot-script-engine</module>
         <module>iot-message-bus</module>
+        <module>iot-message-notify</module>
     </modules>