Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1232abe39 | ||
|
|
1df192f730 | ||
|
|
f897e640fc | ||
|
|
ee6e4f96fb | ||
|
|
d14dc74566 | ||
|
|
ff75379779 | ||
|
|
b95a6b7785 | ||
|
|
5acb3044ac | ||
|
|
ae084063f4 | ||
|
|
cb3a82559d | ||
|
|
9191204bb0 | ||
|
|
6587a88ca9 | ||
|
|
86c1a2e140 | ||
|
|
83e9679339 | ||
|
|
dafb0cd4d9 | ||
|
|
cbcc8310c4 |
@@ -421,7 +421,10 @@ push.harmony.server.address http://localhost:8085/harmony/push
|
|||||||
## 内置文本敏感词过滤处理方法,当命中敏感词后,消息会被记录到t_sensitive_messages表中,然后根据type类型做不同的处理,处理方式如下:
|
## 内置文本敏感词过滤处理方法,当命中敏感词后,消息会被记录到t_sensitive_messages表中,然后根据type类型做不同的处理,处理方式如下:
|
||||||
## 0 发送失败;1 发送成功但消息被服务器直接丢弃;2 命中的敏感词被替换成***然后正常发送;3 正常发送。
|
## 0 发送失败;1 发送成功但消息被服务器直接丢弃;2 命中的敏感词被替换成***然后正常发送;3 正常发送。
|
||||||
## 如果开启 message.sensitive.forward.url 配置,命中敏感词的消息还会被回调到这个地址
|
## 如果开启 message.sensitive.forward.url 配置,命中敏感词的消息还会被回调到这个地址
|
||||||
sensitive.filter.type 0
|
sensitive.filter.type 2
|
||||||
|
|
||||||
|
## 敏感词添加或者删除有2种方式,一种是通过Server API进行,这种方式会立即生效。另外一种方法是修改数据库,直接中数据库的t_sensitive_word表中处理
|
||||||
|
## 修改数据库的方法不会立即生效,IM服务会2个小时重新加载一次敏感词。所以如果直接修改敏感词表,需要等2个小时,或者重启才能生效。
|
||||||
|
|
||||||
## 如果内置敏感词库无法满足您的需求,可以开发部署独立敏感词审核服务。配置如下地址和消息类型,IM服务会把指定消息类型的消息回调到指定地址,内置的敏感词审核和敏感词转发功能就不再起作用了。
|
## 如果内置敏感词库无法满足您的需求,可以开发部署独立敏感词审核服务。配置如下地址和消息类型,IM服务会把指定消息类型的消息回调到指定地址,内置的敏感词审核和敏感词转发功能就不再起作用了。
|
||||||
## 审核服务返回状态码200表示继续发送,如果需要替换内容,返回状态码200并且内容为替换后的内容。返回403表示不允许发送。其它错误继续发送。
|
## 审核服务返回状态码200表示继续发送,如果需要替换内容,返回状态码200并且内容为替换后的内容。返回403表示不允许发送。其它错误继续发送。
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ server {
|
|||||||
root html;
|
root html;
|
||||||
index index.html index.htm index.php;
|
index index.html index.htm index.php;
|
||||||
|
|
||||||
|
#同步服务设置
|
||||||
location /route {
|
location /route {
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
proxy_set_header X-real-ip $remote_addr;
|
||||||
@@ -16,7 +17,7 @@ server {
|
|||||||
proxy_pass http://imserver;
|
proxy_pass http://imserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
#社区版需要启用下面一段,专业版不能用
|
#客户端短连接业务
|
||||||
location /im {
|
location /im {
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
proxy_set_header X-real-ip $remote_addr;
|
||||||
@@ -24,14 +25,21 @@ server {
|
|||||||
proxy_pass http://imserver;
|
proxy_pass http://imserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#版本检查/api/version,可以删掉
|
||||||
location /api {
|
location /api {
|
||||||
proxy_pass http://imserver;
|
proxy_pass http://imserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#内置文件上传和下载
|
||||||
location /fs {
|
location /fs {
|
||||||
|
client_max_body_size 200M;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-real-ip $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_pass http://imserver;
|
proxy_pass http://imserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#机器人API
|
||||||
location /robot {
|
location /robot {
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
proxy_set_header X-real-ip $remote_addr;
|
||||||
@@ -39,6 +47,7 @@ server {
|
|||||||
proxy_pass http://imserver;
|
proxy_pass http://imserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#频道API
|
||||||
location /channel {
|
location /channel {
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-real-ip $remote_addr;
|
proxy_set_header X-real-ip $remote_addr;
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<relativePath>../</relativePath>
|
<relativePath>../</relativePath>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>1.3.2</version>
|
<version>1.3.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>moquette-broker</artifactId>
|
<artifactId>moquette-broker</artifactId>
|
||||||
|
|||||||
@@ -900,11 +900,13 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
session.setPullHistoryMsg(true);
|
session.setPullHistoryMsg(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long previousCurrent;
|
||||||
while (true) {
|
while (true) {
|
||||||
Map.Entry<Long, Long> entry = maps.higherEntry(current);
|
Map.Entry<Long, Long> entry = maps.higherEntry(current);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
previousCurrent = current;
|
||||||
current = entry.getKey();
|
current = entry.getKey();
|
||||||
long targetMessageId = entry.getValue();
|
long targetMessageId = entry.getValue();
|
||||||
|
|
||||||
@@ -933,6 +935,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
if (size >= 512 * 1024) { //3M
|
if (size >= 512 * 1024) { //3M
|
||||||
if(builder.getMessageCount() == 0){
|
if(builder.getMessageCount() == 0){
|
||||||
builder.addMessage(bundle.getMessage());
|
builder.addMessage(bundle.getMessage());
|
||||||
|
} else {
|
||||||
|
current = previousCurrent;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2266,15 +2270,29 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check the new owner is in member list? is that necessary?
|
//check the new owner is in member list? is that necessary?
|
||||||
long updateDt = System.currentTimeMillis();
|
|
||||||
groupInfo = groupInfo.toBuilder().setOwner(newOwner).setUpdateDt(updateDt).setMemberUpdateDt(updateDt).build();
|
|
||||||
mIMap.set(groupId, groupInfo);
|
|
||||||
|
|
||||||
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
MultiMap<String, WFCMessage.GroupMember> groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS);
|
||||||
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
Collection<WFCMessage.GroupMember> members = groupMembers.get(groupId);
|
||||||
if (members == null || members.size() == 0) {
|
if (members == null || members.size() == 0) {
|
||||||
members = loadGroupMemberFromDB(hzInstance, groupId);
|
members = loadGroupMemberFromDB(hzInstance, groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isNewOwnerInGroup = false;
|
||||||
|
for (WFCMessage.GroupMember member : members) {
|
||||||
|
if (member.getMemberId().equals(newOwner)) {
|
||||||
|
if(member.getType() != GroupMemberType_Removed) {
|
||||||
|
isNewOwnerInGroup = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!isNewOwnerInGroup) {
|
||||||
|
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
long updateDt = System.currentTimeMillis();
|
||||||
|
groupInfo = groupInfo.toBuilder().setOwner(newOwner).setUpdateDt(updateDt).setMemberUpdateDt(updateDt).build();
|
||||||
|
mIMap.set(groupId, groupInfo);
|
||||||
|
|
||||||
int modifyMemeberCount = 0;
|
int modifyMemeberCount = 0;
|
||||||
for (WFCMessage.GroupMember member : members) {
|
for (WFCMessage.GroupMember member : members) {
|
||||||
if (modifyMemeberCount == 2) {
|
if (modifyMemeberCount == 2) {
|
||||||
@@ -2440,7 +2458,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
boolean isExpired = false;
|
boolean isExpired = false;
|
||||||
if (!canRecall && message.getFromUser().equals(operatorId)) {
|
if (!canRecall && message.getFromUser().equals(operatorId)) {
|
||||||
if (now - message.getServerTimestamp() > mRecallTimeLimit * 1000) {
|
if (mRecallTimeLimit > 0 && now - message.getServerTimestamp() > mRecallTimeLimit * 1000) {
|
||||||
isExpired = true;
|
isExpired = true;
|
||||||
} else {
|
} else {
|
||||||
canRecall = true;
|
canRecall = true;
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>1.3.2</version>
|
<version>1.3.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<!--<relativePath>../pom.xml</relativePath>-->
|
<!--<relativePath>../pom.xml</relativePath>-->
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>1.3.2</version>
|
<version>1.3.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>distribution</artifactId>
|
<artifactId>distribution</artifactId>
|
||||||
|
|||||||
@@ -426,7 +426,10 @@ push.harmony.server.address http://localhost:8085/harmony/push
|
|||||||
## 内置文本敏感词过滤处理方法,当命中敏感词后,消息会被记录到t_sensitive_messages表中,然后根据type类型做不同的处理,处理方式如下:
|
## 内置文本敏感词过滤处理方法,当命中敏感词后,消息会被记录到t_sensitive_messages表中,然后根据type类型做不同的处理,处理方式如下:
|
||||||
## 0 发送失败;1 发送成功但消息被服务器直接丢弃;2 命中的敏感词被替换成***然后正常发送;3 正常发送。
|
## 0 发送失败;1 发送成功但消息被服务器直接丢弃;2 命中的敏感词被替换成***然后正常发送;3 正常发送。
|
||||||
## 如果开启 message.sensitive.forward.url 配置,命中敏感词的消息还会被回调到这个地址
|
## 如果开启 message.sensitive.forward.url 配置,命中敏感词的消息还会被回调到这个地址
|
||||||
sensitive.filter.type 0
|
sensitive.filter.type 2
|
||||||
|
|
||||||
|
## 敏感词添加或者删除有2种方式,一种是通过Server API进行,这种方式会立即生效。另外一种方法是修改数据库,直接中数据库的t_sensitive_word表中处理
|
||||||
|
## 修改数据库的方法不会立即生效,IM服务会2个小时重新加载一次敏感词。所以如果直接修改敏感词表,需要等2个小时,或者重启才能生效。
|
||||||
|
|
||||||
## 如果内置敏感词库无法满足您的需求,可以开发部署独立敏感词审核服务。配置如下地址和消息类型,IM服务会把指定消息类型的消息回调到指定地址,内置的敏感词审核和敏感词转发功能就不再起作用了。
|
## 如果内置敏感词库无法满足您的需求,可以开发部署独立敏感词审核服务。配置如下地址和消息类型,IM服务会把指定消息类型的消息回调到指定地址,内置的敏感词审核和敏感词转发功能就不再起作用了。
|
||||||
## 审核服务返回状态码200表示继续发送,如果需要替换内容,返回状态码200并且内容为替换后的内容。返回403表示不允许发送。其它错误继续发送。
|
## 审核服务返回状态码200表示继续发送,如果需要替换内容,返回状态码200并且内容为替换后的内容。返回403表示不允许发送。其它错误继续发送。
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ JAVA_OPTS="$JAVA_OPTS -XX:MaxGCPauseMillis=500"
|
|||||||
#JAVA_OPTS="$JAVA_OPTS --add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED"
|
#JAVA_OPTS="$JAVA_OPTS --add-modules java.se --add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED"
|
||||||
|
|
||||||
echo "警告:没有设置JVM内存参数!"
|
echo "警告:没有设置JVM内存参数!"
|
||||||
echo "请设置JVM参数Xmx和Xms,设置为您为IM服务预留的内存大小,注意需要刨除操作系统占用,如果有其它系统也需要相应去除占用。"
|
echo "请设置JVM参数Xmx和Xms,设置为您为IM服务预留的内存大小,注意需要刨除操作系统占用,如果有其它系统也需要相应去除占用,还需要减去堆外内存占用。"
|
||||||
|
echo "建议设置为总内存的60%以下,比如16G总内存,Xmx可以设置为9G"
|
||||||
echo ""
|
echo ""
|
||||||
#JAVA_OPTS="$JAVA_OPTS -Xmx2G"
|
#JAVA_OPTS="$JAVA_OPTS -Xmx2G"
|
||||||
#JAVA_OPTS="$JAVA_OPTS -Xms2G"
|
#JAVA_OPTS="$JAVA_OPTS -Xms2G"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.3.2</version>
|
<version>1.3.4</version>
|
||||||
<name>Wildfire Chat</name>
|
<name>Wildfire Chat</name>
|
||||||
<description>Wildfire Chat Server</description>
|
<description>Wildfire Chat Server</description>
|
||||||
<inceptionYear>2019</inceptionYear>
|
<inceptionYear>2019</inceptionYear>
|
||||||
|
|||||||
@@ -12,6 +12,19 @@
|
|||||||
|
|
||||||
# 更新记录
|
# 更新记录
|
||||||
|
|
||||||
|
--------------
|
||||||
|
Release note 1.3.4:
|
||||||
|
1. 优化Server SDK中消息内容的处理方式。
|
||||||
|
2. Server SDK中添加注册消息接口,在使用自定义消息时,不需要修改Server SDK源码。
|
||||||
|
3. 用户撤回时间配置允许为负数,为负数时可以任意时间撤回。
|
||||||
|
4. Server SDK添加超时参数。
|
||||||
|
5. 解决当分段拉取消息时,可能丢失消息的问题。
|
||||||
|
|
||||||
|
--------------
|
||||||
|
Release note 1.3.3:
|
||||||
|
1. 转移群组时检查新群主是否在群中。
|
||||||
|
2. 机器人API添加定向消息接口。
|
||||||
|
|
||||||
--------------
|
--------------
|
||||||
Release note 1.3.2:
|
Release note 1.3.2:
|
||||||
1. 机器人Server SDK添加朋友圈相关接口。
|
1. 机器人Server SDK添加朋友圈相关接口。
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>wildfirechat-parent</artifactId>
|
<artifactId>wildfirechat-parent</artifactId>
|
||||||
<groupId>cn.wildfirechat</groupId>
|
<groupId>cn.wildfirechat</groupId>
|
||||||
<version>1.3.2</version>
|
<version>1.3.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -24,10 +24,15 @@ public class RobotService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload) throws Exception {
|
public IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload) throws Exception {
|
||||||
|
return sendMessage(sender, conversation, payload, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload, List<String> toUsers) throws Exception {
|
||||||
String path = APIPath.Robot_Message_Send;
|
String path = APIPath.Robot_Message_Send;
|
||||||
SendMessageData messageData = new SendMessageData();
|
SendMessageData messageData = new SendMessageData();
|
||||||
messageData.setSender(sender);
|
messageData.setSender(sender);
|
||||||
messageData.setConv(conversation);
|
messageData.setConv(conversation);
|
||||||
|
messageData.setToUsers(toUsers);
|
||||||
messageData.setPayload(payload);
|
messageData.setPayload(payload);
|
||||||
return robotHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
return robotHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class ArticlesMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setSearchableContent(topArticle.title);
|
payload.setSearchableContent(topArticle.title);
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
|
|
||||||
@@ -53,6 +53,7 @@ public class ArticlesMessageContent extends MessageContent {
|
|||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
try {
|
try {
|
||||||
|
super.decode(payload);
|
||||||
JSONObject object = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
|
JSONObject object = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
|
||||||
JSONObject topObj = (JSONObject) object.get("top");
|
JSONObject topObj = (JSONObject) object.get("top");
|
||||||
this.topArticle = Article.fromJson(topObj);
|
this.topArticle = Article.fromJson(topObj);
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public class CallStartMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setContent(callId);
|
payload.setContent(callId);
|
||||||
payload.setPushContent("音视频通话邀请");
|
payload.setPushContent("音视频通话邀请");
|
||||||
|
|
||||||
@@ -175,6 +175,7 @@ public class CallStartMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
callId = payload.getContent();
|
callId = payload.getContent();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class CardMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setContent(target);
|
payload.setContent(target);
|
||||||
JSONObject objWrite = new JSONObject();
|
JSONObject objWrite = new JSONObject();
|
||||||
objWrite.put("t", type);
|
objWrite.put("t", type);
|
||||||
@@ -116,6 +116,7 @@ public class CardMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
target = payload.getContent();
|
target = payload.getContent();
|
||||||
try {
|
try {
|
||||||
if (!StringUtil.isNullOrEmpty(payload.getBase64edData())) {
|
if (!StringUtil.isNullOrEmpty(payload.getBase64edData())) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class FileMessageContent extends MediaMessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setSearchableContent(name);
|
payload.setSearchableContent(name);
|
||||||
payload.setContent(size + "");
|
payload.setContent(size + "");
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class FileMessageContent extends MediaMessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
super.decodeBase(payload);
|
super.decode(payload);
|
||||||
|
|
||||||
if (payload.getSearchableContent().startsWith(FILE_NAME_PREFIX)) {
|
if (payload.getSearchableContent().startsWith(FILE_NAME_PREFIX)) {
|
||||||
name = payload.getSearchableContent().substring(payload.getSearchableContent().indexOf(FILE_NAME_PREFIX) + FILE_NAME_PREFIX.length());
|
name = payload.getSearchableContent().substring(payload.getSearchableContent().indexOf(FILE_NAME_PREFIX) + FILE_NAME_PREFIX.length());
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class ImageMessageContent extends MediaMessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setSearchableContent("[图片]");
|
payload.setSearchableContent("[图片]");
|
||||||
payload.setBase64edData(Base64.getEncoder().encodeToString(thumbnailBytes));
|
payload.setBase64edData(Base64.getEncoder().encodeToString(thumbnailBytes));
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ public class ImageMessageContent extends MediaMessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
super.decodeBase(payload);
|
super.decode(payload);
|
||||||
thumbnailBytes = Base64.getDecoder().decode(payload.getBase64edData());
|
thumbnailBytes = Base64.getDecoder().decode(payload.getBase64edData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,9 +72,7 @@ public class LinkMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
|
|
||||||
|
|
||||||
payload.setSearchableContent(title);
|
payload.setSearchableContent(title);
|
||||||
JSONObject objWrite = new JSONObject();
|
JSONObject objWrite = new JSONObject();
|
||||||
objWrite.put("d", contentDigest);
|
objWrite.put("d", contentDigest);
|
||||||
@@ -88,9 +86,8 @@ public class LinkMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
title = payload.getSearchableContent();
|
title = payload.getSearchableContent();
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!StringUtil.isNullOrEmpty(payload.getBase64edData())) {
|
if (!StringUtil.isNullOrEmpty(payload.getBase64edData())) {
|
||||||
JSONObject jsonObject = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
|
JSONObject jsonObject = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class LocationMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setSearchableContent(title);
|
payload.setSearchableContent(title);
|
||||||
payload.setBase64edData(Base64.getEncoder().encodeToString(this.thumbnailByte));
|
payload.setBase64edData(Base64.getEncoder().encodeToString(this.thumbnailByte));
|
||||||
|
|
||||||
@@ -82,6 +82,7 @@ public class LocationMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
if (!StringUtil.isNullOrEmpty(payload.getBase64edData())) {
|
if (!StringUtil.isNullOrEmpty(payload.getBase64edData())) {
|
||||||
this.thumbnailByte = Base64.getDecoder().decode(payload.getBase64edData());
|
this.thumbnailByte = Base64.getDecoder().decode(payload.getBase64edData());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,18 @@ abstract public class MediaMessageContent extends MessageContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MessagePayload encodeBase() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setRemoteMediaUrl(remoteMediaUrl);
|
payload.setRemoteMediaUrl(remoteMediaUrl);
|
||||||
payload.setMediaType(getMediaType());
|
payload.setMediaType(getMediaType());
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
|
remoteMediaUrl = payload.getRemoteMediaUrl();
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract int getMediaType();
|
protected abstract int getMediaType();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public abstract class MessageContent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MessagePayload encodeBase() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = new MessagePayload();
|
MessagePayload payload = new MessagePayload();
|
||||||
payload.setType(getContentType());
|
payload.setType(getContentType());
|
||||||
payload.setPersistFlag(getPersistFlag());
|
payload.setPersistFlag(getPersistFlag());
|
||||||
@@ -32,13 +32,11 @@ public abstract class MessageContent {
|
|||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void decodeBase(MessagePayload payload) {
|
protected void decode(MessagePayload payload) {
|
||||||
this.mentionedType = payload.getMentionedType();
|
this.mentionedType = payload.getMentionedType();
|
||||||
this.mentionedTargets = payload.getMentionedTarget();
|
this.mentionedTargets = payload.getMentionedTarget();
|
||||||
this.extra = payload.getExtra();
|
this.extra = payload.getExtra();
|
||||||
}
|
}
|
||||||
abstract public int getContentType();
|
abstract public int getContentType();
|
||||||
abstract public int getPersistFlag();
|
abstract public int getPersistFlag();
|
||||||
abstract public MessagePayload encode();
|
|
||||||
abstract public void decode(MessagePayload payload);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class MessageContentFactory {
|
public class MessageContentFactory {
|
||||||
private static final Map<Integer, Class<MessageContent>> contentClassMap = new ConcurrentHashMap<>();
|
private static final Map<Integer, Class<? extends MessageContent>> contentClassMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
registerAllMessageContent();
|
registerAllMessageContent();
|
||||||
@@ -36,7 +36,7 @@ public class MessageContentFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static MessageContent decodeMessageContent(MessagePayload messagePayload) {
|
public static MessageContent decodeMessageContent(MessagePayload messagePayload) {
|
||||||
Class<MessageContent> cls = contentClassMap.get(messagePayload.getType());
|
Class<? extends MessageContent> cls = contentClassMap.get(messagePayload.getType());
|
||||||
MessageContent messageContent;
|
MessageContent messageContent;
|
||||||
if(cls != null) {
|
if(cls != null) {
|
||||||
try {
|
try {
|
||||||
@@ -49,11 +49,15 @@ public class MessageContentFactory {
|
|||||||
} else {
|
} else {
|
||||||
messageContent = new UnknownMessageContent();
|
messageContent = new UnknownMessageContent();
|
||||||
}
|
}
|
||||||
messageContent.decodeBase(messagePayload);
|
|
||||||
messageContent.decode(messagePayload);
|
messageContent.decode(messagePayload);
|
||||||
return messageContent;
|
return messageContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerCustomMessageContent(Class<? extends MessageContent> cls) throws Exception {
|
||||||
|
MessageContent content = cls.newInstance();
|
||||||
|
contentClassMap.put(content.getContentType(), cls);
|
||||||
|
}
|
||||||
|
|
||||||
private static void registerAllMessageContent() {
|
private static void registerAllMessageContent() {
|
||||||
try {
|
try {
|
||||||
for (Class cls : ClassUtil.getAllAssignedClass(MessageContent.class)) {
|
for (Class cls : ClassUtil.getAllAssignedClass(MessageContent.class)) {
|
||||||
|
|||||||
+2
-1
@@ -43,7 +43,7 @@ public class MultiCallOngoingMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setContent(callId);
|
payload.setContent(callId);
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
object.put("initiator", this.initiator);
|
object.put("initiator", this.initiator);
|
||||||
@@ -60,6 +60,7 @@ public class MultiCallOngoingMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
this.callId = payload.getContent();
|
this.callId = payload.getContent();
|
||||||
try {
|
try {
|
||||||
JSONObject object = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
|
JSONObject object = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
|
||||||
|
|||||||
+2
-2
@@ -57,7 +57,7 @@ public class NotDeliveredMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("mid", this.messageUid);
|
obj.put("mid", this.messageUid);
|
||||||
obj.put("all", this.allFailure);
|
obj.put("all", this.allFailure);
|
||||||
@@ -74,7 +74,7 @@ public class NotDeliveredMessageContent extends MessageContent {
|
|||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
try {
|
try {
|
||||||
|
super.decode(payload);
|
||||||
JSONObject obj = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
|
JSONObject obj = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
|
||||||
this.messageUid = (long) obj.get("mid");
|
this.messageUid = (long) obj.get("mid");
|
||||||
this.allFailure = (boolean) obj.get("all");
|
this.allFailure = (boolean) obj.get("all");
|
||||||
|
|||||||
+2
-1
@@ -89,7 +89,7 @@ public class RichNotificationMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setPushContent(title);
|
payload.setPushContent(title);
|
||||||
payload.setContent(desc);
|
payload.setContent(desc);
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
@@ -113,5 +113,6 @@ public class RichNotificationMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,11 +35,12 @@ public class SoundMessageContent extends MediaMessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put("duration", duration);
|
jsonObject.put("duration", duration);
|
||||||
payload.setContent(jsonObject.toJSONString());
|
payload.setContent(jsonObject.toJSONString());
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class StickerMessageContent extends MediaMessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setSearchableContent("[动态表情]");
|
payload.setSearchableContent("[动态表情]");
|
||||||
JSONObject objWrite = new JSONObject();
|
JSONObject objWrite = new JSONObject();
|
||||||
objWrite.put("x", width);
|
objWrite.put("x", width);
|
||||||
@@ -47,8 +47,7 @@ public class StickerMessageContent extends MediaMessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
super.decodeBase(payload);
|
super.decode(payload);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
|
JSONObject jsonObject = (JSONObject) new JSONParser().parse(new String(Base64.getDecoder().decode(payload.getBase64edData())));
|
||||||
width = (int) jsonObject.get("x");
|
width = (int) jsonObject.get("x");
|
||||||
|
|||||||
+2
-1
@@ -38,13 +38,14 @@ public class StreamTextGeneratedMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
this.streamId = payload.getContent();
|
this.streamId = payload.getContent();
|
||||||
this.text = payload.getSearchableContent();
|
this.text = payload.getSearchableContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setSearchableContent(text);
|
payload.setSearchableContent(text);
|
||||||
payload.setContent(streamId);
|
payload.setContent(streamId);
|
||||||
return payload;
|
return payload;
|
||||||
|
|||||||
+2
-1
@@ -38,13 +38,14 @@ public class StreamTextGeneratingMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
streamId = payload.getContent();
|
streamId = payload.getContent();
|
||||||
text = payload.getSearchableContent();
|
text = payload.getSearchableContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setSearchableContent(text);
|
payload.setSearchableContent(text);
|
||||||
payload.setContent(streamId);
|
payload.setContent(streamId);
|
||||||
return payload;
|
return payload;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class TextMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setSearchableContent(text);
|
payload.setSearchableContent(text);
|
||||||
if(quoteInfo != null) {
|
if(quoteInfo != null) {
|
||||||
payload.setBase64edData(Base64.getEncoder().encodeToString(quoteInfo.encode().toJSONString().getBytes(StandardCharsets.UTF_8)));
|
payload.setBase64edData(Base64.getEncoder().encodeToString(quoteInfo.encode().toJSONString().getBytes(StandardCharsets.UTF_8)));
|
||||||
@@ -66,6 +66,7 @@ public class TextMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
|
super.decode(payload);
|
||||||
text = payload.getSearchableContent();
|
text = payload.getSearchableContent();
|
||||||
if(!TextUtils.isEmpty(payload.getBase64edData())) {
|
if(!TextUtils.isEmpty(payload.getBase64edData())) {
|
||||||
String jsonStr = new String(Base64.getDecoder().decode(payload.getBase64edData()), StandardCharsets.UTF_8);
|
String jsonStr = new String(Base64.getDecoder().decode(payload.getBase64edData()), StandardCharsets.UTF_8);
|
||||||
|
|||||||
+2
-2
@@ -24,7 +24,7 @@ public class TipNotificationMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setContent(tip);
|
payload.setContent(tip);
|
||||||
|
|
||||||
return payload;
|
return payload;
|
||||||
@@ -32,7 +32,7 @@ public class TipNotificationMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
super.decodeBase(payload);
|
super.decode(payload);
|
||||||
tip = payload.getContent();
|
tip = payload.getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ public class TypingMessageContent extends MessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setContent(typingType + "");
|
payload.setContent(typingType + "");
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
super.decodeBase(payload);
|
super.decode(payload);
|
||||||
typingType = Integer.parseInt(payload.getContent());
|
typingType = Integer.parseInt(payload.getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class VideoMessageContent extends MediaMessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload encode() {
|
public MessagePayload encode() {
|
||||||
MessagePayload payload = super.encodeBase();
|
MessagePayload payload = super.encode();
|
||||||
payload.setSearchableContent("[视频]");
|
payload.setSearchableContent("[视频]");
|
||||||
|
|
||||||
payload.setBase64edData(Base64.getEncoder().encodeToString(thumbnailBytes));
|
payload.setBase64edData(Base64.getEncoder().encodeToString(thumbnailBytes));
|
||||||
@@ -73,7 +73,7 @@ public class VideoMessageContent extends MediaMessageContent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(MessagePayload payload) {
|
public void decode(MessagePayload payload) {
|
||||||
super.decodeBase(payload);
|
super.decode(payload);
|
||||||
thumbnailBytes = Base64.getDecoder().decode(payload.getBase64edData());
|
thumbnailBytes = Base64.getDecoder().decode(payload.getBase64edData());
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = (JSONObject) new JSONParser().parse(payload.getContent());
|
JSONObject jsonObject = (JSONObject) new JSONParser().parse(payload.getContent());
|
||||||
|
|||||||
@@ -38,11 +38,24 @@ public class AdminHttpUtils extends JsonUtils {
|
|||||||
private static CloseableHttpClient httpClient;
|
private static CloseableHttpClient httpClient;
|
||||||
|
|
||||||
public static void init(String url, String secret) {
|
public static void init(String url, String secret) {
|
||||||
adminUrl = url;
|
init(url, secret, 15000);
|
||||||
adminSecret = secret;
|
}
|
||||||
|
|
||||||
|
public static void init(String url, String secret, int timeout) {
|
||||||
|
adminUrl = url.trim();
|
||||||
|
adminSecret = secret.trim();
|
||||||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
||||||
cm.setValidateAfterInactivity(1000);
|
cm.setValidateAfterInactivity(1000);
|
||||||
|
int connectTimeout = 5000; // 连接超时时间
|
||||||
|
int connectionRequestTimeout = 3000; // 从连接池获取连接的超时时间
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
.setConnectTimeout(connectTimeout)
|
||||||
|
.setSocketTimeout(timeout)
|
||||||
|
.setConnectionRequestTimeout(connectionRequestTimeout)
|
||||||
|
.build();
|
||||||
|
|
||||||
httpClient = HttpClients.custom()
|
httpClient = HttpClients.custom()
|
||||||
|
.setDefaultRequestConfig(requestConfig)
|
||||||
.setConnectionManager(cm)
|
.setConnectionManager(cm)
|
||||||
.evictExpiredConnections()
|
.evictExpiredConnections()
|
||||||
.evictIdleConnections(60L, TimeUnit.SECONDS)
|
.evictIdleConnections(60L, TimeUnit.SECONDS)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.apache.commons.codec.digest.DigestUtils;
|
|||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
@@ -35,12 +36,21 @@ public class ChannelHttpUtils extends JsonUtils {
|
|||||||
private final CloseableHttpClient httpClient;
|
private final CloseableHttpClient httpClient;
|
||||||
|
|
||||||
public ChannelHttpUtils(String imurl, String channelId, String secret) {
|
public ChannelHttpUtils(String imurl, String channelId, String secret) {
|
||||||
this.imurl = imurl;
|
this.imurl = imurl.trim();
|
||||||
this.channelId = channelId;
|
this.channelId = channelId.trim();
|
||||||
this.channelSecret = secret;
|
this.channelSecret = secret.trim();
|
||||||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
||||||
cm.setValidateAfterInactivity(1000);
|
cm.setValidateAfterInactivity(1000);
|
||||||
|
int connectTimeout = 5000; // 连接超时时间
|
||||||
|
int socketTimeout = 15000; // 请求超时时间
|
||||||
|
int connectionRequestTimeout = 3000; // 从连接池获取连接的超时时间
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
.setConnectTimeout(connectTimeout)
|
||||||
|
.setSocketTimeout(socketTimeout)
|
||||||
|
.setConnectionRequestTimeout(connectionRequestTimeout)
|
||||||
|
.build();
|
||||||
httpClient = HttpClients.custom()
|
httpClient = HttpClients.custom()
|
||||||
|
.setDefaultRequestConfig(requestConfig)
|
||||||
.setConnectionManager(cm)
|
.setConnectionManager(cm)
|
||||||
.evictExpiredConnections()
|
.evictExpiredConnections()
|
||||||
.evictIdleConnections(60L, TimeUnit.SECONDS)
|
.evictIdleConnections(60L, TimeUnit.SECONDS)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.apache.commons.codec.digest.DigestUtils;
|
|||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
@@ -36,12 +37,21 @@ public class RobotHttpUtils extends JsonUtils {
|
|||||||
private final CloseableHttpClient httpClient;
|
private final CloseableHttpClient httpClient;
|
||||||
|
|
||||||
public RobotHttpUtils(String url, String robotId, String robotSecret) {
|
public RobotHttpUtils(String url, String robotId, String robotSecret) {
|
||||||
this.url = url;
|
this.url = url.trim();
|
||||||
this.robotId = robotId;
|
this.robotId = robotId.trim();
|
||||||
this.robotSecret = robotSecret;
|
this.robotSecret = robotSecret.trim();
|
||||||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
||||||
cm.setValidateAfterInactivity(1000);
|
cm.setValidateAfterInactivity(1000);
|
||||||
|
int connectTimeout = 5000; // 连接超时时间
|
||||||
|
int socketTimeout = 15000; // 请求超时时间
|
||||||
|
int connectionRequestTimeout = 3000; // 从连接池获取连接的超时时间
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
.setConnectTimeout(connectTimeout)
|
||||||
|
.setSocketTimeout(socketTimeout)
|
||||||
|
.setConnectionRequestTimeout(connectionRequestTimeout)
|
||||||
|
.build();
|
||||||
httpClient = HttpClients.custom()
|
httpClient = HttpClients.custom()
|
||||||
|
.setDefaultRequestConfig(requestConfig)
|
||||||
.setConnectionManager(cm)
|
.setConnectionManager(cm)
|
||||||
.evictExpiredConnections()
|
.evictExpiredConnections()
|
||||||
.evictIdleConnections(60L, TimeUnit.SECONDS)
|
.evictIdleConnections(60L, TimeUnit.SECONDS)
|
||||||
|
|||||||
Reference in New Issue
Block a user