3 changed files with 123 additions and 3 deletions
Split View
Diff Options
-
6dating-agency-mall-server/pom.xml
-
23dating-agency-mall-server/src/main/java/com/qniao/dam/api/query/order/user/OrderUserQueryController.java
-
97dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/utils/DingTalkWarningUtil.java
@ -0,0 +1,97 @@ |
|||
package com.qniao.dam.infrastructure.utils; |
|||
|
|||
import cn.hutool.http.HttpUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.dingtalk.api.DefaultDingTalkClient; |
|||
import com.dingtalk.api.DingTalkClient; |
|||
import com.dingtalk.api.request.OapiRobotSendRequest; |
|||
import com.taobao.api.ApiException; |
|||
import com.taobao.api.TaobaoResponse; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
public class DingTalkWarningUtil { |
|||
|
|||
@Value("${payment-order-paid-dingTalk-token}") |
|||
private String paymentOrderPaidToken; |
|||
private static Integer contextSize = 600; |
|||
|
|||
private final static String dingTalkUrl = "https://oapi.dingtalk.com/robot/send?access_token="; |
|||
|
|||
/** |
|||
* 发送钉钉报错信息 |
|||
* |
|||
* @param data 数据 |
|||
* @return |
|||
*/ |
|||
public static boolean send(String accessToken, Map<String, String> data) { |
|||
OapiRobotSendRequest request = new OapiRobotSendRequest(); |
|||
if (data.containsKey("Msgtype")) { |
|||
request.setMsgtype(data.get("Msgtype")); |
|||
} else { |
|||
request.setMsgtype("text"); |
|||
|
|||
} |
|||
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text(); |
|||
String content = ""; |
|||
|
|||
if (data.containsKey("time")) { |
|||
content = content + data.get("time"); |
|||
} |
|||
if (data.containsKey("traceId")) { |
|||
content = content + "[" + data.get("traceId") + "]"; |
|||
} |
|||
if (data.containsKey("requestUri")) { |
|||
content = content + "[" + data.get("requestUri") + "]"; |
|||
} |
|||
|
|||
if (data.containsKey("content")) { |
|||
content = content + data.get("content"); |
|||
} |
|||
Integer csize = contextSize; |
|||
if (data.containsKey("contextSize")) { |
|||
csize = Integer.parseInt(data.get("contextSize")); |
|||
} |
|||
if (content.length() > csize) { |
|||
content = content.substring(0, csize); |
|||
} |
|||
log.info(content); |
|||
if (data.containsKey("Msgtype") && data.get("Msgtype").equals("markdown")) { |
|||
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown(); |
|||
markdown.setTitle(data.get("toastType")); |
|||
if (data.containsKey("RemindUser")) { |
|||
content = "@" + data.get("RemindUser") + " <br>" + content; |
|||
} |
|||
markdown.setText(content); |
|||
request.setMarkdown(markdown); |
|||
} else { |
|||
if (data.containsKey("toastType")) { |
|||
content = data.get("toastType") + content; |
|||
} |
|||
text.setContent(content); |
|||
request.setText(text); |
|||
} |
|||
try { |
|||
TaobaoResponse response = getTalkClient(accessToken).execute(request); |
|||
if (response.getErrorCode() != null && !response.getErrorCode().equals("0")) { |
|||
log.error("DingTalk接口异常", response); |
|||
return false; |
|||
} |
|||
} catch (ApiException e) { |
|||
log.error("DingTalk接口异常", e); |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
private static DingTalkClient getTalkClient(String accessToken) { |
|||
return StringUtils.isNotBlank(accessToken) ? new DefaultDingTalkClient(dingTalkUrl + accessToken) : null; |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save