Skip to content

Commit

Permalink
[FEAT] 发送消息支持返回消息ID + GifMessage 添加 extra 字段
Browse files Browse the repository at this point in the history
  • Loading branch information
rchht committed Sep 19, 2024
1 parent c056f30 commit c575497
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 91 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ RongCloud IM Server SDK in Java.
<dependency>
<groupId>cn.rongcloud.im</groupId>
<artifactId>server-sdk-java</artifactId>
<version>3.4.2</version>
<version>3.5.0</version>
</dependency>
```
* 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 打包构建
Expand Down Expand Up @@ -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。
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.rongcloud.im</groupId>
<artifactId>server-sdk-java</artifactId>
<version>3.4.2</version>
<version>3.5.0</version>
<packaging>jar</packaging>

<name>RongCloud IM Server SDK</name>
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/io/rong/messages/GifMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/io/rong/methods/message/_private/Private.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +24,6 @@
import io.rong.util.GsonUtil;
import io.rong.util.HttpUtil;
import com.alibaba.fastjson.JSONException;
import com.google.gson.JsonSyntaxException;

/**
* 发送单聊消息方法
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/io/rong/methods/message/chatroom/Chatroom.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +16,6 @@
import java.net.URLEncoder;

import com.alibaba.fastjson.JSONException;
import com.google.gson.JsonSyntaxException;

/**
* 发送聊天室消息方法
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit c575497

Please sign in to comment.