feat:添加钉钉和企业微信消息通知
parent
8a33c66254
commit
2b29d500cf
|
@ -1,9 +0,0 @@
|
|||
package cc.iotkit.message.model;
|
||||
|
||||
/**
|
||||
* author: 石恒
|
||||
* date: 2023-05-08 15:58
|
||||
* description:
|
||||
**/
|
||||
public class DingTalkMessage extends Message{
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package cc.iotkit.message.model;
|
||||
|
||||
/**
|
||||
* author: 石恒
|
||||
* date: 2023-05-08 15:58
|
||||
* description:
|
||||
**/
|
||||
public class QyWechatMessage extends Message{
|
||||
}
|
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
@ -13,21 +13,25 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-web-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-model</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-message-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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 +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("发送失败.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue