|
|
@ -5,21 +5,26 @@ import cn.hutool.core.date.DateUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
|
|
|
|
|
|
import com.dingtalk.api.DingTalkClient;
|
|
|
|
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
|
|
|
|
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
|
|
|
|
|
|
|
|
import com.dingtalk.api.request.OapiMessageCorpconversationRecallRequest;
|
|
|
|
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
|
|
|
|
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
|
|
|
|
|
|
|
|
import com.dingtalk.api.response.OapiMessageCorpconversationRecallResponse;
|
|
|
|
import com.google.common.base.Throwables;
|
|
|
|
import com.google.common.base.Throwables;
|
|
|
|
import com.java3y.austin.common.constant.AustinConstant;
|
|
|
|
import com.java3y.austin.common.constant.AustinConstant;
|
|
|
|
import com.java3y.austin.common.constant.SendAccountConstant;
|
|
|
|
import com.java3y.austin.common.constant.SendAccountConstant;
|
|
|
|
|
|
|
|
import com.java3y.austin.common.domain.LogParam;
|
|
|
|
import com.java3y.austin.common.domain.TaskInfo;
|
|
|
|
import com.java3y.austin.common.domain.TaskInfo;
|
|
|
|
import com.java3y.austin.common.dto.account.DingDingWorkNoticeAccount;
|
|
|
|
import com.java3y.austin.common.dto.account.DingDingWorkNoticeAccount;
|
|
|
|
import com.java3y.austin.common.dto.model.DingDingRobotContentModel;
|
|
|
|
|
|
|
|
import com.java3y.austin.common.dto.model.DingDingWorkContentModel;
|
|
|
|
import com.java3y.austin.common.dto.model.DingDingWorkContentModel;
|
|
|
|
import com.java3y.austin.common.enums.ChannelType;
|
|
|
|
import com.java3y.austin.common.enums.ChannelType;
|
|
|
|
import com.java3y.austin.common.enums.SendMessageType;
|
|
|
|
import com.java3y.austin.common.enums.SendMessageType;
|
|
|
|
import com.java3y.austin.handler.domain.dingding.DingDingRobotParam;
|
|
|
|
|
|
|
|
import com.java3y.austin.handler.handler.BaseHandler;
|
|
|
|
import com.java3y.austin.handler.handler.BaseHandler;
|
|
|
|
import com.java3y.austin.handler.handler.Handler;
|
|
|
|
import com.java3y.austin.handler.handler.Handler;
|
|
|
|
|
|
|
|
import com.java3y.austin.support.config.SupportThreadPoolConfig;
|
|
|
|
|
|
|
|
import com.java3y.austin.support.domain.MessageTemplate;
|
|
|
|
import com.java3y.austin.support.utils.AccountUtils;
|
|
|
|
import com.java3y.austin.support.utils.AccountUtils;
|
|
|
|
|
|
|
|
import com.java3y.austin.support.utils.LogUtils;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@ -27,7 +32,6 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -41,17 +45,22 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class DingDingWorkNoticeHandler extends BaseHandler implements Handler {
|
|
|
|
public class DingDingWorkNoticeHandler extends BaseHandler implements Handler {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private AccountUtils accountUtils;
|
|
|
|
private AccountUtils accountUtils;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private LogUtils logUtils;
|
|
|
|
|
|
|
|
|
|
|
|
public DingDingWorkNoticeHandler() {
|
|
|
|
public DingDingWorkNoticeHandler() {
|
|
|
|
channelCode = ChannelType.DING_DING_WORK_NOTICE.getCode();
|
|
|
|
channelCode = ChannelType.DING_DING_WORK_NOTICE.getCode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final String URL = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2";
|
|
|
|
private static final String SEND_URL = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2";
|
|
|
|
|
|
|
|
private static final String RECALL_URL = "https://oapi.dingtalk.com/topapi/message/corpconversation/recall";
|
|
|
|
private static final String DING_DING_RECALL_KEY_PREFIX = "RECALL_";
|
|
|
|
private static final String DING_DING_RECALL_KEY_PREFIX = "RECALL_";
|
|
|
|
|
|
|
|
private static final String RECALL_BIZ_TYPE = "DingDingWorkNoticeHandler#recall";
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean handler(TaskInfo taskInfo) {
|
|
|
|
public boolean handler(TaskInfo taskInfo) {
|
|
|
@ -59,13 +68,15 @@ public class DingDingWorkNoticeHandler extends BaseHandler implements Handler {
|
|
|
|
DingDingWorkNoticeAccount account = accountUtils.getAccount(taskInfo.getSendAccount(), SendAccountConstant.DING_DING_WORK_NOTICE_ACCOUNT_KEY, SendAccountConstant.DING_DING_WORK_NOTICE_PREFIX, DingDingWorkNoticeAccount.class);
|
|
|
|
DingDingWorkNoticeAccount account = accountUtils.getAccount(taskInfo.getSendAccount(), SendAccountConstant.DING_DING_WORK_NOTICE_ACCOUNT_KEY, SendAccountConstant.DING_DING_WORK_NOTICE_PREFIX, DingDingWorkNoticeAccount.class);
|
|
|
|
OapiMessageCorpconversationAsyncsendV2Request request = assembleParam(account, taskInfo);
|
|
|
|
OapiMessageCorpconversationAsyncsendV2Request request = assembleParam(account, taskInfo);
|
|
|
|
String accessToken = redisTemplate.opsForValue().get(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + taskInfo.getSendAccount());
|
|
|
|
String accessToken = redisTemplate.opsForValue().get(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + taskInfo.getSendAccount());
|
|
|
|
OapiMessageCorpconversationAsyncsendV2Response response = new DefaultDingTalkClient(URL).execute(request, accessToken);
|
|
|
|
OapiMessageCorpconversationAsyncsendV2Response response = new DefaultDingTalkClient(SEND_URL).execute(request, accessToken);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 发送成功后记录TaskId,用于消息撤回(支持当天的)
|
|
|
|
if (response.getErrcode() == 0) {
|
|
|
|
if (response.getErrcode() == 0) {
|
|
|
|
// 用于消息撤回(支持当天的)
|
|
|
|
|
|
|
|
redisTemplate.opsForList().leftPush(DING_DING_RECALL_KEY_PREFIX + taskInfo.getMessageTemplateId(), String.valueOf(response.getTaskId()));
|
|
|
|
redisTemplate.opsForList().leftPush(DING_DING_RECALL_KEY_PREFIX + taskInfo.getMessageTemplateId(), String.valueOf(response.getTaskId()));
|
|
|
|
redisTemplate.expire(DING_DING_RECALL_KEY_PREFIX + taskInfo.getMessageTemplateId(), (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000, TimeUnit.SECONDS);
|
|
|
|
redisTemplate.expire(DING_DING_RECALL_KEY_PREFIX + taskInfo.getMessageTemplateId(), (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000, TimeUnit.SECONDS);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 常见的错误 应当 关联至 AnchorState,由austin后台统一透出失败原因
|
|
|
|
// 常见的错误 应当 关联至 AnchorState,由austin后台统一透出失败原因
|
|
|
|
log.error("DingDingWorkNoticeHandler#handler fail!result:{},params:{}", JSON.toJSONString(response), JSON.toJSONString(taskInfo));
|
|
|
|
log.error("DingDingWorkNoticeHandler#handler fail!result:{},params:{}", JSON.toJSONString(response), JSON.toJSONString(taskInfo));
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
@ -156,5 +167,33 @@ public class DingDingWorkNoticeHandler extends BaseHandler implements Handler {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return req;
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 在下发的时候存储了messageTemplate -> taskIdList
|
|
|
|
|
|
|
|
* 只要还存在taskIdList,则将其去除
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param messageTemplate
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void recall(MessageTemplate messageTemplate) {
|
|
|
|
|
|
|
|
SupportThreadPoolConfig.getPendingSingleThreadPool().execute(() -> {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
DingDingWorkNoticeAccount account = accountUtils.getAccount(messageTemplate.getSendAccount(), SendAccountConstant.DING_DING_WORK_NOTICE_ACCOUNT_KEY, SendAccountConstant.DING_DING_WORK_NOTICE_PREFIX, DingDingWorkNoticeAccount.class);
|
|
|
|
|
|
|
|
String accessToken = redisTemplate.opsForValue().get(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + messageTemplate.getSendAccount());
|
|
|
|
|
|
|
|
while (redisTemplate.opsForList().size(DING_DING_RECALL_KEY_PREFIX + messageTemplate.getId()) > 0) {
|
|
|
|
|
|
|
|
String taskId = redisTemplate.opsForList().leftPop(DING_DING_RECALL_KEY_PREFIX + messageTemplate.getId());
|
|
|
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient(RECALL_URL);
|
|
|
|
|
|
|
|
OapiMessageCorpconversationRecallRequest req = new OapiMessageCorpconversationRecallRequest();
|
|
|
|
|
|
|
|
req.setAgentId(Long.valueOf(account.getAgentId()));
|
|
|
|
|
|
|
|
req.setMsgTaskId(Long.valueOf(taskId));
|
|
|
|
|
|
|
|
OapiMessageCorpconversationRecallResponse rsp = client.execute(req, accessToken);
|
|
|
|
|
|
|
|
logUtils.print(LogParam.builder().bizType(RECALL_BIZ_TYPE).object(JSON.toJSONString(rsp)).build());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
log.error("DingDingWorkNoticeHandler#recall fail:{}", Throwables.getStackTraceAsString(e));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|