飞书发送卡片消息对接完成

This commit is contained in:
zer0Black
2022-07-01 13:38:20 +08:00
parent 73d3fdba36
commit 50342fcbe4
2 changed files with 25 additions and 19 deletions
@@ -1,6 +1,7 @@
package com.jero.modules.feishu.service.impl; package com.jero.modules.feishu.service.impl;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jero.modules.feishu.service.IFeishuService; import com.jero.modules.feishu.service.IFeishuService;
@@ -135,7 +136,7 @@ public class FeishuServiceImpl implements IFeishuService {
contentSb.append("{"); contentSb.append("{");
contentSb.append("\"tag\": \"div\","); contentSb.append("\"tag\": \"div\",");
contentSb.append("\"text\": {"); contentSb.append("\"text\": {");
contentSb.append("\"content\": " + feishuMsgVo.getContent() + ","); contentSb.append("\"content\": \"" + feishuMsgVo.getContent() + "\",");
contentSb.append("\"tag\": \"lark_md\""); contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}"); contentSb.append("}");
contentSb.append("},"); contentSb.append("},");
@@ -143,52 +144,55 @@ public class FeishuServiceImpl implements IFeishuService {
// 补充tasktype、project、Initiator等的外层 // 补充tasktype、project、Initiator等的外层
contentSb.append("{"); contentSb.append("{");
contentSb.append("\"fields\": ["); contentSb.append("\"fields\": [");
if (StrUtil.isNotEmpty(feishuMsgVo.getTaskType())){ contentSb.append("{");
contentSb.append("{"); contentSb.append("\"is_short\": false,");
contentSb.append("\"is_short\": false,"); contentSb.append("\"text\": {");
contentSb.append("\"text\": {"); contentSb.append("\"content\": \"**Task Type** " + feishuMsgVo.getTaskType() + "\",");
contentSb.append("\"content\": \"**Task Type** " + feishuMsgVo.getTaskType() + "\","); contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("\"tag\": \"lark_md\""); contentSb.append("}");
contentSb.append("}"); contentSb.append("}");
contentSb.append("},");
}
if (StrUtil.isNotEmpty(feishuMsgVo.getRegulationNo())){ if (StrUtil.isNotEmpty(feishuMsgVo.getRegulationNo())){
contentSb.append(",");
contentSb.append("{"); contentSb.append("{");
contentSb.append("\"is_short\": false,"); contentSb.append("\"is_short\": false,");
contentSb.append("\"text\": {"); contentSb.append("\"text\": {");
contentSb.append("\"content\": \"**Regulation No** " + feishuMsgVo.getRegulationNo() + "\","); contentSb.append("\"content\": \"**Regulation No** " + feishuMsgVo.getRegulationNo() + "\",");
contentSb.append("\"tag\": \"lark_md\""); contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}"); contentSb.append("}");
contentSb.append("},"); contentSb.append("}");
} }
if (StrUtil.isNotEmpty(feishuMsgVo.getProject())){ if (StrUtil.isNotEmpty(feishuMsgVo.getProject())){
contentSb.append(",");
contentSb.append("{"); contentSb.append("{");
contentSb.append("\"is_short\": false,"); contentSb.append("\"is_short\": false,");
contentSb.append("\"text\": {"); contentSb.append("\"text\": {");
contentSb.append("\"content\": \"**Project** " + feishuMsgVo.getProject() + "\","); contentSb.append("\"content\": \"**Project** " + feishuMsgVo.getProject() + "\",");
contentSb.append("\"tag\": \"lark_md\""); contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}"); contentSb.append("}");
contentSb.append("},"); contentSb.append("}");
} }
if (StrUtil.isNotEmpty(feishuMsgVo.getInitiator())){ if (StrUtil.isNotEmpty(feishuMsgVo.getInitiator())){
contentSb.append(",");
contentSb.append("{"); contentSb.append("{");
contentSb.append("\"is_short\": false,"); contentSb.append("\"is_short\": false,");
contentSb.append("\"text\": {"); contentSb.append("\"text\": {");
contentSb.append("\"content\": \"**Initiator** " + feishuMsgVo.getInitiator() + "\","); contentSb.append("\"content\": \"**Initiator** " + feishuMsgVo.getInitiator() + "\",");
contentSb.append("\"tag\": \"lark_md\""); contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}"); contentSb.append("}");
contentSb.append("},"); contentSb.append("}");
} }
if (StrUtil.isNotEmpty(feishuMsgVo.getDueDate())){ if (StrUtil.isNotEmpty(feishuMsgVo.getDueDate())){
contentSb.append(",");
contentSb.append("{"); contentSb.append("{");
contentSb.append("\"is_short\": false,"); contentSb.append("\"is_short\": false,");
contentSb.append("\"text\": {"); contentSb.append("\"text\": {");
contentSb.append("\"content\": \"**Due Date** " + feishuMsgVo.getDueDate() + "\","); contentSb.append("\"content\": \"**Due Date** " + feishuMsgVo.getDueDate() + "\",");
contentSb.append("\"tag\": \"lark_md\""); contentSb.append("\"tag\": \"lark_md\"");
contentSb.append("}"); contentSb.append("}");
contentSb.append("},"); contentSb.append("}");
} }
contentSb.append("]"); contentSb.append("],");
contentSb.append("\"tag\": \"div\""); contentSb.append("\"tag\": \"div\"");
contentSb.append("},"); contentSb.append("},");
contentSb.append("{\"tag\": \"hr\"},"); contentSb.append("{\"tag\": \"hr\"},");
@@ -203,7 +207,7 @@ public class FeishuServiceImpl implements IFeishuService {
contentSb.append("\"type\": \"primary\","); contentSb.append("\"type\": \"primary\",");
contentSb.append("\"url\": \" "+ feishuMsgVo.getUrl() +" \""); contentSb.append("\"url\": \" "+ feishuMsgVo.getUrl() +" \"");
contentSb.append("}"); contentSb.append("}");
contentSb.append("},"); contentSb.append("],");
contentSb.append("\"tag\": \"action\""); contentSb.append("\"tag\": \"action\"");
contentSb.append("}"); contentSb.append("}");
contentSb.append("],"); contentSb.append("],");
@@ -216,11 +220,13 @@ public class FeishuServiceImpl implements IFeishuService {
contentSb.append("}"); contentSb.append("}");
contentSb.append("}"); contentSb.append("}");
JSONObject jsonObject = JSONObject.parseObject(contentSb.toString());
// 设置请求参数 // 设置请求参数
JSONObject paramsMap = new JSONObject(); JSONObject paramsMap = new JSONObject();
paramsMap.put("user_ids", userIds); paramsMap.put("user_ids", userIds);
paramsMap.put("msg_type", "post"); paramsMap.put("msg_type", "interactive");
paramsMap.put("content", contentSb.toString()); paramsMap.put("card", jsonObject);
// 发送请求给飞书 // 发送请求给飞书
String response = HttpRequestUtil.getResponseOfPOST(batchSendMessageUrl, headerMap, paramsMap.toJSONString()); String response = HttpRequestUtil.getResponseOfPOST(batchSendMessageUrl, headerMap, paramsMap.toJSONString());
+1 -1
View File
@@ -865,7 +865,7 @@ module.exports = {
greenRequirements: '绿确认符合或满足当前要求', greenRequirements: '绿确认符合或满足当前要求',
blueUndeterminedState: '未判断状态', blueUndeterminedState: '未判断状态',
authenticationMessage: '参数收集', authenticationMessage: '参数收集',
taskRegulationComplianceTask: '任务信息', taskRegulationComplianceTask: '法规符合性任务',
accept: '接受', accept: '接受',
refuse: '拒绝', refuse: '拒绝',
taskTermination: '任务终止', taskTermination: '任务终止',