|
|
@ -1,6 +1,10 @@ |
|
|
|
package com.epmet.commons.tools.utils; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.dingtalk.api.DefaultDingTalkClient; |
|
|
|
import com.dingtalk.api.DingTalkClient; |
|
|
|
import com.dingtalk.api.request.OapiRobotSendRequest; |
|
|
|
import com.epmet.commons.tools.constant.DingDingRobotConstant; |
|
|
|
import com.epmet.commons.tools.dto.form.DingTalkTextMsg; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import org.apache.commons.codec.binary.Base64; |
|
|
@ -49,7 +53,8 @@ public class DingdingMsgSender { |
|
|
|
//阻塞取元素
|
|
|
|
msg = msgQueue.take(); |
|
|
|
if (msg != null) { |
|
|
|
sendMsg(msg); |
|
|
|
//sendMsg(msg);
|
|
|
|
sendMsgSdk(msg); |
|
|
|
} else { |
|
|
|
Thread.sleep(1000); |
|
|
|
} |
|
|
@ -82,7 +87,7 @@ public class DingdingMsgSender { |
|
|
|
DingTalkTextMsg param = new DingTalkTextMsg(); |
|
|
|
param.setContent("待发送消息队列已满,当前队列个数" + msgQueue.size() + "\n" + "最新消息内容:" + JSON.toJSONString(messageParam)); |
|
|
|
param.setWebHook(messageParam.getWebHook()); |
|
|
|
sendMsg(param); |
|
|
|
sendMsgSdk(param); |
|
|
|
} |
|
|
|
return flag; |
|
|
|
} |
|
|
@ -121,6 +126,7 @@ public class DingdingMsgSender { |
|
|
|
* @param param 请求参数,JSON格式 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Deprecated |
|
|
|
private Result<String> sendMsg(DingTalkTextMsg param) { |
|
|
|
if (StringUtils.isBlank(param.getWebHook())) { |
|
|
|
param.setWebHook(webHook); |
|
|
@ -146,6 +152,34 @@ public class DingdingMsgSender { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 发送POST 请求 |
|
|
|
* |
|
|
|
* @param param 请求参数,JSON格式 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private Result<String> sendMsgSdk(DingTalkTextMsg param) { |
|
|
|
if (StringUtils.isBlank(param.getWebHook())) { |
|
|
|
param.setWebHook(webHook); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(param.getSecret())) { |
|
|
|
param.setSecret(secret); |
|
|
|
} |
|
|
|
Result<String> result = new Result<String>().error(); |
|
|
|
try { |
|
|
|
DingTalkClient client = new DefaultDingTalkClient(StringUtils.isBlank(webHook) ? DingDingRobotConstant.DEPLOY_ROBOT : webHook); |
|
|
|
OapiRobotSendRequest request = new OapiRobotSendRequest(); |
|
|
|
request.setMsgtype("text"); |
|
|
|
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text(); |
|
|
|
text.setContent("sdk"+param.getContent()); |
|
|
|
request.setText(text); |
|
|
|
client.execute(request); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.warn("sendPostByJSON error", e); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
for (int i = 0; i < 50; i++) { |
|
|
|
|
|
|
|