perf:钉钉对接调整
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
@@ -15,7 +16,10 @@ import com.tiesheng.util.service.TsCacheService;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@@ -57,18 +61,22 @@ public class PlatformDingConfig {
|
||||
* @return
|
||||
*/
|
||||
public <T> DingResponse<T> doRequest(String service, String url, JSONObject body, TypeReference<DingResponse<T>> typeReference) {
|
||||
|
||||
String accessToken = getAccessToken(service);
|
||||
if (StrUtil.contains(url, "?")) {
|
||||
url = url + "&access_token=" + getAccessToken(service);
|
||||
url = url + "&access_token=" + accessToken;
|
||||
} else {
|
||||
url = url + "?access_token=" + getAccessToken(service);
|
||||
url = url + "?access_token=" + accessToken;
|
||||
}
|
||||
|
||||
HttpResponse execute;
|
||||
HttpRequest request;
|
||||
if (body == null) {
|
||||
execute = HttpUtil.createGet(url).execute();
|
||||
request = HttpUtil.createGet(url);
|
||||
} else {
|
||||
execute = HttpUtil.createPost(url).body(body.toString()).execute();
|
||||
request = HttpUtil.createPost(url).body(body.toString());
|
||||
}
|
||||
request.header("x-acs-dingtalk-access-token", accessToken);
|
||||
HttpResponse execute = request.execute();
|
||||
|
||||
if (execute.isOk()) {
|
||||
DingResponse<T> bean = JSONUtil.toBean(execute.body(), typeReference, true);
|
||||
@@ -264,7 +272,8 @@ public class PlatformDingConfig {
|
||||
* 发送工作通知
|
||||
*
|
||||
* @param service
|
||||
* @param content
|
||||
* @param title
|
||||
* @param markdown
|
||||
* @param actionUrl
|
||||
* @param userIds
|
||||
* @return
|
||||
@@ -280,8 +289,11 @@ public class PlatformDingConfig {
|
||||
JSONObject actionCard = new JSONObject();
|
||||
actionCard.set("title", title);
|
||||
actionCard.set("markdown", markdown);
|
||||
actionCard.set("single_title", "点击查看");
|
||||
actionCard.set("single_url", actionUrl);
|
||||
|
||||
if (StrUtil.isNotEmpty(actionUrl)) {
|
||||
actionCard.set("single_title", "点击查看");
|
||||
actionCard.set("single_url", actionUrl);
|
||||
}
|
||||
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.set("msgtype", "action_card");
|
||||
|
||||
@@ -7,6 +7,8 @@ public class DingResponse<T> {
|
||||
private String errcode;
|
||||
private String errmsg;
|
||||
private String ticket;
|
||||
private String taskId;
|
||||
private String requestId;
|
||||
private Long expiresIn;
|
||||
private T result;
|
||||
|
||||
@@ -61,4 +63,20 @@ public class DingResponse<T> {
|
||||
public void setExpiresIn(Long expiresIn) {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void setTaskId(String taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public String getRequestId() {
|
||||
return requestId;
|
||||
}
|
||||
|
||||
public void setRequestId(String requestId) {
|
||||
this.requestId = requestId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user