entity = restTemplate.postForEntity(webHookUrl, weWorkWebHookDTO, String.class);
+ if (entity.getStatusCode() == HttpStatus.OK) {
+ log.debug("Send weWork webHook: {} Success", webHookUrl);
+ } else {
+ log.warn("Send weWork webHook: {} Failed: {}", webHookUrl, entity.getBody());
+ }
+ } catch (ResourceAccessException e) {
+ log.warn("Send WebHook: {} Failed: {}.", webHookUrl, e.getMessage());
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
}
private void sendWeChatAlert(NoticeReceiver receiver, Alert alert) {
diff --git a/manager/src/main/java/com/usthe/manager/pojo/dto/WeWorkWebHookDTO.java b/manager/src/main/java/com/usthe/manager/pojo/dto/WeWorkWebHookDTO.java
new file mode 100644
index 0000000..4cd6738
--- /dev/null
+++ b/manager/src/main/java/com/usthe/manager/pojo/dto/WeWorkWebHookDTO.java
@@ -0,0 +1,41 @@
+package com.usthe.manager.pojo.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 企业微信机器人请求消息体
+ * @author 花城
+ * @version 1.0
+ * @date 2022/2/21 6:55 下午
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class WeWorkWebHookDTO {
+
+ public static final String WEBHOOK_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=";
+ private static final String MARKDOWN = "markdown";
+
+ /**
+ * 消息类型
+ */
+ private String msgtype = MARKDOWN;
+
+ /**
+ * markdown消息
+ */
+ private MarkdownDTO markdown;
+
+ @Data
+ public static class MarkdownDTO {
+ /**
+ * 消息内容
+ */
+ private String content;
+ }
+
+}
diff --git a/script/sql/schema.sql b/script/sql/schema.sql
index ccf5e4a..7b85496 100644
--- a/script/sql/schema.sql
+++ b/script/sql/schema.sql
@@ -148,11 +148,12 @@ CREATE TABLE notice_receiver
(
id bigint not null auto_increment comment '消息接收人ID',
name varchar(100) not null comment '消息接收人姓名',
- type tinyint not null comment '通知信息方式: 0-手机短信 1-邮箱 2-webhook 3-微信公众号',
+ type tinyint not null comment '通知信息方式: 0-手机短信 1-邮箱 2-webhook 3-微信公众号 4-企业微信机器人 5-钉钉机器人',
phone varchar(100) comment '手机号, 通知方式为手机短信时有效',
email varchar(100) comment '邮箱账号, 通知方式为邮箱时有效',
- hook_url varchar(100) comment 'URL地址, 通知方式为webhook有效',
- wechat_id varchar(100) comment 'wechat用户openId, 通知方式为微信公众号有效',
+ hook_url varchar(255) comment 'URL地址, 通知方式为webhook有效',
+ wechat_id varchar(255) comment 'openId, 通知方式为微信公众号或企业微信机器人有效',
+ access_token varchar(255) comment '访问token, 通知方式为钉钉机器人有效',
creator varchar(100) comment '创建者',
modifier varchar(100) comment '最新修改者',
gmt_create timestamp default current_timestamp comment 'create time',
diff --git a/web-app/src/app/pojo/NoticeReceiver.ts b/web-app/src/app/pojo/NoticeReceiver.ts
index 0742ff1..67d2bc1 100644
--- a/web-app/src/app/pojo/NoticeReceiver.ts
+++ b/web-app/src/app/pojo/NoticeReceiver.ts
@@ -7,6 +7,7 @@ export class NoticeReceiver {
email!: string;
hookUrl!: string;
wechatId!: string;
+ accessToken!: string;
creator!: string;
modifier!: string;
gmtCreate!: number;
diff --git a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html
index 0561ba5..d0f0fab 100644
--- a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html
+++ b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html
@@ -60,12 +60,17 @@
微信公众号
+
+
+ 企业微信机器人
+
|
{{ data.phone }}
{{ data.email }}
{{ data.hookUrl }}
{{ data.wechatId }}
+ {{ data.wechatId }}
|
{{ data.gmtUpdate ? data.gmtUpdate : data.gmtCreate }} |
@@ -158,24 +163,25 @@
diff --git a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts
index 1523ed1..6ecca0a 100644
--- a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts
+++ b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts
@@ -259,6 +259,8 @@ export class AlertNoticeComponent implements OnInit {
case 3:
label = `${label}WeChat`;
break;
+ case 4:
+ label = `${label}WeWorkRobot`;
}
this.receiversOption.push({
value: item.id,
|