publish 2.0.0.rc13

This commit is contained in:
曾文豪
2024-08-05 14:18:50 +08:00
parent 333d283e24
commit be08001f3f
12 changed files with 67 additions and 82 deletions

View File

@@ -6,6 +6,7 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.LogFactory;
import com.tiesheng.platform.config.ding.bean.*;
import com.tiesheng.util.exception.ApiException;
import com.tiesheng.util.service.TsCacheService;
@@ -15,7 +16,6 @@ import okhttp3.Response;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -78,13 +78,16 @@ public class PlatformDingConfig {
request.newBuilder().header("x-acs-dingtalk-access-token", accessToken);
try {
Response response = OkHttpUtil.ofHttpClient().build().newCall(request).execute();
if (response.isSuccessful() || response.body() != null) {
if (response.isSuccessful() && response.body() != null) {
String rawBody = response.body().string();
DingResponse<T> bean = JSONUtil.toBean(rawBody, typeReference, true);
bean.setRawBody(rawBody);
return bean;
} else {
LogFactory.get().info(response.body().string());
}
} catch (IOException ignored) {
} catch (Exception e) {
LogFactory.get().error(e);
}
return DingResponse.ofError();
@@ -279,6 +282,7 @@ public class PlatformDingConfig {
* @param actionUrl
* @param userIds
* @return
* @see <a href='https://open.dingtalk.com/document/orgapp/asynchronous-sending-of-enterprise-session-messages' </a>
*/
public DingResponse<String> messageNotification(String service, String title, String markdown, String actionUrl, List<String> userIds) {
@@ -288,18 +292,20 @@ public class PlatformDingConfig {
DingConfigBean configBean = getConfigBean(service);
JSONObject actionCard = new JSONObject();
actionCard.set("title", title);
actionCard.set("markdown", markdown);
if (StrUtil.isNotEmpty(actionUrl)) {
actionCard.set("single_title", "点击查看");
actionCard.set("single_url", actionUrl);
}
JSONObject msg = new JSONObject();
msg.set("msgtype", "action_card");
msg.set("action_card", actionCard);
if (StrUtil.isEmpty(actionUrl)) {
msg.set("msgtype", "markdown");
msg.set("markdown", JSONUtil.createObj()
.set("title", title).set("text", markdown)
);
} else {
msg.set("msgtype", "action_card");
msg.set("action_card", JSONUtil.createObj()
.set("title", title).set("markdown", markdown)
.set("single_title", "点击查看").set("single_url", actionUrl)
);
}
JSONObject body = new JSONObject();
body.putOpt("agent_id", configBean.getAgentId());