From c5754972295d087c6db18acb1d17f40757239df8 Mon Sep 17 00:00:00 2001 From: huhangtao Date: Tue, 13 Aug 2024 10:25:10 +0800 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=94=E5=9B=9E=E6=B6=88=E6=81=AFID=20+=20?= =?UTF-8?q?GifMessage=20=E6=B7=BB=E5=8A=A0=20extra=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +-- pom.xml | 2 +- .../java/io/rong/messages/GifMessage.java | 12 +++- .../methods/message/_private/Private.java | 42 ++++++------- .../methods/message/chatroom/Chatroom.java | 12 ++-- .../io/rong/methods/message/group/Group.java | 53 ++++++++-------- .../methods/message/system/MsgSystem.java | 43 ++++++------- .../message/ultragroup/UltraGroup.java | 11 ++-- .../rong/models/response/BroadcastResult.java | 36 +++++++++++ .../rong/models/response/MessageResult.java | 37 ++++++++++++ .../rong/models/response/MessageUIDEntry.java | 60 +++++++++++++++++++ .../io/rong/models/response/PushResult.java | 14 +++++ src/test/java/io/rong/example/Example.java | 15 +++-- .../java/io/rong/messages/GifMessageTest.java | 21 +++++++ 14 files changed, 274 insertions(+), 91 deletions(-) create mode 100644 src/main/java/io/rong/models/response/BroadcastResult.java create mode 100644 src/main/java/io/rong/models/response/MessageResult.java create mode 100644 src/main/java/io/rong/models/response/MessageUIDEntry.java create mode 100644 src/test/java/io/rong/messages/GifMessageTest.java diff --git a/README.md b/README.md index 7816d6c7..ccc59f97 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,12 @@ RongCloud IM Server SDK in Java. cn.rongcloud.im server-sdk-java - 3.4.2 + 3.5.0 ``` * Gradle ``` - compile group: 'cn.rongcloud.im', name: 'server-sdk-java', version: '3.4.2' + compile group: 'cn.rongcloud.im', name: 'server-sdk-java', version: '3.5.0' ``` * 基于源码 Meavn 打包构建 @@ -85,5 +85,4 @@ RongCloud IM Server SDK in Java. # 版本说明 -为方便开发者的接入使用,更好的对融云 Server SDK 进行维护管理,现更新SDK 3.0 版本,老版本的 Server SDK仍可使用 -但不兼容。 +为方便开发者的接入使用,更好的对融云 Server SDK 进行维护管理,现更新SDK 3.5.0 版本,老版本的 Server SDK仍可使用,但不支持发送消息返回消息ID。 diff --git a/pom.xml b/pom.xml index 888a5a0d..a25dc199 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.rongcloud.im server-sdk-java - 3.4.2 + 3.5.0 jar RongCloud IM Server SDK diff --git a/src/main/java/io/rong/messages/GifMessage.java b/src/main/java/io/rong/messages/GifMessage.java index 07c2080b..5a5a323d 100644 --- a/src/main/java/io/rong/messages/GifMessage.java +++ b/src/main/java/io/rong/messages/GifMessage.java @@ -34,7 +34,9 @@ public class GifMessage extends BaseMessage { */ private Integer width = 0; private UserInfo user = null; - private transient static final String TYPE = "RC:GIFMsg"; + + private String extra; + private static final String TYPE = "RC:GIFMsg"; public GifMessage(String localPath, String remoteUrl, Integer gifDataSize, Integer height, Integer width) { this.localPath = localPath; @@ -109,6 +111,14 @@ public void setUser(UserInfo user) { this.user = user; } + public String getExtra() { + return extra; + } + + public void setExtra(String extra) { + this.extra = extra; + } + @Override public String getType() { return TYPE; diff --git a/src/main/java/io/rong/methods/message/_private/Private.java b/src/main/java/io/rong/methods/message/_private/Private.java index fe6b15b4..53a209a3 100644 --- a/src/main/java/io/rong/methods/message/_private/Private.java +++ b/src/main/java/io/rong/methods/message/_private/Private.java @@ -8,6 +8,7 @@ import java.util.Map; import com.google.gson.JsonParseException; +import io.rong.models.response.MessageResult; import org.apache.commons.lang3.StringUtils; import io.rong.RongCloud; @@ -23,7 +24,6 @@ import io.rong.util.GsonUtil; import io.rong.util.HttpUtil; import com.alibaba.fastjson.JSONException; -import com.google.gson.JsonSyntaxException; /** * 发送单聊消息方法 @@ -61,10 +61,10 @@ public Private(String appKey, String appSecret) { * @return ResponseResult * @throws Exception **/ - public ResponseResult send(PrivateMessage message) throws Exception { + public MessageResult send(PrivateMessage message) throws Exception { String errMsg = CommonUtil.checkFiled(message, PATH, CheckMethod.SEND); if (null != errMsg) { - return (ResponseResult) GsonUtil.fromJson(errMsg, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(errMsg, MessageResult.class); } StringBuilder sb = new StringBuilder(); @@ -135,14 +135,14 @@ public ResponseResult send(PrivateMessage message) throws Exception { HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/private/publish.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; @@ -155,11 +155,11 @@ public ResponseResult send(PrivateMessage message) throws Exception { * @return ResponseResult * @throws Exception **/ - public ResponseResult sendTemplate(TemplateMessage message) throws Exception { + public MessageResult sendTemplate(TemplateMessage message) throws Exception { String errMsg = CommonUtil.checkFiled(message, PATH, CheckMethod.SENDTEMPLATE); if (null != errMsg) { - return (ResponseResult) GsonUtil.fromJson(errMsg, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(errMsg, MessageResult.class); } Templates templateMessage = new Templates(); @@ -194,14 +194,14 @@ public ResponseResult sendTemplate(TemplateMessage message) throws Exception { HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/private/publish_template.json", "application/json"); HttpUtil.setBodyParameter(templateMessage.toString(), conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISHTEMPLATE, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISHTEMPLATE, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(templateMessage.toString()); return result; @@ -267,10 +267,10 @@ public Result recall(RecallMessage message) throws Exception { * @return * @throws Exception */ - public ResponseResult sendStatusMessage(PrivateStatusMessage message) throws Exception { + public MessageResult sendStatusMessage(PrivateStatusMessage message) throws Exception { String errMsg = CommonUtil.checkFiled(message, PATH, CheckMethod.SENDSTATUS); if (null != errMsg) { - return (ResponseResult) GsonUtil.fromJson(errMsg, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(errMsg, MessageResult.class); } StringBuilder sb = new StringBuilder(); @@ -306,14 +306,14 @@ public ResponseResult sendStatusMessage(PrivateStatusMessage message) throws Exc HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/statusmessage/private/publish.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.SENDSTATUS, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.SENDSTATUS, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; @@ -326,10 +326,10 @@ public ResponseResult sendStatusMessage(PrivateStatusMessage message) throws Exc * @return * @throws Exception */ - public ResponseResult sendTypingStatusMessage(PrivateMessage message) throws Exception { + public MessageResult sendTypingStatusMessage(PrivateMessage message) throws Exception { String errMsg = CommonUtil.checkFiled(message, PATH, CheckMethod.SEND); if (null != errMsg) { - return (ResponseResult) GsonUtil.fromJson(errMsg, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(errMsg, MessageResult.class); } StringBuilder sb = new StringBuilder(); @@ -356,14 +356,14 @@ public ResponseResult sendTypingStatusMessage(PrivateMessage message) throws Exc HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/private/publish.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; diff --git a/src/main/java/io/rong/methods/message/chatroom/Chatroom.java b/src/main/java/io/rong/methods/message/chatroom/Chatroom.java index 39bc3df2..e8f7dce6 100644 --- a/src/main/java/io/rong/methods/message/chatroom/Chatroom.java +++ b/src/main/java/io/rong/methods/message/chatroom/Chatroom.java @@ -5,6 +5,7 @@ import io.rong.models.CheckMethod; import io.rong.models.Result; import io.rong.models.message.RecallMessage; +import io.rong.models.response.MessageResult; import io.rong.models.response.ResponseResult; import io.rong.models.message.ChatroomMessage; import io.rong.util.CommonUtil; @@ -15,7 +16,6 @@ import java.net.URLEncoder; import com.alibaba.fastjson.JSONException; -import com.google.gson.JsonSyntaxException; /** * 发送聊天室消息方法 @@ -52,11 +52,11 @@ public Chatroom(String appKey, String appSecret) { * @return ResponseResult * @throws Exception **/ - public ResponseResult send(ChatroomMessage message) throws Exception { + public MessageResult send(ChatroomMessage message) throws Exception { String code = CommonUtil.checkFiled(message, PATH, CheckMethod.SEND); if (null != code) { - return (ResponseResult) GsonUtil.fromJson(code, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(code, MessageResult.class); } StringBuilder sb = new StringBuilder(); sb.append("&fromUserId=").append(URLEncoder.encode(message.getSenderId(), UTF8)); @@ -90,14 +90,14 @@ public ResponseResult send(ChatroomMessage message) throws Exception { HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/chatroom/publish.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; diff --git a/src/main/java/io/rong/methods/message/group/Group.java b/src/main/java/io/rong/methods/message/group/Group.java index 826e4baa..fb663fd5 100644 --- a/src/main/java/io/rong/methods/message/group/Group.java +++ b/src/main/java/io/rong/methods/message/group/Group.java @@ -7,6 +7,7 @@ import io.rong.models.Result; import io.rong.models.message.MentionMessage; import io.rong.models.message.RecallMessage; +import io.rong.models.response.MessageResult; import io.rong.models.response.ResponseResult; import io.rong.models.message.GroupMessage; import io.rong.models.message.GroupStatusMessage; @@ -19,7 +20,6 @@ import org.apache.commons.lang3.StringUtils; import com.alibaba.fastjson.JSONException; -import com.google.gson.JsonSyntaxException; /** * 发送群组消息方法 @@ -58,11 +58,11 @@ public Group(String appKey, String appSecret) { * @return ResponseResult * @throws Exception **/ - public ResponseResult send(GroupMessage message) throws Exception { + public MessageResult send(GroupMessage message) throws Exception { String code = CommonUtil.checkFiled(message, PATH, CheckMethod.PUBLISH); if (null != code) { - return (ResponseResult) GsonUtil.fromJson(code, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(code, MessageResult.class); } StringBuilder sb = new StringBuilder(); sb.append("&fromUserId=").append(URLEncoder.encode(message.getSenderId().toString(), UTF8)); @@ -93,9 +93,6 @@ public ResponseResult send(GroupMessage message) throws Exception { sb.append("&isPersisted=").append(URLEncoder.encode(message.getIsPersisted().toString(), UTF8)); } - /*if (message.getIsCounted() != null) { - sb.append("&isCounted=").append(URLEncoder.encode(message.getIsCounted().toString(), UTF8)); - }*/ if (message.getIsIncludeSender() != null) { sb.append("&isIncludeSender=").append(URLEncoder.encode(message.getIsIncludeSender().toString(), UTF8)); @@ -124,14 +121,14 @@ public ResponseResult send(GroupMessage message) throws Exception { HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/group/publish.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; @@ -144,17 +141,17 @@ public ResponseResult send(GroupMessage message) throws Exception { * @return ResponseResult * @throws Exception **/ - public ResponseResult sendMention(MentionMessage message) throws Exception { + public MessageResult sendMention(MentionMessage message) throws Exception { String code = CommonUtil.checkFiled(message, PATH, CheckMethod.SEND_MENTION); if (null != code) { - return (ResponseResult) GsonUtil.fromJson(code, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(code, MessageResult.class); } if (null == message.getContent().getMentionedInfo()) { - return new ResponseResult(1002, "mentionedInfo 参数为必传项"); + return new MessageResult(1002, "mentionedInfo 参数为必传项"); } if (null == message.getContent().getContent()) { - return new ResponseResult(1002, "MentionMessageContent.content 参数为必传项"); + return new MessageResult(1002, "MentionMessageContent.content 参数为必传项"); } StringBuilder sb = new StringBuilder(); sb.append("&fromUserId=").append(URLEncoder.encode(message.getSenderId().toString(), UTF8)); @@ -207,14 +204,14 @@ public ResponseResult sendMention(MentionMessage message) throws Exception { HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/group/publish.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; @@ -227,17 +224,17 @@ public ResponseResult sendMention(MentionMessage message) throws Exception { * @return ResponseResult * @throws Exception **/ - public ResponseResult sendDirection(GroupMessage message) throws Exception { + public MessageResult sendDirection(GroupMessage message) throws Exception { String code = CommonUtil.checkFiled(message, PATH, CheckMethod.PUBLISH); if (null != code) { - return (ResponseResult) GsonUtil.fromJson(code, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(code, MessageResult.class); } if (message.getTargetId().length > 1) { - return new ResponseResult(20005, "群定向消息当群组 Id 为一个时有效 "); + return new MessageResult(20005, "群定向消息当群组 Id 为一个时有效 "); } if (null == message.getToUserId() && message.getToUserId().length < 1) { - return new ResponseResult(20005, "toUserId 必传 "); + return new MessageResult(20005, "toUserId 必传 "); } StringBuilder sb = new StringBuilder(); sb.append("&fromUserId=").append(URLEncoder.encode(message.getSenderId().toString(), UTF8)); @@ -295,14 +292,14 @@ public ResponseResult sendDirection(GroupMessage message) throws Exception { HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/group/publish.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; @@ -363,10 +360,10 @@ public ResponseResult recall(RecallMessage message) throws Exception { * @return * @throws Exception */ - public ResponseResult sendStatusMessage(GroupStatusMessage message) throws Exception { + public MessageResult sendStatusMessage(GroupStatusMessage message) throws Exception { String errMsg = CommonUtil.checkFiled(message, PATH, CheckMethod.SENDGROUPSTATUS); if (null != errMsg) { - return (ResponseResult) GsonUtil.fromJson(errMsg, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(errMsg, MessageResult.class); } StringBuilder sb = new StringBuilder(); @@ -401,14 +398,14 @@ public ResponseResult sendStatusMessage(GroupStatusMessage message) throws Excep HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/statusmessage/group/publish.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.SENDGROUPSTATUS, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.SENDGROUPSTATUS, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; diff --git a/src/main/java/io/rong/methods/message/system/MsgSystem.java b/src/main/java/io/rong/methods/message/system/MsgSystem.java index 0785436e..a036ad64 100644 --- a/src/main/java/io/rong/methods/message/system/MsgSystem.java +++ b/src/main/java/io/rong/methods/message/system/MsgSystem.java @@ -5,6 +5,8 @@ import io.rong.models.CheckMethod; import io.rong.models.Result; import io.rong.models.message.*; +import io.rong.models.response.BroadcastResult; +import io.rong.models.response.MessageResult; import io.rong.models.response.ResponseResult; import io.rong.models.Templates; import io.rong.util.CommonUtil; @@ -20,6 +22,7 @@ import com.alibaba.fastjson.JSONException; + /** * 发送系统消息方法 *

@@ -56,11 +59,11 @@ public MsgSystem(String appKey, String appSecret) { * @return ResponseResult * @throws Exception **/ - public ResponseResult send(MessageModel message) throws Exception { + public MessageResult send(MessageModel message) throws Exception { SystemMessage systemMessage = (SystemMessage) message; String code = CommonUtil.checkFiled(systemMessage, PATH, CheckMethod.PUBLISH); if (null != code) { - return (ResponseResult) GsonUtil.fromJson(code, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(code, MessageResult.class); } StringBuilder sb = new StringBuilder(); sb.append("&fromUserId=").append(URLEncoder.encode(systemMessage.getSenderId().toString(), UTF8)); @@ -113,14 +116,14 @@ public ResponseResult send(MessageModel message) throws Exception { HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/system/publish.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; @@ -187,11 +190,11 @@ public Result recall(RecallMessage message) throws Exception { * @return ResponseResult * @throws Exception **/ - public ResponseResult sendTemplate(TemplateMessage template) throws Exception { + public MessageResult sendTemplate(TemplateMessage template) throws Exception { String code = CommonUtil.checkFiled(template, PATH, CheckMethod.PUBLISHTEMPLATE); if (null != code) { - return (ResponseResult) GsonUtil.fromJson(code, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(code, MessageResult.class); } Templates templateMessage = new Templates(); @@ -219,14 +222,14 @@ public ResponseResult sendTemplate(TemplateMessage template) throws Exception { HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/system/publish_template.json", "application/json"); HttpUtil.setBodyParameter(templateMessage.toString(), conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISHTEMPLATE, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISHTEMPLATE, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(templateMessage.toString()); return result; @@ -241,11 +244,11 @@ public ResponseResult sendTemplate(TemplateMessage template) throws Exception { * @return ResponseResult * @throws Exception **/ - public ResponseResult broadcast(BroadcastMessage message) throws Exception { + public BroadcastResult broadcast(BroadcastMessage message) throws Exception { String errMsg = CommonUtil.checkFiled(message, PATH, CheckMethod.BROADCAST); if (null != errMsg) { - return (ResponseResult) GsonUtil.fromJson(errMsg, ResponseResult.class); + return (BroadcastResult) GsonUtil.fromJson(errMsg, BroadcastResult.class); } StringBuilder sb = new StringBuilder(); sb.append("&fromUserId=").append(URLEncoder.encode(message.getSenderId().toString(), UTF8)); @@ -287,14 +290,14 @@ public ResponseResult broadcast(BroadcastMessage message) throws Exception { HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/broadcast.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + BroadcastResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.BROADCAST, response), ResponseResult.class); + result = (BroadcastResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.BROADCAST, response), BroadcastResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new BroadcastResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; @@ -310,11 +313,11 @@ public ResponseResult broadcast(BroadcastMessage message) throws Exception { * @return ResponseResult * @throws Exception **/ - public ResponseResult onlineBroadcast(BroadcastMessage message) throws Exception { + public BroadcastResult onlineBroadcast(BroadcastMessage message) throws Exception { String errMsg = CommonUtil.checkFiled(message, PATH, CheckMethod.ONLINE); if (null != errMsg) { - return (ResponseResult) GsonUtil.fromJson(errMsg, ResponseResult.class); + return (BroadcastResult) GsonUtil.fromJson(errMsg, BroadcastResult.class); } StringBuilder sb = new StringBuilder(); sb.append("&fromUserId=").append(URLEncoder.encode(message.getSenderId().toString(), UTF8)); @@ -331,14 +334,14 @@ public ResponseResult onlineBroadcast(BroadcastMessage message) throws Exception HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/online/broadcast.json", "application/x-www-form-urlencoded"); HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig()); - ResponseResult result = null; + BroadcastResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.ONLINE, response), ResponseResult.class); + result = (BroadcastResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.ONLINE, response), BroadcastResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new BroadcastResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(body); return result; diff --git a/src/main/java/io/rong/methods/message/ultragroup/UltraGroup.java b/src/main/java/io/rong/methods/message/ultragroup/UltraGroup.java index 6c3e85d8..f304fe08 100644 --- a/src/main/java/io/rong/methods/message/ultragroup/UltraGroup.java +++ b/src/main/java/io/rong/methods/message/ultragroup/UltraGroup.java @@ -6,6 +6,7 @@ import io.rong.RongCloud; import io.rong.models.CheckMethod; import io.rong.models.message.*; +import io.rong.models.response.MessageResult; import io.rong.models.response.ResponseResult; import io.rong.util.CommonUtil; import io.rong.util.GsonUtil; @@ -52,11 +53,11 @@ public UltraGroup(String appKey, String appSecret) { * @return ResponseResult * @throws Exception **/ - public ResponseResult send(UltraGroupMessage message) throws Exception { + public MessageResult send(UltraGroupMessage message) throws Exception { String code = CommonUtil.checkFiled(message, PATH, CheckMethod.PUBLISH); if (null != code) { - return (ResponseResult) GsonUtil.fromJson(code, ResponseResult.class); + return (MessageResult) GsonUtil.fromJson(code, MessageResult.class); } ConcurrentHashMap params = new ConcurrentHashMap(); params.put("fromUserId", message.getSenderId()); @@ -110,14 +111,14 @@ public ResponseResult send(UltraGroupMessage message) throws Exception { HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/message/ultragroup/publish.json", "application/json"); HttpUtil.setBodyParameter(GsonUtil.toJson(params), conn, rongCloud.getConfig()); - ResponseResult result = null; + MessageResult result = null; String response = ""; try { response = HttpUtil.returnResult(conn, rongCloud.getConfig()); - result = (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), ResponseResult.class); + result = (MessageResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH, CheckMethod.PUBLISH, response), MessageResult.class); } catch (JSONException | JsonParseException | IllegalStateException e) { rongCloud.getConfig().errorCounter.incrementAndGet(); - result = new ResponseResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); + result = new MessageResult(500, "request:" + conn.getURL() + " ,response:" + response + " ,JSONException:" + e.getMessage()); } result.setReqBody(GsonUtil.toJson(params)); return result; diff --git a/src/main/java/io/rong/models/response/BroadcastResult.java b/src/main/java/io/rong/models/response/BroadcastResult.java new file mode 100644 index 00000000..3a8f3fc7 --- /dev/null +++ b/src/main/java/io/rong/models/response/BroadcastResult.java @@ -0,0 +1,36 @@ +package io.rong.models.response; + +import io.rong.util.GsonUtil; + +/** + * push 返回结果 + */ +public class BroadcastResult extends ResponseResult { + + /** + * 广播消息ID。 + */ + private String messageUID; + + + public BroadcastResult(Integer code, String msg) { + super(code, msg); + } + + + public String getMessageUID() { + return messageUID; + } + + public BroadcastResult setMessageUID(String messageUID) { + this.messageUID = messageUID; + return this; + } + + @Override + public String toString() { + return GsonUtil.toJson(this, BroadcastResult.class); + } + + +} \ No newline at end of file diff --git a/src/main/java/io/rong/models/response/MessageResult.java b/src/main/java/io/rong/models/response/MessageResult.java new file mode 100644 index 00000000..16e48a91 --- /dev/null +++ b/src/main/java/io/rong/models/response/MessageResult.java @@ -0,0 +1,37 @@ +package io.rong.models.response; + +import io.rong.util.GsonUtil; + +import java.util.List; + +/** + * push 返回结果 + */ +public class MessageResult extends ResponseResult { + + /** + * 单聊、群聊、聊天室、超级群消息ID列表, + */ + private List messageUIDs; + + public MessageResult(Integer code, String errorMessage) { + super(code, errorMessage); + } + + + public List getMessageUIDs() { + return messageUIDs; + } + + public MessageResult setMessageUIDs(List messageUIDs) { + this.messageUIDs = messageUIDs; + return this; + } + + @Override + public String toString() { + return GsonUtil.toJson(this, MessageResult.class); + } + + +} \ No newline at end of file diff --git a/src/main/java/io/rong/models/response/MessageUIDEntry.java b/src/main/java/io/rong/models/response/MessageUIDEntry.java new file mode 100644 index 00000000..c0eb3265 --- /dev/null +++ b/src/main/java/io/rong/models/response/MessageUIDEntry.java @@ -0,0 +1,60 @@ +package io.rong.models.response; + +/** + * @author huhangtao + * @date 2024/8/8 14:54 + */ +public class MessageUIDEntry { + /** + * 发送单聊消息有值 + */ + private String userId; + /** + * 发送群/超级群消息有值 + */ + private String groupId; + /** + * 发送聊天室消息有值 + */ + private String chatroomId; + /** + * 消息 ID + */ + private String messageUID; + + public String getUserId() { + return userId; + } + + public MessageUIDEntry setUserId(String userId) { + this.userId = userId; + return this; + } + + public String getGroupId() { + return groupId; + } + + public MessageUIDEntry setGroupId(String groupId) { + this.groupId = groupId; + return this; + } + + public String getChatroomId() { + return chatroomId; + } + + public MessageUIDEntry setChatroomId(String chatroomId) { + this.chatroomId = chatroomId; + return this; + } + + public String getMessageUID() { + return messageUID; + } + + public MessageUIDEntry setMessageUID(String messageUID) { + this.messageUID = messageUID; + return this; + } +} diff --git a/src/main/java/io/rong/models/response/PushResult.java b/src/main/java/io/rong/models/response/PushResult.java index 9c6bd0c2..66f596e7 100644 --- a/src/main/java/io/rong/models/response/PushResult.java +++ b/src/main/java/io/rong/models/response/PushResult.java @@ -13,6 +13,11 @@ public class PushResult extends Result { */ private String id; + /** + * 推送消息ID + */ + private String messageUID; + private String reqBody; public String getId() { @@ -38,6 +43,15 @@ public PushResult(Integer code, String id) { this.id = id; } + public String getMessageUID() { + return messageUID; + } + + public PushResult setMessageUID(String messageUID) { + this.messageUID = messageUID; + return this; + } + @Override public String toString() { return GsonUtil.toJson(this, PushResult.class); diff --git a/src/test/java/io/rong/example/Example.java b/src/test/java/io/rong/example/Example.java index 10f9e873..fa2ff22a 100644 --- a/src/test/java/io/rong/example/Example.java +++ b/src/test/java/io/rong/example/Example.java @@ -528,11 +528,12 @@ public void testSendPrivateTemplate() throws Exception { Example.class.getClassLoader().getResourceAsStream("jsonsource/message/TemplateMessage.json"))); TemplateMessage template = (TemplateMessage) GsonUtil.fromJson(reader, TemplateMessage.class); System.out.println(template.toString()); - ResponseResult messagePublishTemplateResult = rongCloud.message.msgPrivate.sendTemplate(template); + MessageResult messagePublishTemplateResult = rongCloud.message.msgPrivate.sendTemplate(template); System.out.println("sendPrivateTemplate: " + messagePublishTemplateResult.toString()); - assertEquals("200", messagePublishTemplateResult.getCode().toString()); - + for (MessageUIDEntry entry : messagePublishTemplateResult.getMessageUIDs()) { + System.out.println(entry.getUserId() + ":" + entry.getMessageUID()); + } } catch (Exception e) { e.printStackTrace(); } finally { @@ -564,10 +565,14 @@ public void testSendPrivate() throws Exception { .setIsIncludeSender(0); //发送单聊方法 - ResponseResult publishPrivateResult = rongCloud.message.msgPrivate.send(privateMessage); + MessageResult publishPrivateResult = rongCloud.message.msgPrivate.send(privateMessage); System.out.println("sendPrivate: " + publishPrivateResult.toString()); - assertEquals("200", publishPrivateResult.getCode().toString()); + + // 获取返回消息ID + for (MessageUIDEntry entry : publishPrivateResult.getMessageUIDs()) { + System.out.println("sendPrivate: " + entry.getMessageUID()); + } } /** diff --git a/src/test/java/io/rong/messages/GifMessageTest.java b/src/test/java/io/rong/messages/GifMessageTest.java new file mode 100644 index 00000000..99e3810f --- /dev/null +++ b/src/test/java/io/rong/messages/GifMessageTest.java @@ -0,0 +1,21 @@ +package io.rong.messages; + + +import io.rong.util.GsonUtil; +import org.junit.Assert; +import org.junit.Test; + + +/** + * @author huhangtao + * @date 2024/8/8 16:48 + */ +public class GifMessageTest { + + @Test + public void test() throws Exception { + GifMessage gifMessage = new GifMessage(null, null, null, null, null); + gifMessage.setExtra("ext"); + Assert.assertEquals("{\"extra\":\"ext\"}", GsonUtil.toJson(gifMessage)); + } +} \ No newline at end of file