|
|
|
@ -1,35 +1,25 @@
|
|
|
|
|
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.crypto.digest.MD5;
|
|
|
|
|
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.model.EnterpriseWeChatRobotContentModel;
|
|
|
|
|
import com.java3y.austin.common.enums.ChannelType;
|
|
|
|
|
import com.java3y.austin.common.enums.SendMessageType;
|
|
|
|
|
import com.java3y.austin.handler.domain.wechat.robot.EnterpriseWeChatRobotParam;
|
|
|
|
|
import com.java3y.austin.handler.domain.wechat.robot.EnterpriseWeChatRootResult;
|
|
|
|
|
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.io.FileInputStream;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -51,17 +41,17 @@ public class EnterpriseWeChatRobotHandler extends BaseHandler implements Handler
|
|
|
|
|
@Override
|
|
|
|
|
public boolean handler(TaskInfo taskInfo) {
|
|
|
|
|
try {
|
|
|
|
|
EnterpriseWeChatRobotAccount account = accountUtils.getAccountById(taskInfo.getSendAccount(), EnterpriseWeChatRobotAccount.class);
|
|
|
|
|
EnterpriseWeChatRobotAccount account = accountUtils.getAccountById(taskInfo.getSendAccount(), EnterpriseWeChatRobotAccount.class);
|
|
|
|
|
EnterpriseWeChatRobotParam enterpriseWeChatRobotParam = assembleParam(taskInfo);
|
|
|
|
|
String result = HttpRequest.post(account.getWebhook()).header(Header.CONTENT_TYPE.getValue(), ContentType.JSON.getValue())
|
|
|
|
|
.body(JSON.toJSONString(enterpriseWeChatRobotParam))
|
|
|
|
|
.timeout(2000)
|
|
|
|
|
.execute().body();
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(result);
|
|
|
|
|
if (jsonObject.getInteger("errcode") != 0) {
|
|
|
|
|
EnterpriseWeChatRootResult weChatRootResult = JSON.parseObject(result, EnterpriseWeChatRootResult.class);
|
|
|
|
|
if (weChatRootResult.getErrcode() == 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
log.error("EnterpriseWeChatRobotHandler#handler fail! result:{},params:{}", JSON.toJSONString(jsonObject), JSON.toJSONString(taskInfo));
|
|
|
|
|
log.error("EnterpriseWeChatRobotHandler#handler fail! result:{},params:{}", JSON.toJSONString(weChatRootResult), JSON.toJSONString(taskInfo));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("EnterpriseWeChatRobotHandler#handler fail!e:{},params:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(taskInfo));
|
|
|
|
|
}
|
|
|
|
@ -80,10 +70,7 @@ public class EnterpriseWeChatRobotHandler extends BaseHandler implements Handler
|
|
|
|
|
param.setMarkdown(EnterpriseWeChatRobotParam.MarkdownDTO.builder().content(contentModel.getContent()).build());
|
|
|
|
|
}
|
|
|
|
|
if (SendMessageType.IMAGE.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
FileReader fileReader = new FileReader(contentModel.getImagePath());
|
|
|
|
|
byte[] bytes = fileReader.readBytes();
|
|
|
|
|
param.setImage(EnterpriseWeChatRobotParam.ImageDTO.builder().base64(Base64.encode(bytes))
|
|
|
|
|
.md5(DigestUtil.md5Hex(bytes)).build());
|
|
|
|
|
param.setImage(EnterpriseWeChatRobotParam.ImageDTO.builder().base64(contentModel.getBase64()).md5(contentModel.getMd5()).build());
|
|
|
|
|
}
|
|
|
|
|
if (SendMessageType.FILE.getCode().equals(contentModel.getSendType())) {
|
|
|
|
|
param.setFile(EnterpriseWeChatRobotParam.FileDTO.builder().mediaId(contentModel.getMediaId()).build());
|
|
|
|
|