🐛 使用字符串拼接的 jsonString 消息在转为json的时候出现了一些异常,该异常由传入的字符串导致,改用 JSONObject 插入消息避免了该异常
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.hccake.extend.ding.talk.message;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.hccake.ballcat.common.core.markdown.MarkdownBuilder;
|
||||
import com.hccake.extend.ding.talk.enums.ActionBtnOrientationEnum;
|
||||
import com.hccake.extend.ding.talk.enums.MessageTypeEnum;
|
||||
@@ -62,24 +61,20 @@ public class DingTalkActionCardMessage extends AbstractDingTalkMessage {
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
// 头
|
||||
String jsonStr = "{\"actionCard\":{" +
|
||||
"\"title\":\"" + title + "\"," +
|
||||
"\"text\":\"" + text.build() + "\"," +
|
||||
"\"btnOrientation\":\"" + orientation.getVal() + "\",";
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("title", title);
|
||||
json.put("text", text.build());
|
||||
json.put("btnOrientation", orientation.getVal());
|
||||
|
||||
// 当 单按钮的 文本和链接都不为空时
|
||||
if (buttons.size() == 0) {
|
||||
jsonStr += "\"singleTitle\":\"" + singleTitle + "\"," +
|
||||
"\"singleURL\":\"" + singleUrl + "\",";
|
||||
json.put("singleTitle", singleTitle);
|
||||
json.put("singleURL", singleUrl);
|
||||
} else {
|
||||
// 否则使用自定义按钮组
|
||||
jsonStr += "\"btns\":" + JSONUtil.toJsonStr(buttons);
|
||||
json.put("btns", buttons);
|
||||
}
|
||||
|
||||
// 尾
|
||||
jsonStr += "}}";
|
||||
return JSONUtil.parseObj(jsonStr);
|
||||
return new JSONObject().put("actionCard", json);
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.hccake.extend.ding.talk.message;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.hccake.extend.ding.talk.enums.MessageTypeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -38,6 +37,13 @@ public class DingTalkLinkMessage extends AbstractDingTalkMessage {
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
return JSONUtil.parseObj("{\"link\":{\"text\":\"" + text + "\",\"title\":\"" + title + "\",\"picUrl\":\"" + picUrl + "\",\"messageUrl\":\"" + messageUrl + "\"}}");
|
||||
return new JSONObject().put(
|
||||
"link",
|
||||
new JSONObject()
|
||||
.put("text", text)
|
||||
.put("title", title)
|
||||
.put("picUrl", picUrl)
|
||||
.put("messageUrl", messageUrl)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.hccake.extend.ding.talk.message;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.hccake.ballcat.common.core.markdown.MarkdownBuilder;
|
||||
import com.hccake.extend.ding.talk.enums.MessageTypeEnum;
|
||||
import lombok.Getter;
|
||||
@@ -31,6 +30,11 @@ public class DingTalkMarkDownMessage extends AbstractDingTalkMessage {
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
return JSONUtil.parseObj("{\"markdown\":{\"title\":\"" + title + "\",\"text\":\"" + text.build() + "\"}}");
|
||||
return new JSONObject().put(
|
||||
"markdown",
|
||||
new JSONObject()
|
||||
.put("title", title)
|
||||
.put("text", text.build())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.hccake.extend.ding.talk.message;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.hccake.extend.ding.talk.enums.MessageTypeEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -26,6 +25,10 @@ public class DingTalkTextMessage extends AbstractDingTalkMessage {
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
return JSONUtil.parseObj("{\"text\":{\"content\":\"" + content + "\"}}");
|
||||
return new JSONObject().put(
|
||||
"text",
|
||||
new JSONObject()
|
||||
.put("content", content)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user