parent
7ea71af0a4
commit
7399f78092
@ -0,0 +1,24 @@
|
||||
package com.java3y.austin.common.dto.account;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 飞书 机器人 账号信息
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class FeiShuRobotAccount {
|
||||
/**
|
||||
* 自定义群机器人中的 webhook
|
||||
*/
|
||||
private String webhook;
|
||||
|
||||
}
|
@ -0,0 +1,310 @@
|
||||
package com.java3y.austin.handler.domain.feishu;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author 3y
|
||||
* 飞书机器人 请求参数
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class FeiShuRobotParam {
|
||||
|
||||
/**
|
||||
* msgType
|
||||
*/
|
||||
@JSONField(name = "msg_type")
|
||||
private String msgType;
|
||||
/**
|
||||
* content
|
||||
*/
|
||||
@JSONField(name = "content")
|
||||
private ContentDTO content;
|
||||
/**
|
||||
* card
|
||||
*/
|
||||
@JSONField(name = "card")
|
||||
private CardDTO card;
|
||||
|
||||
/**
|
||||
* ContentDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class ContentDTO {
|
||||
/**
|
||||
* text
|
||||
*/
|
||||
@JSONField(name = "text")
|
||||
private String text;
|
||||
/**
|
||||
* post
|
||||
*/
|
||||
@JSONField(name = "post")
|
||||
private PostDTO post;
|
||||
/**
|
||||
* shareChatId
|
||||
*/
|
||||
@JSONField(name = "share_chat_id")
|
||||
private String shareChatId;
|
||||
/**
|
||||
* imageKey
|
||||
*/
|
||||
@JSONField(name = "image_key")
|
||||
private String imageKey;
|
||||
|
||||
/**
|
||||
* PostDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class PostDTO {
|
||||
/**
|
||||
* zhCn
|
||||
*/
|
||||
@JSONField(name = "zh_cn")
|
||||
private ZhCnDTO zhCn;
|
||||
|
||||
/**
|
||||
* ZhCnDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class ZhCnDTO {
|
||||
/**
|
||||
* title
|
||||
*/
|
||||
@JSONField(name = "title")
|
||||
private String title;
|
||||
/**
|
||||
* content
|
||||
*/
|
||||
@JSONField(name = "content")
|
||||
private List<List<ContentDTO.PostDTO.ZhCnDTO.PostContentDTO>> content;
|
||||
|
||||
/**
|
||||
* ContentDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class PostContentDTO {
|
||||
/**
|
||||
* tag
|
||||
*/
|
||||
@JSONField(name = "tag")
|
||||
private String tag;
|
||||
/**
|
||||
* text
|
||||
*/
|
||||
@JSONField(name = "text")
|
||||
private String text;
|
||||
/**
|
||||
* href
|
||||
*/
|
||||
@JSONField(name = "href")
|
||||
private String href;
|
||||
/**
|
||||
* userId
|
||||
*/
|
||||
@JSONField(name = "user_id")
|
||||
private String userId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CardDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class CardDTO {
|
||||
/**
|
||||
* config
|
||||
*/
|
||||
@JSONField(name = "config")
|
||||
private ConfigDTO config;
|
||||
/**
|
||||
* elements
|
||||
*/
|
||||
@JSONField(name = "elements")
|
||||
private List<ElementsDTO> elements;
|
||||
/**
|
||||
* header
|
||||
*/
|
||||
@JSONField(name = "header")
|
||||
private HeaderDTO header;
|
||||
|
||||
/**
|
||||
* ConfigDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class ConfigDTO {
|
||||
/**
|
||||
* wideScreenMode
|
||||
*/
|
||||
@JSONField(name = "wide_screen_mode")
|
||||
private Boolean wideScreenMode;
|
||||
/**
|
||||
* enableForward
|
||||
*/
|
||||
@JSONField(name = "enable_forward")
|
||||
private Boolean enableForward;
|
||||
}
|
||||
|
||||
/**
|
||||
* HeaderDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class HeaderDTO {
|
||||
/**
|
||||
* title
|
||||
*/
|
||||
@JSONField(name = "title")
|
||||
private TitleDTO title;
|
||||
|
||||
/**
|
||||
* TitleDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class TitleDTO {
|
||||
/**
|
||||
* content
|
||||
*/
|
||||
@JSONField(name = "content")
|
||||
private String content;
|
||||
/**
|
||||
* tag
|
||||
*/
|
||||
@JSONField(name = "tag")
|
||||
private String tag;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ElementsDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class ElementsDTO {
|
||||
/**
|
||||
* tag
|
||||
*/
|
||||
@JSONField(name = "tag")
|
||||
private String tag;
|
||||
/**
|
||||
* text
|
||||
*/
|
||||
@JSONField(name = "text")
|
||||
private TextDTO text;
|
||||
/**
|
||||
* actions
|
||||
*/
|
||||
@JSONField(name = "actions")
|
||||
private List<ActionsDTO> actions;
|
||||
|
||||
/**
|
||||
* TextDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class TextDTO {
|
||||
/**
|
||||
* content
|
||||
*/
|
||||
@JSONField(name = "content")
|
||||
private String content;
|
||||
/**
|
||||
* tag
|
||||
*/
|
||||
@JSONField(name = "tag")
|
||||
private String tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* ActionsDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class ActionsDTO {
|
||||
/**
|
||||
* tag
|
||||
*/
|
||||
@JSONField(name = "tag")
|
||||
private String tag;
|
||||
/**
|
||||
* text
|
||||
*/
|
||||
@JSONField(name = "text")
|
||||
private TextDTO text;
|
||||
/**
|
||||
* url
|
||||
*/
|
||||
@JSONField(name = "url")
|
||||
private String url;
|
||||
/**
|
||||
* type
|
||||
*/
|
||||
@JSONField(name = "type")
|
||||
private String type;
|
||||
/**
|
||||
* value
|
||||
*/
|
||||
@JSONField(name = "value")
|
||||
private ValueDTO value;
|
||||
|
||||
/**
|
||||
* TextDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class TextDTO {
|
||||
}
|
||||
|
||||
/**
|
||||
* ValueDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public static class ValueDTO {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.java3y.austin.handler.domain.feishu;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* @author 3y
|
||||
* 飞书机器人 返回值
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class FeiShuRobotResult {
|
||||
|
||||
/**
|
||||
* extra
|
||||
*/
|
||||
@JSONField(name = "Extra")
|
||||
private Object extra;
|
||||
/**
|
||||
* statusCode
|
||||
*/
|
||||
@JSONField(name = "StatusCode")
|
||||
private Integer statusCode;
|
||||
/**
|
||||
* statusMessage
|
||||
*/
|
||||
@JSONField(name = "StatusMessage")
|
||||
private String statusMessage;
|
||||
/**
|
||||
* code
|
||||
*/
|
||||
@JSONField(name = "code")
|
||||
private Integer code;
|
||||
/**
|
||||
* msg
|
||||
*/
|
||||
@JSONField(name = "msg")
|
||||
private String msg;
|
||||
/**
|
||||
* data
|
||||
*/
|
||||
@JSONField(name = "data")
|
||||
private DataDTO data;
|
||||
|
||||
/**
|
||||
* DataDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class DataDTO {
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package com.java3y.austin.handler.handler.impl;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.io.file.FileReader;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.http.ContentType;
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.java3y.austin.common.constant.SendAccountConstant;
|
||||
import com.java3y.austin.common.domain.TaskInfo;
|
||||
import com.java3y.austin.common.dto.account.EnterpriseWeChatRobotAccount;
|
||||
import com.java3y.austin.common.dto.account.FeiShuRobotAccount;
|
||||
import com.java3y.austin.common.dto.model.EnterpriseWeChatRobotContentModel;
|
||||
import com.java3y.austin.common.dto.model.FeiShuRobotContentModel;
|
||||
import com.java3y.austin.common.enums.ChannelType;
|
||||
import com.java3y.austin.common.enums.SendMessageType;
|
||||
import com.java3y.austin.handler.domain.feishu.FeiShuRobotParam;
|
||||
import com.java3y.austin.handler.domain.feishu.FeiShuRobotResult;
|
||||
import com.java3y.austin.handler.domain.wechat.robot.EnterpriseWeChatRobotParam;
|
||||
import com.java3y.austin.handler.handler.BaseHandler;
|
||||
import com.java3y.austin.handler.handler.Handler;
|
||||
import com.java3y.austin.support.domain.MessageTemplate;
|
||||
import com.java3y.austin.support.utils.AccountUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 企业微信群机器人 消息处理器
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class FeiShuRobotHandler extends BaseHandler implements Handler {
|
||||
|
||||
@Autowired
|
||||
private AccountUtils accountUtils;
|
||||
|
||||
public FeiShuRobotHandler() {
|
||||
channelCode = ChannelType.FEI_SHU_ROBOT.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handler(TaskInfo taskInfo) {
|
||||
try {
|
||||
FeiShuRobotAccount account = accountUtils.getAccount(taskInfo.getSendAccount(), SendAccountConstant.FEI_SHU_ROBOT_ACCOUNT_KEY, SendAccountConstant.FEI_SHU_ROBOT_PREFIX, FeiShuRobotAccount.class);
|
||||
FeiShuRobotParam feiShuRobotParam = assembleParam(taskInfo);
|
||||
String result = HttpRequest.post(account.getWebhook())
|
||||
.header(Header.CONTENT_TYPE.getValue(), ContentType.JSON.getValue())
|
||||
.body(JSON.toJSONString(feiShuRobotParam))
|
||||
.timeout(2000)
|
||||
.execute().body();
|
||||
FeiShuRobotResult feiShuRobotResult = JSON.parseObject(result, FeiShuRobotResult.class);
|
||||
if (feiShuRobotResult.getStatusCode() == 0) {
|
||||
return true;
|
||||
}
|
||||
log.error("FeiShuRobotHandler#handler fail! result:{},params:{}", JSON.toJSONString(feiShuRobotResult), JSON.toJSONString(taskInfo));
|
||||
} catch (Exception e) {
|
||||
log.error("FeiShuRobotHandler#handler fail!e:{},params:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(taskInfo));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private FeiShuRobotParam assembleParam(TaskInfo taskInfo) {
|
||||
FeiShuRobotContentModel contentModel = (FeiShuRobotContentModel) taskInfo.getContentModel();
|
||||
|
||||
FeiShuRobotParam param = FeiShuRobotParam.builder()
|
||||
.msgType(SendMessageType.geFeiShuRobotTypeByCode(contentModel.getSendType())).build();
|
||||
|
||||
if (SendMessageType.TEXT.getCode().equals(contentModel.getSendType())) {
|
||||
param.setContent(FeiShuRobotParam.ContentDTO.builder().text(contentModel.getContent()).build());
|
||||
}
|
||||
if (SendMessageType.RICH_TEXT.getCode().equals(contentModel.getSendType())) {
|
||||
List<FeiShuRobotParam.ContentDTO.PostDTO.ZhCnDTO.PostContentDTO> postContentDTOS = JSON.parseArray(contentModel.getPostContent(), FeiShuRobotParam.ContentDTO.PostDTO.ZhCnDTO.PostContentDTO.class);
|
||||
List<List<FeiShuRobotParam.ContentDTO.PostDTO.ZhCnDTO.PostContentDTO>> postContentList = new ArrayList<>();
|
||||
postContentList.add(postContentDTOS);
|
||||
FeiShuRobotParam.ContentDTO.PostDTO postDTO = FeiShuRobotParam.ContentDTO.PostDTO.builder()
|
||||
.zhCn(FeiShuRobotParam.ContentDTO.PostDTO.ZhCnDTO.builder().title(contentModel.getTitle()).content(postContentList).build())
|
||||
.build();
|
||||
param.setContent(FeiShuRobotParam.ContentDTO.builder().post(postDTO).build());
|
||||
}
|
||||
if (SendMessageType.SHARE_CHAT.getCode().equals(contentModel.getSendType())) {
|
||||
param.setContent(FeiShuRobotParam.ContentDTO.builder().shareChatId(contentModel.getMediaId()).build());
|
||||
}
|
||||
if (SendMessageType.IMAGE.getCode().equals(contentModel.getSendType())) {
|
||||
param.setContent(FeiShuRobotParam.ContentDTO.builder().imageKey(contentModel.getMediaId()).build());
|
||||
}
|
||||
if (SendMessageType.ACTION_CARD.getCode().equals(contentModel.getSendType())) {
|
||||
//
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recall(MessageTemplate messageTemplate) {
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue