Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52b624f25e | ||
|
|
d90bab53ad | ||
|
|
4d60231c8c | ||
|
|
d08d6f0c49 | ||
|
|
effa30b546 | ||
|
|
0f688ff1df | ||
|
|
daa4767ed8 | ||
|
|
44a916892b | ||
|
|
51dd94d3a7 | ||
|
|
2609a4251c | ||
|
|
7d36775c27 | ||
|
|
6c9df5c071 | ||
|
|
2f9c4e028c | ||
|
|
a9b83a14ed | ||
|
|
919b81139d | ||
|
|
52959a5e63 | ||
|
|
31dad28fde | ||
|
|
3094089658 | ||
|
|
24d24fe1e9 | ||
|
|
47039f53b2 | ||
|
|
554243d553 | ||
|
|
b65282f8e2 | ||
|
|
a5f64df2de | ||
|
|
c7f1ea57dc | ||
|
|
c9b2de076d | ||
|
|
552fadaa87 | ||
|
|
765572db36 | ||
|
|
a5f194b385 | ||
|
|
c74cd7e290 | ||
|
|
70cf65f0c0 | ||
|
|
3bb23f92c4 | ||
|
|
804c12845e | ||
|
|
fe15a32499 | ||
|
|
06d168935d | ||
|
|
c1984d27b3 | ||
|
|
29ef46b7a0 | ||
|
|
0bdff3fd89 | ||
|
|
cd03583dab | ||
|
|
3f8fd7e5e0 | ||
|
|
fdfe71f700 | ||
|
|
35ecf7ccc6 | ||
|
|
8f798742c3 | ||
|
|
f4ea8b184c | ||
|
|
2d7f344b1a | ||
|
|
bee03cd2f8 | ||
|
|
59b1c3180f |
@@ -158,6 +158,14 @@ mvn clean package
|
||||
## 服务对象
|
||||
因为野火的使用范围比较广,难免被一些不法分子利用,国内反诈反赌力度很大,所以国内多地警方都跟我们都有过联系。***为了预防我们的产品被用于非法目的,试用及购买只能支持境内法人单位,不接受个人或者境外团体。如果我们发现产品被用于非法目的,我们会立即停止技术支持服务并且报警和配合警方调查。请用于非法目的用户绕行!***
|
||||
|
||||
## 群的性能问题
|
||||
群的大小和性能不是线性相关的,而是O(N²)的关系,这是群的特性决定的。所以社区版IM服务很难支持很大的群人数,我们建议最大群不要超过500人,像微信的群大小一样。修改方法是修改数据库中```t_settings```表中的群最大人数。
|
||||
|
||||
如果是专业版IM服务,普通群性能会有些加强,但也不会提高太多,所以我们就开发了超级群,可以支持上万群成员。关于超级群,请参考[野火超级群组](https://mp.weixin.qq.com/s/ov5ZiaEIUZuvgFBXOrcjbg)。现有客户有接近10W的群组成员能够流畅稳定地运行。
|
||||
|
||||
## 网络问题
|
||||
如果是自建机房或者私有网络,可能会有跨运营商瓶颈,详情请参考[《从野火 IM 的网络踩坑经历,聊聊跨运营商访问的那些坑》](https://mp.weixin.qq.com/s/Pa8b93oMk58fjMgwtwmePQ)。
|
||||
|
||||
## 常见问题
|
||||
请参考文档[常见问题](https://docs.wildfirechat.cn/faq/server.html)
|
||||
|
||||
|
||||
@@ -170,6 +170,16 @@ robot.callback_with_sender_info false
|
||||
## 机器人回调信息是否带上目标的信息,单聊时是对方用户信息,群聊时是群组信息,频道时是频道信息
|
||||
robot.callback_with_target_info false
|
||||
|
||||
## 是否允许@会话外的机器人。如果为true,单聊或者群聊时,可以@不在会话中的机器人。当机器人收到消息后,可以回复消息。
|
||||
## 如果为false,不能@不在会话中的机器人。机器人不在会话中时,也不能回复消息。
|
||||
robot.mention_external_robot true
|
||||
|
||||
## 机器人获取信息允许的字段,可以获取userId/displayName/portrait,其他需要这里配置允许。
|
||||
## 第一位(1)是name, 第二位(2)是mobile,第三(4)位是email,第四位(8)是address,第五位(16)是company,第六位(32)是extra,
|
||||
## 第七位(64)是updateDt,第八位(128)是gender,第九位(256)是social,第十位(512)是type。
|
||||
## 比如允许获取name和email就是5(1+4),允许获取name和mobile和company和type就是531(1+2+16+512),允许全部是1023(1+2+...+512)
|
||||
#robot.get_user_info_mask 1023
|
||||
|
||||
## 频道回调信息是否带上用户clientId和平台类型。
|
||||
channel.callback_with_client_info false
|
||||
|
||||
@@ -189,8 +199,8 @@ friend.disable_search false
|
||||
##禁止按照昵称搜索用户。
|
||||
friend.disable_nick_name_search false
|
||||
|
||||
##禁止按照用户id搜索用户,默认为true。
|
||||
friend.disable_user_id_search true
|
||||
##禁止按照用户id搜索用户,默认为false。
|
||||
friend.disable_user_id_search false
|
||||
|
||||
##禁止发送好友邀请,通过server api添加好友不受此限制(force参数需要为true)
|
||||
friend.disable_friend_request false
|
||||
@@ -207,6 +217,12 @@ friend.request_expiration_duration 604800000
|
||||
##好友请求限制频率,一个用户24小时之内允许请求好友的次数,默认不限频。
|
||||
friend.request_rate_limit 30
|
||||
|
||||
##如果搜索电话号码,24小时内搜索错误号码几次就不再允许电话号码搜素。防止有人遍历搜索电话号码
|
||||
friend.search_mobile_empty_rate_limit 5
|
||||
|
||||
##如果搜索用户,24小时内搜索次数。防止有人遍历用户名或者用户ID乱加好友。另外可以禁止ID搜索friend.disable_user_id_search
|
||||
friend.search_rate_limit 100
|
||||
|
||||
##请求添加机器人为好友时,机器人是否自动接受,默认为true
|
||||
friend.robot_auto_accept true
|
||||
|
||||
@@ -263,6 +279,16 @@ group.enable_mark_deletion true
|
||||
## 销毁用户时,用户信息会被清空,deleted字段设置为1,这个开关控制是否保留用户昵称,默认为true。
|
||||
user.keep_display_name_when_destroy true
|
||||
|
||||
## 销毁用户时deleted字段设置为1,这个开关控制是否保留其他信息,默认是false。
|
||||
user.keep_full_info_when_destroy false
|
||||
|
||||
## 销毁用户时,如果user.keep_full_info_when_destroy为true,会保留所有信息,这个开关控制是否保留这个用户信息的电话号码,默认为false。
|
||||
## 当保留所有信息且保留电话号码时,用户如果再注册会用到原来的UID,能够看到原来用户的消息,需要考虑一下是否让已删除用户再次注册登录看到之前的消息。
|
||||
user.keep_mobile_when_destroy false
|
||||
|
||||
## 销毁用户时是否保留归属于这个用户的所有消息记录,默认为false。
|
||||
user.keep_messages_when_destroy false
|
||||
|
||||
# 好友/好友请求/用户设置 这三类数据同步的最大条目数。之前是客户第一次登录时,会把所有的对应数据一次下载到客户端,但如果有特别多的信息,会导致无法同步到客户端,
|
||||
# 因此需要分段多次同步,此开关定义了每次同步的数据的条数。此需要客户端支持,客户端SDK在2021.5.25日后支持此功能。如果确认所有客户端都在这个日志之后才可以打开此设置。
|
||||
#sync.data_part_size 1000
|
||||
@@ -314,6 +340,13 @@ qiniu.bucket_portrait_name storage
|
||||
qiniu.bucket_portrait_domain http://cdn2.wildfirechat.cn
|
||||
qiniu.bucket_favorite_name storage
|
||||
qiniu.bucket_favorite_domain http://cdn2.wildfirechat.cn
|
||||
## custom的桶是给客户预留的,客户可以上传自己的文件到这3个桶中,野火不会用到这几个桶。如果不需要,可以忽略这几个配置
|
||||
qiniu.bucket_custom1_name temp1
|
||||
qiniu.bucket_custom1_domain http://temp1.wildfirechat.cn
|
||||
qiniu.bucket_custom2_name temp2
|
||||
qiniu.bucket_custom2_domain http://temp2.wildfirechat.cn
|
||||
qiniu.bucket_custom3_name temp3
|
||||
qiniu.bucket_custom3_domain http://temp3.wildfirechat.cn
|
||||
|
||||
##媒体类型分类
|
||||
#Media_Type_GENERAL = 0,
|
||||
@@ -448,6 +481,10 @@ push.harmony.server.address http://localhost:8085/harmony/push
|
||||
## 如果开启 message.sensitive.forward.url 配置,命中敏感词的消息还会被回调到这个地址
|
||||
sensitive.filter.type 2
|
||||
|
||||
## 敏感词是否只处理消息。如果为true,只过滤消息;如果为false,会同时过滤用户昵称、群组名和群昵称。
|
||||
## 除了消息之外的信息只支持内部敏感词处理,不支持外置审核。
|
||||
sensitive.only_message false
|
||||
|
||||
## 敏感词添加或者删除有2种方式,一种是通过Server API进行,这种方式会立即生效。另外一种方法是修改数据库,直接中数据库的t_sensitive_word表中处理
|
||||
## 修改数据库的方法不会立即生效,IM服务会2个小时重新加载一次敏感词。所以如果直接修改敏感词表,需要等2个小时,或者重启才能生效。
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
CREATE INDEX `user_gid_mid_dt_index` ON `t_group_member` (`_gid`, `_mid`, `_dt`);
|
||||
CREATE INDEX `user_gid_dt_index` ON `t_group_member` (`_gid`, `_dt`);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
insert into t_settings(`id`, `_value`,`_desc`) values (2, '文件传输助手,客服,官方', '禁止使用名称,如果有多个,以英文逗号隔开。直接修改数据库,不用重启IM服务');
|
||||
+1
@@ -0,0 +1 @@
|
||||
alter table `t_messages` modify column `_target` varchar(129) NOT NULL;
|
||||
+1
@@ -0,0 +1 @@
|
||||
ALTER TABLE `t_user_session` ADD COLUMN `_ip` varchar(40) DEFAULT '';
|
||||
+1
@@ -0,0 +1 @@
|
||||
CREATE INDEX `user_gid_type_index` ON `t_group_member` (`_gid`, `_type`);
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_conference`;
|
||||
CREATE TABLE `t_conference` (
|
||||
`_id` varchar(64) NOT NULL PRIMARY KEY,
|
||||
`_des` varchar(64) NOT NULL,
|
||||
`_pin` varchar(16) NOT NULL,
|
||||
`_max_publishers` int(11) NOT NULL DEFAULT 0,
|
||||
`_bitrate` int(11) NOT NULL DEFAULT 0,
|
||||
`_advance` tinyint NOT NULL DEFAULT 0,
|
||||
`_recording` tinyint NOT NULL DEFAULT 0,
|
||||
`_create_dt` bigint(20) NOT NULL
|
||||
);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
DROP TABLE IF EXISTS `t_join_group_request`;
|
||||
CREATE TABLE `t_join_group_request` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`_uid` varchar(64) NOT NULL,
|
||||
`_gid` varchar(64) NOT NULL,
|
||||
`_mid` varchar(64) NOT NULL,
|
||||
`_request_uid` varchar(64) NOT NULL,
|
||||
`_accept_uid` varchar(64) DEFAULT NULL,
|
||||
`_reason` TEXT DEFAULT NULL,
|
||||
`_extra` TEXT DEFAULT NULL,
|
||||
`_status` tinyint NOT NULL DEFAULT 0,
|
||||
`_dt` bigint(20) NOT NULL,
|
||||
`_read_status` tinyint DEFAULT 0,
|
||||
UNIQUE INDEX `join_group_request_key_index` (`_uid` DESC, `_gid` DESC, `_mid` DESC, `_request_uid` DESC),
|
||||
INDEX `join_group_request_gm_index` (`_gid` DESC, `_mid` DESC),
|
||||
INDEX `join_group_request_sync_index` (`_uid` DESC, `_dt` DESC)
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
DROP INDEX `user_gid_mid_dt_index` ON `t_group_member`;
|
||||
CREATE INDEX `user_gid_dt_index` ON `t_group_member` (`_gid`, `_dt`);
|
||||
@@ -0,0 +1 @@
|
||||
insert into t_settings(`id`, `_value`,`_desc`) values (2, '文件传输助手,客服,官方', '禁止使用名称,如果有多个,以英文逗号隔开。直接修改数据库,不用重启IM服务');
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
alter table `t_messages` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_0` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_1` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_2` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_3` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_4` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_5` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_6` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_7` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_8` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_9` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_10` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_11` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_12` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_13` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_14` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_15` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_16` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_17` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_18` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_19` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_20` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_21` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_22` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_23` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_24` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_25` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_26` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_27` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_28` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_29` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_30` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_31` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_32` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_33` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_34` modify column `_target` varchar(129) NOT NULL;
|
||||
alter table `t_messages_35` modify column `_target` varchar(129) NOT NULL;
|
||||
+1
@@ -0,0 +1 @@
|
||||
ALTER TABLE `t_user_session` ADD COLUMN `_ip` varchar(40) DEFAULT '';
|
||||
@@ -0,0 +1 @@
|
||||
CREATE INDEX `user_gid_type_index` ON `t_group_member` (`_gid`, `_type`);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_conference`;
|
||||
CREATE TABLE `t_conference` (
|
||||
`_id` varchar(64) NOT NULL PRIMARY KEY,
|
||||
`_des` varchar(64) NOT NULL,
|
||||
`_pin` varchar(16) NOT NULL,
|
||||
`_max_publishers` int(11) NOT NULL DEFAULT 0,
|
||||
`_bitrate` int(11) NOT NULL DEFAULT 0,
|
||||
`_advance` tinyint NOT NULL DEFAULT 0,
|
||||
`_recording` tinyint NOT NULL DEFAULT 0,
|
||||
`_create_dt` bigint(20) NOT NULL
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_unicode_ci;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
DROP TABLE IF EXISTS `t_join_group_request`;
|
||||
CREATE TABLE `t_join_group_request` (
|
||||
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`_uid` varchar(64) NOT NULL,
|
||||
`_gid` varchar(64) NOT NULL,
|
||||
`_mid` varchar(64) NOT NULL,
|
||||
`_request_uid` varchar(64) NOT NULL,
|
||||
`_accept_uid` varchar(64) DEFAULT NULL,
|
||||
`_reason` TEXT DEFAULT NULL,
|
||||
`_extra` TEXT DEFAULT NULL,
|
||||
`_status` tinyint NOT NULL DEFAULT 0,
|
||||
`_dt` bigint(20) NOT NULL,
|
||||
`_read_status` tinyint DEFAULT 0,
|
||||
UNIQUE INDEX `join_group_request_key_index` (`_uid` DESC, `_gid` DESC, `_mid` DESC, `_request_uid` DESC),
|
||||
INDEX `join_group_request_gm_index` (`_gid` DESC, `_mid` DESC),
|
||||
INDEX `join_group_request_sync_index` (`_uid` DESC, `_dt` DESC)
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = utf8mb4
|
||||
COLLATE = utf8mb4_unicode_ci;
|
||||
+1
-55
@@ -5,7 +5,7 @@
|
||||
<relativePath>../</relativePath>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>1.3.7</version>
|
||||
<version>1.4.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>moquette-broker</artifactId>
|
||||
@@ -211,60 +211,6 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Test.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Generate the test-jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Includes to generate OSGi headers -->
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>bundle-manifest</id>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>manifest</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
|
||||
@@ -11,6 +11,7 @@ package com.xiaoleilu.loServer.action;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
@@ -28,7 +29,9 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Route("/route")
|
||||
@@ -111,6 +114,12 @@ public class RouteAction extends Action {
|
||||
WFCMessage.IMHttpWrapper wrapper = WFCMessage.IMHttpWrapper.parseFrom(bytes);
|
||||
String token = wrapper.getToken();
|
||||
String userId = Tokenor.getUserId(token.getBytes());
|
||||
|
||||
String remote = ((InetSocketAddress) ctx.channel().remoteAddress())
|
||||
.getAddress().getHostAddress();
|
||||
String ip = computeRealIp(request.getHeaders(), remote);
|
||||
|
||||
|
||||
LOG.info("RouteAction token={}, userId={}", token, userId);
|
||||
if (userId == null) {
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_TOKEN_ERROR, null);
|
||||
@@ -119,6 +128,8 @@ public class RouteAction extends Action {
|
||||
@Override
|
||||
public void onSuccess(byte[] result) {
|
||||
sendResponse(response, null, result);
|
||||
//save ip after success response.
|
||||
sessionsStore.updateSessionIp(userId, wrapper.getClientId(), ip);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,6 +158,20 @@ public class RouteAction extends Action {
|
||||
return true;
|
||||
}
|
||||
|
||||
private String computeRealIp(Map<String, String> h, String remote) {
|
||||
String xff = h.get("X-Forwarded-For");
|
||||
if (xff != null && !xff.isEmpty() && !"unknown".equalsIgnoreCase(xff)) {
|
||||
int idx = xff.indexOf(',');
|
||||
String first = (idx > 0 ? xff.substring(0, idx) : xff).trim();
|
||||
return first;
|
||||
}
|
||||
String xri = h.get("X-Real-IP");
|
||||
if (xri != null && !xri.isEmpty() && !"unknown".equalsIgnoreCase(xri)) {
|
||||
return xri;
|
||||
}
|
||||
return remote;
|
||||
}
|
||||
|
||||
private void sendResponse(Response response, ErrorCode errorCode, byte[] contents) {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
if (contents == null) {
|
||||
|
||||
@@ -24,6 +24,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
@@ -213,7 +215,7 @@ public class UploadFileAction extends Action {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
remoteFileName = getSafeFileName(remoteFileName);
|
||||
|
||||
String remoteFileExt = "";
|
||||
if (remoteFileName.lastIndexOf(".") == -1) {
|
||||
@@ -339,6 +341,15 @@ public class UploadFileAction extends Action {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String getSafeFileName(String originalFilename) {
|
||||
// Paths.get() 会解析路径,getFileName() 只取最后一部分(纯文件名)
|
||||
Path filenamePath = Paths.get(originalFilename.trim());
|
||||
String safeFilename = filenamePath.getFileName().toString();
|
||||
// 额外过滤特殊字符(可选,根据业务需要)
|
||||
safeFilename = safeFilename.replaceAll("[\\\\/:*?\"<>|]", "_");
|
||||
return safeFilename.isEmpty() ? "default_file_" + System.currentTimeMillis() : safeFilename;
|
||||
}
|
||||
|
||||
public static void put(File file, long pos, byte[] data) throws Exception {
|
||||
RandomAccessFile raf = null;
|
||||
try {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class CreateUserAction extends AdminAction {
|
||||
if (inputCreateUser.getName() != null)
|
||||
newUserBuilder.setName(inputCreateUser.getName());
|
||||
if (inputCreateUser.getDisplayName() != null)
|
||||
newUserBuilder.setDisplayName(StringUtil.isNullOrEmpty(inputCreateUser.getDisplayName()) ? inputCreateUser.getName() : inputCreateUser.getDisplayName());
|
||||
newUserBuilder.setDisplayName(inputCreateUser.getDisplayName());
|
||||
if (inputCreateUser.getPortrait() != null)
|
||||
newUserBuilder.setPortrait(inputCreateUser.getPortrait());
|
||||
if (inputCreateUser.getEmail() != null)
|
||||
@@ -65,11 +65,8 @@ public class CreateUserAction extends AdminAction {
|
||||
newUserBuilder.setAddress(inputCreateUser.getAddress());
|
||||
if (inputCreateUser.getCompany() != null)
|
||||
newUserBuilder.setCompany(inputCreateUser.getCompany());
|
||||
|
||||
if (inputCreateUser.getSocial() != null)
|
||||
newUserBuilder.setSocial(inputCreateUser.getSocial());
|
||||
|
||||
|
||||
if (inputCreateUser.getMobile() != null)
|
||||
newUserBuilder.setMobile(inputCreateUser.getMobile());
|
||||
newUserBuilder.setGender(inputCreateUser.getGender());
|
||||
|
||||
@@ -11,12 +11,17 @@ package com.xiaoleilu.loServer.action.admin;
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.InputUpdateFriendExtra;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
@Route(APIPath.Friend_Set_Extra)
|
||||
@HttpMethod("POST")
|
||||
@@ -31,8 +36,17 @@ public class FriendExtraPutAction extends AdminAction {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputUpdateFriendExtra input = getRequestBody(request.getNettyRequest(), InputUpdateFriendExtra.class);
|
||||
ErrorCode errorCode = messagesStore.setFriendExtraRequest(input.getOperator(), input.getTargetId(), input.getExtra(), new long[1]);
|
||||
setResponseContent(RestResult.resultOf(errorCode), response);
|
||||
if (input != null && !StringUtil.isNullOrEmpty(input.getOperator()) && !StringUtil.isNullOrEmpty(input.getTargetId())) {
|
||||
sendApiMessage(response, input.getOperator(), IMTopic.SetFriendExtraTopic, WFCMessage.StringPair.newBuilder().setKey(input.getTargetId()).setValue(input.getExtra()==null?"":input.getExtra()).build().toByteArray(), result -> {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
byteBuf.writeBytes(result);
|
||||
ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte());
|
||||
return new Result(errorCode);
|
||||
});
|
||||
return false;
|
||||
} else {
|
||||
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.InputRobotId;
|
||||
import cn.wildfirechat.pojos.InputUserId;
|
||||
import cn.wildfirechat.pojos.OutputRobot;
|
||||
import cn.wildfirechat.pojos.OutputStringList;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
@Route(APIPath.User_Get_User_Robots)
|
||||
@HttpMethod("POST")
|
||||
public class GetUserRobotsAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputUserId inputUserId = getRequestBody(request.getNettyRequest(), InputUserId.class);
|
||||
if (inputUserId != null
|
||||
&& (!StringUtil.isNullOrEmpty(inputUserId.getUserId()))) {
|
||||
RestResult result = RestResult.ok(new OutputStringList(messagesStore.getUserRobotIds(inputUserId.getUserId())));
|
||||
setResponseContent(result, response);
|
||||
} else {
|
||||
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class SendMessageAction extends AdminAction {
|
||||
} else {
|
||||
return new Result(errorCode);
|
||||
}
|
||||
});
|
||||
}, sendMessageData.isUserMessage());
|
||||
return false;
|
||||
} else {
|
||||
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||
|
||||
@@ -47,7 +47,39 @@ public class GetUserAction extends RobotAction {
|
||||
if (user == null || user.getDeleted() > 0) {
|
||||
result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST);
|
||||
} else {
|
||||
result = RestResult.ok(InputOutputUserInfo.fromPbUser(user));
|
||||
InputOutputUserInfo outputUserInfo = InputOutputUserInfo.fromPbUser(user);
|
||||
int mask = messagesStore.getRobotGetUserInfoMask();
|
||||
if((mask & 1) == 0) {
|
||||
outputUserInfo.setName(null);
|
||||
}
|
||||
if((mask & 2) == 0) {
|
||||
outputUserInfo.setMobile(null);
|
||||
}
|
||||
if((mask & 4) == 0) {
|
||||
outputUserInfo.setEmail(null);
|
||||
}
|
||||
if((mask & 8) == 0) {
|
||||
outputUserInfo.setAddress(null);
|
||||
}
|
||||
if((mask & 16) == 0) {
|
||||
outputUserInfo.setCompany(null);
|
||||
}
|
||||
if((mask & 32) == 0) {
|
||||
outputUserInfo.setExtra(null);
|
||||
}
|
||||
if((mask & 64) == 0) {
|
||||
outputUserInfo.setUpdateDt(0);
|
||||
}
|
||||
if((mask & 128) == 0) {
|
||||
outputUserInfo.setGender(0);
|
||||
}
|
||||
if((mask & 256) == 0) {
|
||||
outputUserInfo.setSocial(null);
|
||||
}
|
||||
if((mask & 512) == 0) {
|
||||
outputUserInfo.setType(0);
|
||||
}
|
||||
result = RestResult.ok(outputUserInfo);
|
||||
}
|
||||
setResponseContent(result, response);
|
||||
} else {
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package com.xiaoleilu.loServer.action.robot;
|
||||
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.Conversation;
|
||||
import cn.wildfirechat.pojos.ReplyMessageData;
|
||||
import cn.wildfirechat.pojos.SendMessageData;
|
||||
import cn.wildfirechat.pojos.SendMessageResult;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
import com.xiaoleilu.loServer.annotation.Route;
|
||||
import com.xiaoleilu.loServer.handler.Request;
|
||||
import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Route(APIPath.Robot_Message_Reply)
|
||||
@HttpMethod("POST")
|
||||
public class ReplyMessageAction extends RobotAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
ReplyMessageData replyMessageData = getRequestBody(request.getNettyRequest(), ReplyMessageData.class);
|
||||
if (ReplyMessageData.isValide(replyMessageData)) {
|
||||
WFCMessage.Message message = messagesStore.getMessage(replyMessageData.getMessageUid());
|
||||
ErrorCode errorCode = null;
|
||||
if(message == null) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
} else if(!message.getContent().getMentionedTargetList().contains(robot.getUid())) {
|
||||
errorCode = ErrorCode.ERROR_CODE_INVALID_MESSAGE;
|
||||
} else if(message.getConversation().getType() != ProtoConstants.ConversationType.ConversationType_Private && message.getConversation().getType() != ProtoConstants.ConversationType.ConversationType_Group) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
|
||||
} else if(System.currentTimeMillis() - message.getServerTimestamp() > 15*60*1000) {
|
||||
errorCode = ErrorCode.ERROR_CODE_RECALL_TIME_EXPIRED;
|
||||
} else if(!messagesStore.isRobotMentionExternalRobot()) {
|
||||
if(message.getConversation().getType() != ProtoConstants.ConversationType.ConversationType_Group) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
|
||||
} else {
|
||||
WFCMessage.GroupMember member = messagesStore.getGroupMember(message.getConversation().getTarget(), robot.getUid());
|
||||
if(member == null || member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Removed) {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(errorCode != null) {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(errorCode);
|
||||
response.setContent(gson.toJson(result));
|
||||
return true;
|
||||
}
|
||||
|
||||
SendMessageData sendMessageData = getSendMessageData(message, replyMessageData);
|
||||
WFCMessage.Message newMsg = sendMessageData.toProtoMessage().toBuilder().setMessageId(message.getMessageId()).build();
|
||||
sendApiRequest(response, IMTopic.RobotReplyMessageTopic, newMsg.toByteArray(), result -> {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
byteBuf.writeBytes(result);
|
||||
ErrorCode ec = ErrorCode.fromCode(byteBuf.readByte());
|
||||
if (ec == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
long messageId = byteBuf.readLong();
|
||||
long timestamp = byteBuf.readLong();
|
||||
sendResponse(response, null, new SendMessageResult(messageId, timestamp));
|
||||
} else {
|
||||
sendResponse(response, ec, null);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
} else {
|
||||
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private @NotNull SendMessageData getSendMessageData(WFCMessage.Message message, ReplyMessageData replyMessageData) {
|
||||
SendMessageData sendMessageData = new SendMessageData();
|
||||
sendMessageData.setSender(robot.getUid());
|
||||
Conversation conversation = new Conversation();
|
||||
conversation.setType(message.getConversation().getType());
|
||||
conversation.setLine(message.getConversation().getLine());
|
||||
conversation.setTarget(message.getConversation().getTarget());
|
||||
sendMessageData.setConv(conversation);
|
||||
sendMessageData.setPayload(replyMessageData.getPayload());
|
||||
if(replyMessageData.isOnly2Sender()) {
|
||||
sendMessageData.setToUsers(Arrays.asList(message.getFromUser()));
|
||||
}
|
||||
return sendMessageData;
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,13 @@ public final class BrokerConstants {
|
||||
public static final String QINIU_BUCKET_PORTRAIT_DOMAIN = "qiniu.bucket_portrait_domain";
|
||||
public static final String QINIU_BUCKET_FAVORITE_NAME= "qiniu.bucket_favorite_name";
|
||||
public static final String QINIU_BUCKET_FAVORITE_DOMAIN = "qiniu.bucket_favorite_domain";
|
||||
public static final String QINIU_BUCKET_CUSTOM1_NAME= "qiniu.bucket_custom1_name";
|
||||
public static final String QINIU_BUCKET_CUSTOM1_DOMAIN = "qiniu.bucket_custom1_domain";
|
||||
public static final String QINIU_BUCKET_CUSTOM2_NAME= "qiniu.bucket_custom2_name";
|
||||
public static final String QINIU_BUCKET_CUSTOM2_DOMAIN = "qiniu.bucket_custom2_domain";
|
||||
public static final String QINIU_BUCKET_CUSTOM3_NAME= "qiniu.bucket_custom3_name";
|
||||
public static final String QINIU_BUCKET_CUSTOM3_DOMAIN = "qiniu.bucket_custom3_domain";
|
||||
|
||||
|
||||
public static final String FILE_STORAGE_ROOT = "local.media.storage.root";
|
||||
public static final String FILE_STORAGE_REMOTE_SERVER_URL = "local.media.storage.remote_server_url";
|
||||
@@ -124,7 +131,7 @@ public final class BrokerConstants {
|
||||
|
||||
|
||||
public static final String SENSITIVE_Filter_Type = "sensitive.filter.type";
|
||||
|
||||
public static final String SENSITIVE_Only_Message = "sensitive.only_message";
|
||||
public static final String SENSITIVE_Remote_Server_URL = "sensitive.remote_server_url";
|
||||
public static final String SENSITIVE_Remote_Message_Type = "sensitive.remote_sensitive_message_type";
|
||||
public static final String SENSITIVE_Remote_Fail_When_Matched = "sensitive.remote_fail_when_matched";
|
||||
@@ -173,6 +180,8 @@ public final class BrokerConstants {
|
||||
public static final String ROBOT_Callback_With_Client_Info = "robot.callback_with_client_info";
|
||||
public static final String ROBOT_Callback_With_Sender_Info = "robot.callback_with_sender_info";
|
||||
public static final String ROBOT_Callback_With_Target_Info = "robot.callback_with_target_info";
|
||||
public static final String ROBOT_Mention_External_Robot = "robot.mention_external_robot";
|
||||
public static final String ROBOT_Get_User_Info_Mask = "robot.get_user_info_mask";
|
||||
|
||||
public static final String CHANNEL_Callback_With_Client_Info = "channel.callback_with_client_info";
|
||||
public static final String CHANNEL_Callback_With_Sender_Info = "channel.callback_with_sender_info";
|
||||
@@ -188,6 +197,8 @@ public final class BrokerConstants {
|
||||
public static final String FRIEND_Reject_Request_Duration = "friend.reject_request_duration";
|
||||
public static final String FRIEND_Request_Expiration_Duration = "friend.request_expiration_duration";
|
||||
public static final String FRIEND_Request_Rate_Limit = "friend.request_rate_limit";
|
||||
public static final String FRIEND_Search_Mobile_Empty_Rate_Limit = "friend.search_mobile_empty_rate_limit";
|
||||
public static final String FRIEND_Search_Rate_Limit = "friend.search_rate_limit";
|
||||
public static final String FRIEND_Request_Robot_Auto_Accept = "friend.robot_auto_accept";
|
||||
|
||||
|
||||
@@ -211,6 +222,9 @@ public final class BrokerConstants {
|
||||
|
||||
public static final String USER_HIDE_PROPERTIES = "user.hide_properties";
|
||||
public static final String USER_KEEP_DISPLAY_NAME_WHEN_DESTROY = "user.keep_display_name_when_destroy";
|
||||
public static final String USER_KEEP_FULL_INFO_WHEN_DESTROY = "user.keep_full_info_when_destroy";
|
||||
public static final String USER_KEEP_MOBILE_WHEN_DESTROY = "user.keep_mobile_when_destroy";
|
||||
public static final String USER_KEEP_MESSAGES_WHEN_DESTROY = "user.keep_messages_when_destroy";
|
||||
|
||||
public static final String SYNC_Data_Part_Size = "sync.data_part_size";
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import win.liyufan.im.IMTopic;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Handler(value = IMTopic.CreateGroupTopic)
|
||||
public class CreateGroupHandler extends GroupHandler<WFCMessage.CreateGroupRequest> {
|
||||
@@ -68,6 +69,19 @@ public class CreateGroupHandler extends GroupHandler<WFCMessage.CreateGroupReque
|
||||
return ErrorCode.INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if(!isAdmin && !StringUtil.isNullOrEmpty(request.getGroup().getGroupInfo().getName())) {
|
||||
if(!m_messagesStore.isSensitiveOnlyMessage()) {
|
||||
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getGroup().getGroupInfo().getName());
|
||||
if (matched != null && !matched.isEmpty()) {
|
||||
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
}
|
||||
}
|
||||
|
||||
if(!m_messagesStore.isAllowName(request.getGroup().getGroupInfo().getName())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.createGroup(fromUser, request.getGroup().getGroupInfo(), request.getGroup().getMembersList(), request.getMemberExtra(), isAdmin, failedMembers);
|
||||
if (groupInfo != null && groupInfo.getDeleted() == 0) {
|
||||
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
|
||||
@@ -32,7 +32,6 @@ public class GetMediaUploadTokenHandler extends IMHandler<WFCMessage.GetUploadTo
|
||||
if (MediaServerConfig.USER_QINIU) {
|
||||
Auth auth = Auth.create(MediaServerConfig.QINIU_ACCESS_KEY, MediaServerConfig.QINIU_SECRET_KEY);
|
||||
|
||||
|
||||
String bucketName;
|
||||
String bucketDomain;
|
||||
switch (type) {
|
||||
@@ -72,6 +71,18 @@ public class GetMediaUploadTokenHandler extends IMHandler<WFCMessage.GetUploadTo
|
||||
bucketName = MediaServerConfig.QINIU_BUCKET_MOMENTS_NAME;
|
||||
bucketDomain = MediaServerConfig.QINIU_BUCKET_MOMENTS_DOMAIN;
|
||||
break;
|
||||
case 9:
|
||||
bucketName = MediaServerConfig.QINIU_BUCKET_CUSTOM1_NAME;
|
||||
bucketDomain = MediaServerConfig.QINIU_BUCKET_CUSTOM1_DOMAIN;
|
||||
break;
|
||||
case 10:
|
||||
bucketName = MediaServerConfig.QINIU_BUCKET_CUSTOM2_NAME;
|
||||
bucketDomain = MediaServerConfig.QINIU_BUCKET_CUSTOM2_DOMAIN;
|
||||
break;
|
||||
case 11:
|
||||
bucketName = MediaServerConfig.QINIU_BUCKET_CUSTOM3_NAME;
|
||||
bucketDomain = MediaServerConfig.QINIU_BUCKET_CUSTOM3_DOMAIN;
|
||||
break;
|
||||
default:
|
||||
bucketName = MediaServerConfig.QINIU_BUCKET_GENERAL_NAME;
|
||||
bucketDomain = MediaServerConfig.QINIU_BUCKET_GENERAL_DOMAIN;
|
||||
|
||||
@@ -77,6 +77,18 @@ public class GetQiniuUploadTokenHandler extends IMHandler<Byte> {
|
||||
bucketName = MediaServerConfig.QINIU_BUCKET_MOMENTS_NAME;
|
||||
bucketDomain = MediaServerConfig.QINIU_BUCKET_MOMENTS_DOMAIN;
|
||||
break;
|
||||
case 9:
|
||||
bucketName = MediaServerConfig.QINIU_BUCKET_CUSTOM1_NAME;
|
||||
bucketDomain = MediaServerConfig.QINIU_BUCKET_CUSTOM1_DOMAIN;
|
||||
break;
|
||||
case 10:
|
||||
bucketName = MediaServerConfig.QINIU_BUCKET_CUSTOM2_NAME;
|
||||
bucketDomain = MediaServerConfig.QINIU_BUCKET_CUSTOM2_DOMAIN;
|
||||
break;
|
||||
case 11:
|
||||
bucketName = MediaServerConfig.QINIU_BUCKET_CUSTOM3_NAME;
|
||||
bucketDomain = MediaServerConfig.QINIU_BUCKET_CUSTOM3_DOMAIN;
|
||||
break;
|
||||
default:
|
||||
bucketName = MediaServerConfig.QINIU_BUCKET_GENERAL_NAME;
|
||||
bucketDomain = MediaServerConfig.QINIU_BUCKET_GENERAL_DOMAIN;
|
||||
|
||||
@@ -45,20 +45,20 @@ public class HandleFriendRequestHandler extends IMHandler<WFCMessage.HandleFrien
|
||||
contentBuilder.setType(92);
|
||||
|
||||
builder = WFCMessage.Message.newBuilder();
|
||||
builder.setFromUser(request.getTargetUid());
|
||||
builder.setConversation(WFCMessage.Conversation.newBuilder().setTarget(fromUser).setLine(0).setType(ProtoConstants.ConversationType.ConversationType_Private).build());
|
||||
builder.setFromUser(fromUser);
|
||||
builder.setConversation(WFCMessage.Conversation.newBuilder().setTarget(request.getTargetUid()).setLine(0).setType(ProtoConstants.ConversationType.ConversationType_Private).build());
|
||||
builder.setContent(contentBuilder);
|
||||
builder.setServerTimestamp(++timestamp);
|
||||
|
||||
messageId = MessageShardingUtil.generateId();
|
||||
builder.setMessageId(messageId);
|
||||
saveAndPublish(request.getTargetUid(), null, builder.build(), requestSourceType);
|
||||
saveAndPublish(fromUser, null, builder.build(), requestSourceType);
|
||||
contentBuilder.setType(93);
|
||||
builder.setContent(contentBuilder);
|
||||
messageId = MessageShardingUtil.generateId();
|
||||
builder.setMessageId(messageId);
|
||||
builder.setServerTimestamp(++timestamp);
|
||||
saveAndPublish(request.getTargetUid(), null, builder.build(), requestSourceType);
|
||||
saveAndPublish(fromUser, null, builder.build(), requestSourceType);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -11,11 +11,14 @@ package io.moquette.imhandler;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import cn.wildfirechat.pojos.GroupNotificationBinaryContent;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@Handler(IMTopic.ModifyGroupAliasTopic)
|
||||
@@ -26,10 +29,24 @@ public class ModifyGroupAliasHandler extends GroupHandler<WFCMessage.ModifyGroup
|
||||
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0 && requestSourceType == ProtoConstants.RequestSourceType.Request_From_User && !m_messagesStore.isAllowClientCustomGroupNotification()) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0 && requestSourceType == ProtoConstants.RequestSourceType.Request_From_Robot && !m_messagesStore.isAllowRobotCustomGroupNotification()) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
if (!isAdmin && !StringUtil.isNullOrEmpty(request.getAlias())) {
|
||||
if(!m_messagesStore.isSensitiveOnlyMessage()) {
|
||||
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getAlias());
|
||||
if (matched != null && !matched.isEmpty()) {
|
||||
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
}
|
||||
}
|
||||
|
||||
if(!m_messagesStore.isAllowName(request.getAlias())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode errorCode = m_messagesStore.modifyGroupMemberAlias(fromUser, request.getGroupId(), request.getAlias(), null, isAdmin);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
if (request.hasNotifyContent()&& request.getNotifyContent().getType() > 0) {
|
||||
|
||||
@@ -12,10 +12,13 @@ import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.GroupNotificationBinaryContent;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@Handler(IMTopic.ModifyGroupMemberAliasTopic)
|
||||
@@ -29,6 +32,18 @@ public class ModifyGroupMemberAliasHandler extends GroupHandler<WFCMessage.Modif
|
||||
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0 && requestSourceType == ProtoConstants.RequestSourceType.Request_From_Robot && !m_messagesStore.isAllowRobotCustomGroupNotification()) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
if (!isAdmin && !StringUtil.isNullOrEmpty(request.getAlias())) {
|
||||
if(!m_messagesStore.isSensitiveOnlyMessage()) {
|
||||
Set<String> matched = m_messagesStore.handleSensitiveWord(request.getAlias());
|
||||
if (matched != null && !matched.isEmpty()) {
|
||||
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
}
|
||||
}
|
||||
|
||||
if(!m_messagesStore.isAllowName(request.getAlias())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode errorCode = m_messagesStore.modifyGroupMemberAlias(fromUser, request.getGroupId(), request.getAlias(), request.getMemberId(), isAdmin);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.MessagePayload;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import io.moquette.BrokerConstants;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import win.liyufan.im.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@Handler(value = IMTopic.RobotReplyMessageTopic)
|
||||
public class ReplyMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
private int mSensitiveType = 0; //命中敏感词时,0 失败,1 吞掉, 2 敏感词替换成*。
|
||||
private String mForwardUrl = null;
|
||||
private String mSensitiveMessageForwardUrl = null;
|
||||
private Set<Integer> mForwardMessageTypes = new HashSet<>();
|
||||
private Set<Integer> mForwardExcludeMessageTypes = new HashSet<>();
|
||||
private String mMentionForwardUrl = null;
|
||||
private int mBlacklistStrategy = 0; //黑名单中时,0失败,1吞掉。
|
||||
private boolean mBlacklistAllowSend2Black = true;
|
||||
private boolean mNoForwardAdminMessage = false;
|
||||
private boolean mAllowSend2ForbiddenUser = false;
|
||||
|
||||
private String mRemoteSensitiveServerUrl = null;
|
||||
private Set<Integer> mRemoteSensitiveMessageTypes;
|
||||
private boolean mWaitRemoteSensitiveServerResponse = false;
|
||||
|
||||
public ReplyMessageHandler() {
|
||||
super();
|
||||
|
||||
mForwardUrl = mServer.getConfig().getProperty(BrokerConstants.MESSAGE_Forward_Url);
|
||||
if (!StringUtil.isNullOrEmpty(mForwardUrl)) {
|
||||
String forwardTypes = mServer.getConfig().getProperty(BrokerConstants.MESSAGE_Forward_Types);
|
||||
parseTypes(mForwardMessageTypes, forwardTypes);
|
||||
String excludeTypes = mServer.getConfig().getProperty(BrokerConstants.MESSAGE_Forward_Exclude_Types);
|
||||
parseTypes(mForwardExcludeMessageTypes, excludeTypes);
|
||||
}
|
||||
mSensitiveMessageForwardUrl = mServer.getConfig().getProperty(BrokerConstants.MESSAGE_Sensitive_Forward_Url);
|
||||
mMentionForwardUrl = mServer.getConfig().getProperty(BrokerConstants.MESSAGE_MentionMsg_Forward_Url);
|
||||
|
||||
try {
|
||||
mSensitiveType = Integer.parseInt(mServer.getConfig().getProperty(BrokerConstants.SENSITIVE_Filter_Type));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
}
|
||||
|
||||
try {
|
||||
mBlacklistStrategy = Integer.parseInt(mServer.getConfig().getProperty(BrokerConstants.MESSAGE_Blacklist_Strategy));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
}
|
||||
|
||||
try {
|
||||
mBlacklistAllowSend2Black = Boolean.parseBoolean(mServer.getConfig().getProperty(BrokerConstants.MESSAGE_Blacklist_Allow_Send, "true"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
mRemoteSensitiveServerUrl = mServer.getConfig().getProperty(BrokerConstants.SENSITIVE_Remote_Server_URL);
|
||||
if(!StringUtil.isNullOrEmpty(mRemoteSensitiveServerUrl)) {
|
||||
mWaitRemoteSensitiveServerResponse = Boolean.parseBoolean(mServer.getConfig().getProperty(BrokerConstants.SENSITIVE_Remote_Fail_When_Matched, "false"));
|
||||
String types = mServer.getConfig().getProperty(BrokerConstants.SENSITIVE_Remote_Message_Type, "");
|
||||
mRemoteSensitiveMessageTypes = new HashSet<>();
|
||||
if(!StringUtil.isNullOrEmpty(types)) {
|
||||
String[] ts = types.split(",");
|
||||
for (String t:ts) {
|
||||
mRemoteSensitiveMessageTypes.add(Integer.parseInt(t.trim()));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
}
|
||||
|
||||
try {
|
||||
mNoForwardAdminMessage = Boolean.parseBoolean(mServer.getConfig().getProperty(BrokerConstants.MESSAGE_NO_Forward_Admin_Message, "false"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e);
|
||||
}
|
||||
|
||||
try {
|
||||
mAllowSend2ForbiddenUser = Boolean.parseBoolean(mServer.getConfig().getProperty(BrokerConstants.MESSAGES_ALLOW_SEND_TO_FORBIDDEN_USER, "false"));
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
private void parseTypes(Collection<Integer> collection, String types) {
|
||||
try {
|
||||
if (!StringUtil.isNullOrEmpty(types)) {
|
||||
String[] tss = types.split(",");
|
||||
for (String ts:tss) {
|
||||
if(ts.contains("-")) {
|
||||
String[] ss = ts.split("-");
|
||||
if(ss.length == 2) {
|
||||
int begin = Integer.parseInt(ss[0]);
|
||||
int end = Integer.parseInt(ss[1]);
|
||||
for (int i = begin; i <= end ; i++) {
|
||||
collection.add(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
collection.add(Integer.parseInt(ts.trim()));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, ProtoConstants.RequestSourceType requestSourceType, WFCMessage.Message message, Qos1PublishHandler.IMCallback callback) {
|
||||
if(requestSourceType != ProtoConstants.RequestSourceType.Request_From_Robot) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
if (message != null) {
|
||||
if(message.getContent().getContent().length() +
|
||||
message.getContent().getSearchableContent().length() +
|
||||
message.getContent().getData().size() +
|
||||
message.getContent().getExtra().length() +
|
||||
message.getContent().getPushContent().length() +
|
||||
message.getContent().getPushData().length() > 64 * 1024) {
|
||||
return ErrorCode.ERROR_CODE_MESSAGE_TOO_LARGE;
|
||||
}
|
||||
|
||||
boolean ignoreMsg = false;
|
||||
|
||||
// 不能在端上直接发送撤回和群通知
|
||||
if (message.getContent().getType() == 80 || message.getContent().getType() == 81 || (message.getContent().getType() >= 100 && message.getContent().getType() < 200)) {
|
||||
return ErrorCode.INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if(m_messagesStore.getClientForbiddenSendTypes().contains(message.getContent().getType())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
int userStatus = m_messagesStore.getUserStatus(fromUser);
|
||||
if (userStatus == ProtoConstants.UserStatus.Muted || userStatus == ProtoConstants.UserStatus.Forbidden) {
|
||||
if(!m_messagesStore.getGlobalMuteExceptionTypes().contains(message.getContent().getType())) {
|
||||
return ErrorCode.ERROR_CODE_FORBIDDEN_SEND_MSG;
|
||||
}
|
||||
}
|
||||
|
||||
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Private) {
|
||||
if(!m_messagesStore.getBlackListExceptionTypes().contains(message.getContent().getType())) {
|
||||
errorCode = m_messagesStore.isAllowUserMessage(message.getConversation().getTarget(), fromUser, message.getConversation().getLine());
|
||||
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (errorCode == ErrorCode.ERROR_CODE_IN_BLACK_LIST && mBlacklistStrategy != ProtoConstants.BlacklistStrategy.Message_Reject) {
|
||||
ignoreMsg = true;
|
||||
errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
} else {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
if(!mBlacklistAllowSend2Black) {
|
||||
errorCode = m_messagesStore.isBlacked(fromUser, message.getConversation().getTarget());
|
||||
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!mAllowSend2ForbiddenUser) {
|
||||
userStatus = m_messagesStore.getUserStatus(message.getConversation().getTarget());
|
||||
if (userStatus == ProtoConstants.UserStatus.Forbidden) {
|
||||
return ErrorCode.ERROR_CODE_USER_FORBIDDEN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Group ) {
|
||||
if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) {
|
||||
errorCode = m_messagesStore.canSendMessageInGroup(fromUser, message.getConversation().getTarget());
|
||||
if(errorCode == ERROR_CODE_NOT_IN_GROUP) {
|
||||
errorCode = ERROR_CODE_SUCCESS;
|
||||
}
|
||||
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_ChatRoom) {
|
||||
if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) {
|
||||
if (!m_messagesStore.checkUserClientInChatroom(fromUser, clientID, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_CHATROOM;
|
||||
}
|
||||
}
|
||||
} else if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) {
|
||||
if(!m_messagesStore.getGroupMuteExceptionTypes().contains(message.getContent().getType())) {
|
||||
if (!m_messagesStore.canSendMessageInChannel(fromUser, message.getConversation().getTarget())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_IN_CHANNEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Private) {
|
||||
long beforeMessageId = message.getMessageId();
|
||||
WFCMessage.Message replyMsg = m_messagesStore.getMessage(beforeMessageId);
|
||||
message = message.toBuilder().setConversation(message.getConversation().toBuilder().setTarget(replyMsg.getFromUser() + "|" + replyMsg.getConversation().getTarget())).build();
|
||||
}
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
final long messageId;
|
||||
try {
|
||||
messageId = MessageShardingUtil.generateId();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ErrorCode.ERROR_CODE_SERVER_ERROR;
|
||||
}
|
||||
message = message.toBuilder().setFromUser(fromUser).setMessageId(messageId).setServerTimestamp(timestamp).build();
|
||||
|
||||
|
||||
if (!StringUtil.isNullOrEmpty(mForwardUrl) && (mForwardMessageTypes.isEmpty() || mForwardMessageTypes.contains(message.getContent().getType())) && !mForwardExcludeMessageTypes.contains(message.getContent().getType())) {
|
||||
publisher.forwardMessage(message, mForwardUrl, clientID);
|
||||
}
|
||||
|
||||
if(!StringUtil.isNullOrEmpty(mMentionForwardUrl) && message.hasContent() && message.getContent().getMentionedType() != 0) {
|
||||
publisher.forwardMessage(message, mMentionForwardUrl, clientID);
|
||||
}
|
||||
|
||||
|
||||
if(StringUtil.isNullOrEmpty(mRemoteSensitiveServerUrl)) {
|
||||
Set<String> matched = m_messagesStore.handleSensitiveWord(message.getContent().getSearchableContent());
|
||||
if (matched != null && !matched.isEmpty()) {
|
||||
m_messagesStore.storeSensitiveMessage(message);
|
||||
if (!StringUtil.isNullOrEmpty(mSensitiveMessageForwardUrl)) {
|
||||
publisher.forwardMessage(message, mSensitiveMessageForwardUrl, clientID);
|
||||
}
|
||||
if (mSensitiveType == 0) {
|
||||
errorCode = ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
} else if (mSensitiveType == 1) {
|
||||
ignoreMsg = true;
|
||||
} else if (mSensitiveType == 2) {
|
||||
String text = message.getContent().getSearchableContent();
|
||||
for (String word : matched) {
|
||||
text = text.replace(word, "***");
|
||||
}
|
||||
message = message.toBuilder().setContent(message.getContent().toBuilder().setSearchableContent(text).build()).build();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(mRemoteSensitiveMessageTypes.contains(message.getContent().getType())) {
|
||||
final WFCMessage.Message finalMsg = message;
|
||||
publisher.forwardMessageWithCallback(message, clientID, mRemoteSensitiveServerUrl, new HttpUtils.HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(String content) {
|
||||
if(StringUtil.isNullOrEmpty(content)) {
|
||||
saveAndPublish(fromUser, clientID, finalMsg, requestSourceType);
|
||||
} else {
|
||||
MessagePayload payload = GsonUtil.gson.fromJson(content, MessagePayload.class);
|
||||
if (payload != null && payload.getType() > 0) {
|
||||
WFCMessage.Message newMsg = finalMsg.toBuilder().setContent(payload.toProtoMessageContent()).build();
|
||||
saveAndPublish(fromUser, clientID, newMsg, requestSourceType);
|
||||
} else {
|
||||
LOG.error("Response content {} from censor is invalid payload, ignore response and send original message", content);
|
||||
saveAndPublish(fromUser, clientID, finalMsg, requestSourceType);
|
||||
}
|
||||
}
|
||||
if(mWaitRemoteSensitiveServerResponse) {
|
||||
ByteBuf ackPayload = Unpooled.buffer(21);
|
||||
ErrorCode errorCode = ERROR_CODE_SUCCESS;
|
||||
ackPayload.writeByte(errorCode.getCode());
|
||||
ackPayload.writeLong(messageId);
|
||||
ackPayload.writeLong(timestamp);
|
||||
callback.onIMHandled(ErrorCode.ERROR_CODE_SUCCESS, ackPayload);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int statusCode, String errorMessage) {
|
||||
ByteBuf ackPayload = null;
|
||||
ErrorCode errorCode = ERROR_CODE_SUCCESS;
|
||||
if(statusCode == 403) {
|
||||
if(mWaitRemoteSensitiveServerResponse) {
|
||||
errorCode = ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
ackPayload = Unpooled.buffer(1);
|
||||
ackPayload.writeByte(errorCode.getCode());
|
||||
}
|
||||
} else {
|
||||
LOG.warn("Failed to censor message with status {}, errorMessage {}. Send the original message", statusCode, errorMessage);
|
||||
saveAndPublish(fromUser, clientID, finalMsg, requestSourceType);
|
||||
|
||||
if(mWaitRemoteSensitiveServerResponse) {
|
||||
errorCode = ERROR_CODE_SUCCESS;
|
||||
ackPayload = Unpooled.buffer(21);
|
||||
ackPayload.writeByte(errorCode.getCode());
|
||||
ackPayload.writeLong(messageId);
|
||||
ackPayload.writeLong(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
if(mWaitRemoteSensitiveServerResponse) {
|
||||
callback.onIMHandled(errorCode, ackPayload);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(mWaitRemoteSensitiveServerResponse) {
|
||||
ackPayload.clear();
|
||||
return ErrorCode.INVALID_ASYNC_HANDLING;
|
||||
} else {
|
||||
ackPayload = ackPayload.capacity(20);
|
||||
ackPayload.writeLong(messageId);
|
||||
ackPayload.writeLong(timestamp);
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if(!ignoreMsg) {
|
||||
saveAndPublish(fromUser, clientID, message, requestSourceType);
|
||||
}
|
||||
ackPayload = ackPayload.capacity(20);
|
||||
ackPayload.writeLong(messageId);
|
||||
ackPayload.writeLong(timestamp);
|
||||
}
|
||||
} else {
|
||||
errorCode = ErrorCode.ERROR_CODE_INVALID_MESSAGE;
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -136,6 +136,15 @@ public class SendMessageHandler extends IMHandler<WFCMessage.Message> {
|
||||
ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS;
|
||||
boolean isAdmin = requestSourceType == ProtoConstants.RequestSourceType.Request_From_Admin;
|
||||
if (message != null) {
|
||||
if(message.getContent().getContent().length() +
|
||||
message.getContent().getSearchableContent().length() +
|
||||
message.getContent().getData().size() +
|
||||
message.getContent().getExtra().length() +
|
||||
message.getContent().getPushContent().length() +
|
||||
message.getContent().getPushData().length() > 64 * 1024) {
|
||||
return ErrorCode.ERROR_CODE_MESSAGE_TOO_LARGE;
|
||||
}
|
||||
|
||||
boolean ignoreMsg = false;
|
||||
if (!isAdmin) { //admin do not check the right
|
||||
// 不能在端上直接发送撤回和群通知
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import win.liyufan.im.IMTopic;
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@Handler(IMTopic.SetFriendExtraTopic)
|
||||
public class SetFriendExtraHandler extends IMHandler<WFCMessage.StringPair> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, ProtoConstants.RequestSourceType requestSourceType, WFCMessage.StringPair request, Qos1PublishHandler.IMCallback callback) {
|
||||
long[] heads = new long[1];
|
||||
ErrorCode errorCode = m_messagesStore.setFriendExtraRequest(fromUser, request.getKey(), request.getValue(), heads);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
publisher.publishNotification(IMTopic.NotifyFriendTopic, fromUser, heads[0], clientID);
|
||||
}
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,18 @@ import io.netty.buffer.ByteBuf;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Handler(IMTopic.UserSearchTopic)
|
||||
public class UserSearchHandler extends IMHandler<WFCMessage.SearchUserRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, ProtoConstants.RequestSourceType requestSourceType, WFCMessage.SearchUserRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
List<WFCMessage.User> users = m_messagesStore.searchUser(request.getKeyword(), request.getFuzzy(), request.getType(), request.getPage());
|
||||
List<WFCMessage.User> users = new ArrayList<>();
|
||||
ErrorCode errorCode = m_messagesStore.searchUser(fromUser, request.getKeyword(), request.getFuzzy(), request.getType(), request.getPage(), users);
|
||||
if(errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
return errorCode;
|
||||
}
|
||||
WFCMessage.SearchUserResult.Builder builder = WFCMessage.SearchUserResult.newBuilder();
|
||||
builder.addAllEntry(users);
|
||||
byte[] data = builder.build().toByteArray();
|
||||
|
||||
@@ -1832,6 +1832,31 @@ public class DatabaseStore {
|
||||
});
|
||||
}
|
||||
|
||||
void updateSessionIp(String uid, String cid, String ip) {
|
||||
mScheduler.execute(()->{
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "update t_user_session set _ip = ? where `_uid` = ? and `_cid` = ?";
|
||||
statement = connection.prepareStatement(sql);
|
||||
int index = 1;
|
||||
statement.setString(index++, ip);
|
||||
statement.setString(index++, uid);
|
||||
statement.setString(index++, cid);
|
||||
|
||||
int c = statement.executeUpdate();
|
||||
LOG.info("Update rows {}", c);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, RDBS_Exception);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void clearMultiEndpoint(String uid, String clientId, int platform) {
|
||||
LOG.info("clearMultiEndpoint {}, {}", uid, clientId);
|
||||
Connection connection = null;
|
||||
@@ -3152,6 +3177,34 @@ public class DatabaseStore {
|
||||
return outList;
|
||||
}
|
||||
|
||||
List<String> getUserRobotIds(String userId) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
ResultSet rs = null;
|
||||
List<String> outList = new ArrayList<>();
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select _uid from t_robot where _owner = ? and _state = 0";
|
||||
statement = connection.prepareStatement(sql);
|
||||
|
||||
int index = 1;
|
||||
statement.setString(1, userId);
|
||||
|
||||
rs = statement.executeQuery();
|
||||
while (rs.next()) {
|
||||
outList.add(rs.getString(1));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Utility.printExecption(LOG, e, RDBS_Exception);
|
||||
} finally {
|
||||
DBUtil.closeDB(connection, statement, rs);
|
||||
}
|
||||
return outList;
|
||||
}
|
||||
|
||||
|
||||
Set<String> getAllEnds(boolean fromUserTable) {
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
|
||||
@@ -58,6 +58,8 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static cn.wildfirechat.common.IMExceptionEvent.EventType.EVENT_CALLBACK_Exception;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ChannelState.*;
|
||||
@@ -157,6 +159,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
private long mFriendRejectDuration = 30 * 24 * 60 * 60 * 1000;
|
||||
private long mFriendRequestExpiration = 7 * 24 * 60 * 60 * 1000;
|
||||
private RateLimiter mFriendRateLimiter;
|
||||
private RateLimiter mFriendSearchEmpthMobileRateLimiter;
|
||||
private RateLimiter mFriendSearchRateLimiter;
|
||||
private boolean mFriendRobotAutoAccept = true;
|
||||
|
||||
private long mPushExpiredTimes = 604800000L;
|
||||
@@ -171,7 +175,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
private boolean mGroupAllowPartSuccess = false;
|
||||
|
||||
private boolean mIDUseUUID = true;
|
||||
|
||||
private boolean mSensitiveOnlyMessage = true;
|
||||
private Set<String> mClientSignatureSet = new HashSet<>();
|
||||
private boolean mRejectEmptySignature = true;
|
||||
|
||||
@@ -202,6 +206,10 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
private int mGroupForbiddenClientOperation;
|
||||
private int mSyncDataPartSize = 0;
|
||||
private boolean keepDisplayNameWhenDestroyUser = true;
|
||||
private boolean keepFullInfoWhenDestroyUser = false;
|
||||
private boolean keepMobileWhenDestroyUser = false;
|
||||
private boolean keepMessagesWhenDestroyUser = false;
|
||||
|
||||
private String mRecallForwardUrl = null;
|
||||
|
||||
private boolean mBroadcastTargetFromUserTable = false;
|
||||
@@ -213,6 +221,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
private boolean mRobotCallbackWithClientInfo = false;
|
||||
private boolean mRobotCallbackWithSenderInfo = false;
|
||||
private boolean mRobotCallbackWithTargetInfo = false;
|
||||
private boolean mRobotMentionExternalRobot = false;
|
||||
private int mRobotGetUserInfoMask = 0;
|
||||
|
||||
private boolean mChannelCallbackWithClientInfo = false;
|
||||
private boolean mChannelCallbackWithSenderInfo = false;
|
||||
@@ -331,7 +341,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
printMissConfigLog(FRIEND_Disable_NickName_Search, mDisableNicknameSearch + "");
|
||||
}
|
||||
try {
|
||||
mDisableUserIdSearch = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.FRIEND_Disable_UserId_Search, "true"));
|
||||
mDisableUserIdSearch = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.FRIEND_Disable_UserId_Search, "false"));
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
@@ -375,6 +385,21 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
int rateLimit = Integer.parseInt(m_Server.getConfig().getProperty(FRIEND_Search_Mobile_Empty_Rate_Limit, "0"));
|
||||
if(rateLimit > 0) {
|
||||
mFriendSearchEmpthMobileRateLimiter = new RateLimiter(86400, rateLimit);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
int rateLimit = Integer.parseInt(m_Server.getConfig().getProperty(FRIEND_Search_Rate_Limit, "0"));
|
||||
if(rateLimit > 0) {
|
||||
mFriendSearchRateLimiter = new RateLimiter(86400, rateLimit);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
mFriendRobotAutoAccept = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.FRIEND_Request_Robot_Auto_Accept, "true"));
|
||||
@@ -599,6 +624,17 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
try {
|
||||
keepFullInfoWhenDestroyUser = "true".equals(server.getConfig().getProperty(USER_KEEP_FULL_INFO_WHEN_DESTROY));
|
||||
} catch (Exception e) {}
|
||||
|
||||
try {
|
||||
keepMobileWhenDestroyUser = "true".equals(server.getConfig().getProperty(USER_KEEP_MOBILE_WHEN_DESTROY));
|
||||
} catch (Exception e) {}
|
||||
|
||||
try {
|
||||
keepMessagesWhenDestroyUser = "true".equals(server.getConfig().getProperty(USER_KEEP_MESSAGES_WHEN_DESTROY));
|
||||
} catch (Exception e) {}
|
||||
|
||||
|
||||
try {
|
||||
@@ -646,6 +682,12 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
try {
|
||||
mRobotCallbackWithTargetInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ROBOT_Callback_With_Target_Info, "false"));
|
||||
} catch (Exception e) {}
|
||||
try {
|
||||
mRobotMentionExternalRobot = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ROBOT_Mention_External_Robot, "false"));
|
||||
} catch (Exception e) {}
|
||||
try {
|
||||
mRobotGetUserInfoMask = Integer.parseInt(server.getConfig().getProperty(BrokerConstants.ROBOT_Get_User_Info_Mask, "0"));
|
||||
} catch (Exception e) {}
|
||||
|
||||
try {
|
||||
mChannelCallbackWithClientInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.CHANNEL_Callback_With_Client_Info, "false"));
|
||||
@@ -671,6 +713,11 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
mIDUseUUID = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ID_USE_UUID, "false"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
mSensitiveOnlyMessage = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.SENSITIVE_Only_Message, "true"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
private void printMissConfigLog(String config, String defaultValue) {
|
||||
@@ -737,13 +784,34 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
int pullType = ProtoConstants.PullType.Pull_Normal;
|
||||
|
||||
if (type == ProtoConstants.ConversationType.ConversationType_Private) {
|
||||
notifyReceivers.add(fromUser);
|
||||
if(message.getToCount() > 0) {
|
||||
if(message.getToList().contains(message.getConversation().getTarget())) {
|
||||
notifyReceivers.add(message.getConversation().getTarget());
|
||||
if(mRobotMentionExternalRobot && message.getConversation().getTarget().contains("|")) {
|
||||
String[] ss = message.getConversation().getTarget().split("\\|");
|
||||
notifyReceivers.add(ss[0]);
|
||||
notifyReceivers.add(ss[1]);
|
||||
if(!message.getToList().isEmpty()) {
|
||||
notifyReceivers.addAll(message.getToList());
|
||||
} else if(!StringUtil.isNullOrEmpty(message.getToUser())) {
|
||||
notifyReceivers.add(message.getToUser());
|
||||
}
|
||||
} else {
|
||||
notifyReceivers.add(message.getConversation().getTarget());
|
||||
notifyReceivers.add(fromUser);
|
||||
if (message.getToCount() > 0) {
|
||||
if (message.getToList().contains(message.getConversation().getTarget())) {
|
||||
notifyReceivers.add(message.getConversation().getTarget());
|
||||
}
|
||||
} else {
|
||||
notifyReceivers.add(message.getConversation().getTarget());
|
||||
}
|
||||
}
|
||||
if (mRobotMentionExternalRobot && message.getContent().getMentionedTargetCount() > 0) {
|
||||
for (String mentioned : message.getContent().getMentionedTargetList()) {
|
||||
if (!notifyReceivers.contains(mentioned)) {
|
||||
WFCMessage.User user = getUserInfo(mentioned);
|
||||
if(user != null && user.getType() == ProtoConstants.UserType.UserType_Robot) {
|
||||
notifyReceivers.add(mentioned);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pullType = ProtoConstants.PullType.Pull_Normal;
|
||||
} else if (type == ProtoConstants.ConversationType.ConversationType_Group) {
|
||||
@@ -773,6 +841,16 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mRobotMentionExternalRobot && message.getContent().getMentionedTargetCount() > 0) {
|
||||
for (String mentioned : message.getContent().getMentionedTargetList()) {
|
||||
if (!notifyReceivers.contains(mentioned)) {
|
||||
WFCMessage.User user = getUserInfo(mentioned);
|
||||
if(user != null && user.getType() == ProtoConstants.UserType.UserType_Robot) {
|
||||
notifyReceivers.add(mentioned);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pullType = ProtoConstants.PullType.Pull_Normal;
|
||||
} else if (type == ProtoConstants.ConversationType.ConversationType_ChatRoom) {
|
||||
boolean isDirect = !StringUtil.isNullOrEmpty(message.getToUser()) || !message.getToList().isEmpty();
|
||||
@@ -1974,6 +2052,19 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
if (!isAllow) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
if (modifyType == Modify_Group_Name && !StringUtil.isNullOrEmpty(value)) {
|
||||
if(!mSensitiveOnlyMessage) {
|
||||
Set<String> matched = handleSensitiveWord(value);
|
||||
if (matched != null && !matched.isEmpty()) {
|
||||
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isAllowName(value)) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (oldInfo.getType() == ProtoConstants.GroupType.GroupType_Normal) {
|
||||
@@ -2705,8 +2796,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
} finally {
|
||||
mWriteLock.unlock();
|
||||
}
|
||||
|
||||
databaseStore.clearUserMessage(userId);
|
||||
if(!keepMessagesWhenDestroyUser) {
|
||||
databaseStore.clearUserMessage(userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2810,6 +2902,19 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
) {
|
||||
switch (entry.getType()) {
|
||||
case Modify_DisplayName:
|
||||
if(!StringUtil.isNullOrEmpty(entry.getValue())) {
|
||||
if (!mSensitiveOnlyMessage) {
|
||||
Set<String> matched = handleSensitiveWord(entry.getValue());
|
||||
if (matched != null && !matched.isEmpty()) {
|
||||
return ErrorCode.ERROR_CODE_SENSITIVE_MATCHED;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isAllowName(entry.getValue())) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
builder.setDisplayName(entry.getValue());
|
||||
modified = true;
|
||||
break;
|
||||
@@ -3071,37 +3176,29 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
IMap<String, WFCMessage.User> mUserMap = hzInstance.getMap(USERS);
|
||||
WFCMessage.User us = mUserMap.get(userId);
|
||||
if (us != null) {
|
||||
if (keepDisplayNameWhenDestroyUser) {
|
||||
us = WFCMessage.User.newBuilder()
|
||||
.setUid(userId)
|
||||
.setUpdateDt(System.currentTimeMillis())
|
||||
.setName(userId)
|
||||
.setDeleted(1)
|
||||
.clearAddress()
|
||||
.clearCompany()
|
||||
.clearEmail()
|
||||
.clearExtra()
|
||||
.clearMobile()
|
||||
.clearPortrait()
|
||||
.clearSocial()
|
||||
.build();
|
||||
WFCMessage.User.Builder builder = WFCMessage.User.newBuilder().setUpdateDt(System.currentTimeMillis()).setDeleted(1);
|
||||
|
||||
if(keepFullInfoWhenDestroyUser) {
|
||||
if(!keepMobileWhenDestroyUser) {
|
||||
builder.clearMobile();
|
||||
}
|
||||
} else {
|
||||
us = WFCMessage.User.newBuilder()
|
||||
.setUid(userId)
|
||||
.setUpdateDt(System.currentTimeMillis())
|
||||
builder.setUid(userId)
|
||||
.setName(userId)
|
||||
.setDeleted(1)
|
||||
.clearDisplayName()
|
||||
.clearAddress()
|
||||
.clearCompany()
|
||||
.clearEmail()
|
||||
.clearExtra()
|
||||
.clearMobile()
|
||||
.clearPortrait()
|
||||
.clearSocial()
|
||||
.build();
|
||||
.clearGender()
|
||||
.clearSocial();
|
||||
if (!keepDisplayNameWhenDestroyUser) {
|
||||
builder.clearDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
us = builder.build();
|
||||
try {
|
||||
databaseStore.updateUser(us);
|
||||
} catch (Exception e) {
|
||||
@@ -3110,8 +3207,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
mUserMap.put(userId, us);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserInfo(WFCMessage.User user) throws Exception {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
@@ -3157,9 +3254,46 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WFCMessage.User> searchUser(String keyword, int searchType, int userType, int page) {
|
||||
public List<String> getUserRobotIds(String userId) {
|
||||
return databaseStore.getUserRobotIds(userId);
|
||||
}
|
||||
|
||||
// 电话号码校验正则表达式(支持中国大陆手机号和固话)
|
||||
private static final String PHONE_REGEX = "^\\s*" + // 允许开头空白
|
||||
"(?:" +
|
||||
"(1[0-9])\\d{9}" +
|
||||
"|" +
|
||||
"((0\\d{2,3})|(\\(0\\d{2,3}\\)))" +
|
||||
"[-\\s.]?" +
|
||||
"\\d{7,8}" +
|
||||
"|" +
|
||||
"\\d{7,8}" +
|
||||
")\\s*$";
|
||||
|
||||
private static final Pattern PHONE_PATTERN = Pattern.compile(PHONE_REGEX);
|
||||
private static final Pattern PHONE_PART_PATTERN = Pattern.compile("^1\\d{0,10}$");
|
||||
|
||||
public static boolean isPhoneNumber(String phone) {
|
||||
if (phone == null || phone.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
Matcher matcher = PHONE_PATTERN.matcher(phone);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
public static boolean isPhoneNumberPart(String str) {
|
||||
if (str == null || str.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Matcher matcher = PHONE_PART_PATTERN.matcher(str);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode searchUser(String userId, String keyword, int searchType, int userType, int page, List<WFCMessage.User> users) {
|
||||
if (mDisableSearch) {
|
||||
return new ArrayList<>();
|
||||
return ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
if (mDisableNicknameSearch && searchType == ProtoConstants.SearchUserType.SearchUserType_General) {
|
||||
@@ -3175,10 +3309,29 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
if(mDisableUserIdSearch && searchType == ProtoConstants.SearchUserType.SearchUserType_UserId) {
|
||||
return new ArrayList<>();
|
||||
return ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
return databaseStore.searchUserFromDB(keyword, searchType, userType, page);
|
||||
if(mFriendSearchRateLimiter != null && !isPhoneNumberPart(keyword)) {
|
||||
//非电话号码,允许多少次搜索。
|
||||
if(!mFriendSearchRateLimiter.isGranted(userId)) {
|
||||
LOG.error("User {} search user mobile over frequency, keyword {}, searchType {}", userId, keyword, searchType);
|
||||
return ErrorCode.ERROR_CODE_OVER_FREQUENCY;
|
||||
}
|
||||
}
|
||||
|
||||
List<WFCMessage.User> matchedUsers = databaseStore.searchUserFromDB(keyword, searchType, userType, page);
|
||||
if(mFriendSearchEmpthMobileRateLimiter != null && matchedUsers.isEmpty() && isPhoneNumber(keyword)) {
|
||||
//查电话号码为空
|
||||
if(!mFriendSearchEmpthMobileRateLimiter.isGranted(userId)) {
|
||||
LOG.error("User {} search user over frequency, keyword {}, searchType {}", userId, keyword, searchType);
|
||||
return ErrorCode.ERROR_CODE_OVER_FREQUENCY;
|
||||
}
|
||||
}
|
||||
|
||||
users.addAll(matchedUsers);
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -3901,6 +4054,25 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowName(String name) {
|
||||
if(StringUtil.isNullOrEmpty(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
name = name.trim();
|
||||
SystemSettingPojo notAllowNameSetting = getSystemSetting(ProtoConstants.SystemSettingType.NOT_ALLOW_USER_NAMES);
|
||||
if (notAllowNameSetting != null && !StringUtil.isNullOrEmpty(notAllowNameSetting.value)) {
|
||||
String[] ss = notAllowNameSetting.value.split(",");
|
||||
for (String s : ss) {
|
||||
if(name.contains(s.trim())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId) {
|
||||
IMap<String, WFCMessage.ChatroomInfo> chatroomInfoMap = m_Server.getHazelcastInstance().getMap(CHATROOMS);
|
||||
@@ -4770,6 +4942,11 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return new ArrayList<>(databaseStore.getSensitiveWord());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSensitiveOnlyMessage() {
|
||||
return mSensitiveOnlyMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WFCMessage.Message getMessage(long messageId) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
@@ -4836,6 +5013,16 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return mRobotCallbackWithTargetInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRobotMentionExternalRobot() {
|
||||
return mRobotMentionExternalRobot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRobotGetUserInfoMask() {
|
||||
return mRobotGetUserInfoMask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChannelCallbackWithClientInfo() {
|
||||
return mChannelCallbackWithClientInfo;
|
||||
|
||||
@@ -61,6 +61,7 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
private int deleted;
|
||||
|
||||
private boolean pullHistoryMsg;
|
||||
private String ip;
|
||||
|
||||
public int getDeleted() {
|
||||
return deleted;
|
||||
@@ -159,6 +160,14 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
}
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
private int pushType;
|
||||
private int platform;
|
||||
|
||||
@@ -544,6 +553,15 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
return session.clientSession;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSessionIp(String username, String clientID, String ip) {
|
||||
Session session = getSession(clientID);
|
||||
if(session != null && session.getDeleted() == 0) {
|
||||
session.setIp(ip);
|
||||
databaseStore.updateSessionIp(username, clientID, ip);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Session sessionForClientAndUser(String username, String clientID) {
|
||||
Session session = sessions.get(clientID);
|
||||
|
||||
@@ -331,6 +331,14 @@ public class Server {
|
||||
MediaServerConfig.QINIU_BUCKET_FAVORITE_NAME = config.getProperty(BrokerConstants.QINIU_BUCKET_FAVORITE_NAME);
|
||||
MediaServerConfig.QINIU_BUCKET_FAVORITE_DOMAIN = config.getProperty(BrokerConstants.QINIU_BUCKET_FAVORITE_DOMAIN);
|
||||
|
||||
MediaServerConfig.QINIU_BUCKET_CUSTOM1_NAME = config.getProperty(BrokerConstants.QINIU_BUCKET_CUSTOM1_NAME);
|
||||
MediaServerConfig.QINIU_BUCKET_CUSTOM1_DOMAIN = config.getProperty(BrokerConstants.QINIU_BUCKET_CUSTOM1_DOMAIN);
|
||||
|
||||
MediaServerConfig.QINIU_BUCKET_CUSTOM2_NAME = config.getProperty(BrokerConstants.QINIU_BUCKET_CUSTOM2_NAME);
|
||||
MediaServerConfig.QINIU_BUCKET_CUSTOM2_DOMAIN = config.getProperty(BrokerConstants.QINIU_BUCKET_CUSTOM2_DOMAIN);
|
||||
|
||||
MediaServerConfig.QINIU_BUCKET_CUSTOM3_NAME = config.getProperty(BrokerConstants.QINIU_BUCKET_CUSTOM3_NAME);
|
||||
MediaServerConfig.QINIU_BUCKET_CUSTOM3_DOMAIN = config.getProperty(BrokerConstants.QINIU_BUCKET_CUSTOM3_DOMAIN);
|
||||
|
||||
MediaServerConfig.SERVER_IP = getServerIp(config);
|
||||
|
||||
|
||||
@@ -23,7 +23,14 @@ public class MediaServerConfig {
|
||||
public static String QINIU_BUCKET_PORTRAIT_DOMAIN;
|
||||
public static String QINIU_BUCKET_FAVORITE_NAME;
|
||||
public static String QINIU_BUCKET_FAVORITE_DOMAIN;
|
||||
|
||||
public static String QINIU_BUCKET_CUSTOM1_NAME;
|
||||
public static String QINIU_BUCKET_CUSTOM1_DOMAIN;
|
||||
public static String QINIU_BUCKET_CUSTOM2_NAME;
|
||||
public static String QINIU_BUCKET_CUSTOM2_DOMAIN;
|
||||
public static String QINIU_BUCKET_CUSTOM3_NAME;
|
||||
public static String QINIU_BUCKET_CUSTOM3_DOMAIN;
|
||||
|
||||
|
||||
public static String SERVER_IP = "localhost";
|
||||
public static int HTTP_SERVER_PORT = 8080;
|
||||
public static String FILE_STROAGE_ROOT = "fs";
|
||||
|
||||
@@ -154,9 +154,10 @@ public interface IMessagesStore {
|
||||
WFCMessage.User getUserInfoByName(String name);
|
||||
WFCMessage.User getUserInfoByMobile(String mobile);
|
||||
List<WFCMessage.User> getUserInfosByEmail(String email);
|
||||
List<WFCMessage.User> searchUser(String keyword, int searchType, int userType, int page);
|
||||
ErrorCode searchUser(String userId, String keyword, int searchType, int userType, int page, List<WFCMessage.User> users);
|
||||
|
||||
List<WFCMessage.User> getUserInfoList(int count, int offset);
|
||||
List<String> getUserRobotIds(String userId);
|
||||
|
||||
boolean updateSystemSetting(int id, String value, String desc);
|
||||
SystemSettingPojo getSystemSetting(int id);
|
||||
@@ -190,6 +191,8 @@ public interface IMessagesStore {
|
||||
ErrorCode setFriendAliasRequest(String fromUser, String targetUserId, String alias, long[] head);
|
||||
ErrorCode setFriendExtraRequest(String fromUser, String targetUserId, String extra, long[] head);
|
||||
|
||||
boolean isAllowName(String name);
|
||||
|
||||
ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId);
|
||||
ErrorCode handleQuitChatroom(String userId, String clientId, String chatroomId);
|
||||
|
||||
@@ -232,6 +235,7 @@ public interface IMessagesStore {
|
||||
boolean addSensitiveWords(List<String> words);
|
||||
boolean removeSensitiveWords(List<String> words);
|
||||
List<String> getAllSensitiveWords();
|
||||
boolean isSensitiveOnlyMessage();
|
||||
|
||||
WFCMessage.Message getMessage(long messageId);
|
||||
|
||||
@@ -251,6 +255,8 @@ public interface IMessagesStore {
|
||||
boolean isRobotCallbackWithClientInfo();
|
||||
boolean isRobotCallbackWithSenderInfo();
|
||||
boolean isRobotCallbackWithTargetInfo();
|
||||
boolean isRobotMentionExternalRobot();
|
||||
int getRobotGetUserInfoMask();
|
||||
|
||||
boolean isChannelCallbackWithClientInfo();
|
||||
boolean isChannelCallbackWithSenderInfo();
|
||||
|
||||
@@ -43,7 +43,7 @@ public interface ISessionsStore {
|
||||
ErrorCode loadActiveSession(String username, String clientID);
|
||||
|
||||
ClientSession updateExistSession(String username, String clientID, WFCMessage.RouteRequest endpoint, boolean cleanSession);
|
||||
|
||||
void updateSessionIp(String username, String clientID, String ip);
|
||||
Session getSession(String clientID);
|
||||
|
||||
void cleanDuplatedToken(String cid, int pushType, String token, boolean isVoip, String packageName);
|
||||
|
||||
@@ -179,6 +179,7 @@ public class MessagesPublisher {
|
||||
message = m_messagesStore.getMessage(messageId);
|
||||
}
|
||||
OutputMessageData outputMessageData = getOutputMessageWithExtraInfo(message, exceptClientId, m_messagesStore.isRobotCallbackWithClientInfo() , m_messagesStore.isRobotCallbackWithSenderInfo(), m_messagesStore.isRobotCallbackWithTargetInfo());
|
||||
outputMessageData.setToRobotId(robot.getUid());
|
||||
Server.getServer().getCallbackScheduler().execute(() -> {
|
||||
try {
|
||||
HttpUtils.httpJsonPost(robot.getCallback(), GsonUtil.gson.toJson(outputMessageData, OutputMessageData.class), HttpUtils.HttpPostType.POST_TYPE_Robot_Message_Callback);
|
||||
@@ -230,6 +231,7 @@ public class MessagesPublisher {
|
||||
}
|
||||
}
|
||||
|
||||
boolean unreadCountIncreased = false;
|
||||
for (Session targetSession : sessions) {
|
||||
//超过7天不活跃的用户忽略
|
||||
if(System.currentTimeMillis() - targetSession.getLastActiveTime() > m_messagesStore.getPushExpiredTimes()) {
|
||||
@@ -314,8 +316,9 @@ public class MessagesPublisher {
|
||||
}
|
||||
|
||||
if (!StringUtil.isNullOrEmpty(pushContent) || messageContentType == 400) {
|
||||
if (!isConvSilent && (persistFlag & 0x02) > 0) {
|
||||
if (!isConvSilent && (persistFlag & 0x02) > 0 && !unreadCountIncreased) {
|
||||
m_messagesStore.increaseUnreceivedMsgCount(user);
|
||||
unreadCountIncreased = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ public class ProtocolProcessor {
|
||||
sessionstatus = 0;
|
||||
}
|
||||
|
||||
userOnlineStatus.sessions.add(new OutputCheckUserOnline.Session(userId, session.getClientID(), session.getPlatform(), sessionstatus, session.getLastActiveTime(), session.getAppName()));
|
||||
userOnlineStatus.sessions.add(new OutputCheckUserOnline.Session(userId, session.getClientID(), session.getPlatform(), sessionstatus, session.getLastActiveTime(), session.getAppName(), session.getIp()));
|
||||
}
|
||||
|
||||
HttpUtils.httpJsonPost(mUserOnlineStatusCallback, GsonUtil.gson.toJson(userOnlineStatus), HttpUtils.HttpPostType.POST_TYPE_User_Online_Event_Callback);
|
||||
|
||||
@@ -141,7 +141,7 @@ public class Qos1PublishHandler extends QosPublishHandler {
|
||||
status = 0;
|
||||
}
|
||||
|
||||
out.addSession(userId, session.getClientID(), session.getPlatform(), status, session.getLastActiveTime(), session.getAppName());
|
||||
out.addSession(userId, session.getClientID(), session.getPlatform(), status, session.getLastActiveTime(), session.getAppName(), session.getIp());
|
||||
}
|
||||
|
||||
callback.onRouteHandled(GsonUtil.gson.toJson(out).getBytes());
|
||||
|
||||
@@ -10,6 +10,7 @@ package win.liyufan.im;
|
||||
|
||||
public interface IMTopic {
|
||||
String SendMessageTopic = "MS";
|
||||
String RobotReplyMessageTopic = "RRM";
|
||||
String MultiCastMessageTopic = "MMC";
|
||||
String RecallMessageTopic = "MR";
|
||||
String RecallMultiCastMessageTopic = "MRMC";
|
||||
@@ -51,6 +52,7 @@ public interface IMTopic {
|
||||
String FriendRequestPullTopic = "FRP";
|
||||
String NotifyFriendRequestTopic = "FRN";
|
||||
String RriendRequestUnreadSyncTopic = "FRUS";
|
||||
String SetFriendExtraTopic = "FES";
|
||||
|
||||
String DeleteFriendTopic = "FDL";
|
||||
String FriendPullTopic = "FP";
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>1.3.7</version>
|
||||
<version>1.4.4</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public interface APIPath {
|
||||
String Get_Domain = "/admin/domain/get";
|
||||
String Destroy_Domain = "/admin/domain/destroy";
|
||||
String List_Domain = "/admin/domain/list";
|
||||
String Ping_Domain = "/admin/domain/ping";
|
||||
|
||||
String Create_User = "/admin/user/create";
|
||||
String Update_User = "/admin/user/update";
|
||||
@@ -37,6 +38,7 @@ public interface APIPath {
|
||||
String User_Get_Email_Info = "/admin/user/get_info_by_email";
|
||||
String User_Get_All = "/admin/user/all";
|
||||
String User_Get_Robot_Info = "/admin/user/get_robot_info";
|
||||
String User_Get_User_Robots = "/admin/user/get_user_robots";
|
||||
String User_Get_Blocked_List = "/admin/user/get_blocked_list";
|
||||
String User_Check_Block_Status = "/admin/user/check_block_status";
|
||||
String User_Get_Online_Status = "/admin/user/onlinestatus";
|
||||
@@ -94,6 +96,7 @@ public interface APIPath {
|
||||
String Group_Set_Manager = "/admin/group/manager/set";
|
||||
String Group_Mute_Member = "/admin/group/manager/mute";
|
||||
String Group_Allow_Member = "/admin/group/manager/allow";
|
||||
String Group_Join_Request_Add = "/admin/group/join_request/add";
|
||||
String Get_User_Groups = "/admin/group/of_user";
|
||||
String Get_User_Groups_By_Type = "/admin/group/of_user_by_type";
|
||||
String Group_Set_Member_Alias = "/admin/group/member/set_alias";
|
||||
@@ -113,6 +116,9 @@ public interface APIPath {
|
||||
String Put_System_Setting = "/admin/system/put_setting";
|
||||
String GET_CUSTOMER = "/admin/customer";
|
||||
String Health = "/admin/health";
|
||||
String Get_Conversation_Files = "/admin/file/conversation_files";
|
||||
String Get_User_Files = "/admin/file/user_files";
|
||||
String Get_Message_File = "/admin/file/message_file";
|
||||
|
||||
String Conference_List = "/admin/conference/list";
|
||||
String Conference_Exist = "/admin/conference/exist";
|
||||
@@ -128,6 +134,8 @@ public interface APIPath {
|
||||
String Channel_Update_Profile = "/channel/update_profile";
|
||||
String Channel_Get_Profile = "/channel/get_profile";
|
||||
String Channel_Message_Send = "/channel/message/send";
|
||||
String Channel_Msg_Recall = "/channel/message/recall";
|
||||
String Channel_Msg_Republish = "/channel/message/republish";
|
||||
String Channel_Subscribe = "/channel/subscribe";
|
||||
String Channel_Subscriber_List = "/channel/subscriber_list";
|
||||
String Channel_Is_Subscriber = "/channel/is_subscriber";
|
||||
@@ -136,6 +144,7 @@ public interface APIPath {
|
||||
String Robot_User_Info = "/robot/user_info";
|
||||
String Robot_Get_Profile = "/robot/profile";
|
||||
String Robot_Message_Send = "/robot/message/send";
|
||||
String Robot_Message_Reply = "/robot/message/reply";
|
||||
String Robot_Message_Recall = "/robot/message/recall";
|
||||
String Robot_Message_Update = "/robot/message/update";
|
||||
String Robot_Set_Callback = "/robot/set_callback";
|
||||
|
||||
@@ -49,6 +49,7 @@ public enum ErrorCode {
|
||||
ERROR_CODE_ROBOT_NO_TOKEN(27, "robot no token"),
|
||||
ERROR_CODE_WS_NOT_CONFIGURED_CORRECTLY(28, "ws not configured correctly"),
|
||||
ERROR_CODE_TIME_INCONSISTENT(30, "time inconsistent"),
|
||||
ERROR_CODE_MESSAGE_TOO_LARGE(35, "message too large"),
|
||||
ERROR_CODE_CONFERENCE_ROOM_NOT_EXIST(60, "conference room not exist"),
|
||||
ERROR_CODE_CONFERENCE_SERVICE_NOT_AVAILABLE(61, "conference service not available"),
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FilesPojo {
|
||||
public int total;
|
||||
public List<FilePojo> files;
|
||||
public static class FilePojo {
|
||||
public long messageId;
|
||||
public String sender;
|
||||
public int conversationType;
|
||||
public String target;
|
||||
public int line;
|
||||
public String name;
|
||||
public String url;
|
||||
public int size;
|
||||
public int downloadCount;
|
||||
public long timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
public class GetConversationFilesPojo {
|
||||
public int conversationType;
|
||||
public String target;
|
||||
public int line;
|
||||
public String userId;
|
||||
public int offset;
|
||||
public boolean desc;
|
||||
public int count;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ public class GetOnlineUserResult {
|
||||
public String userId;
|
||||
public String clientId;
|
||||
public int platform;
|
||||
public String ip;
|
||||
}
|
||||
|
||||
public ArrayList<GetOnlineUserResult.UserClient> userClients;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
public class GetUserFilesPojo {
|
||||
public String userId;
|
||||
public int offset;
|
||||
public boolean desc;
|
||||
public int count;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
public class InputCountOffset {
|
||||
public int count;
|
||||
public int offset;
|
||||
}
|
||||
@@ -25,6 +25,7 @@ public class InputOutputUserInfo {
|
||||
private String social;
|
||||
private String extra;
|
||||
private int type;
|
||||
private int deleted;
|
||||
private long updateDt;
|
||||
|
||||
public static InputOutputUserInfo fromPbUser(WFCMessage.User pbUser) {
|
||||
@@ -42,6 +43,7 @@ public class InputOutputUserInfo {
|
||||
inputCreateUser.extra = pbUser.getExtra();
|
||||
inputCreateUser.type = pbUser.getType();
|
||||
inputCreateUser.updateDt = pbUser.getUpdateDt();
|
||||
inputCreateUser.deleted = pbUser.getDeleted();
|
||||
return inputCreateUser;
|
||||
}
|
||||
|
||||
@@ -77,6 +79,7 @@ public class InputOutputUserInfo {
|
||||
newUserBuilder.setExtra(getExtra());
|
||||
newUserBuilder.setGender(gender);
|
||||
newUserBuilder.setType(type);
|
||||
newUserBuilder.setDeleted(deleted);
|
||||
|
||||
newUserBuilder.setUpdateDt(System.currentTimeMillis());
|
||||
return newUserBuilder.build();
|
||||
@@ -185,4 +188,24 @@ public class InputOutputUserInfo {
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(int deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" +
|
||||
"userId='" + userId + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", displayName='" + displayName + '\'' +
|
||||
", portrait='" + portrait + '\'' +
|
||||
", mobile='" + mobile + '\'' +
|
||||
", updateDt=" + updateDt +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
public class LongPojo {
|
||||
public long value;
|
||||
}
|
||||
@@ -20,22 +20,24 @@ public class OutputCheckUserOnline {
|
||||
public int status; //0 online, 1 have session offline
|
||||
public long lastSeen;
|
||||
public String packageName;
|
||||
public String ip;
|
||||
|
||||
public Session() {
|
||||
}
|
||||
|
||||
public Session(String clientId, String userId, int platform, int status, long lastSeen, String packageName) {
|
||||
public Session(String clientId, String userId, int platform, int status, long lastSeen, String packageName, String ip) {
|
||||
this.clientId = clientId;
|
||||
this.userId = userId;
|
||||
this.platform = platform;
|
||||
this.status = status;
|
||||
this.lastSeen = lastSeen;
|
||||
this.packageName = packageName;
|
||||
this.ip = ip;
|
||||
}
|
||||
}
|
||||
|
||||
public void addSession(String userId, String clientId, int platform, int status, long lastSeen, String packageName) {
|
||||
Session session = new Session(clientId, userId, platform, status, lastSeen, packageName);
|
||||
public void addSession(String userId, String clientId, int platform, int status, long lastSeen, String packageName, String ip) {
|
||||
Session session = new Session(clientId, userId, platform, status, lastSeen, packageName, ip);
|
||||
sessions.add(session);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ public class OutputMessageData {
|
||||
private PojoGroupInfo targetGroupInfo;
|
||||
private OutputGetChannelInfo targetChannelInfo;
|
||||
|
||||
private String toRobotId;
|
||||
|
||||
public String getSender() {
|
||||
return sender;
|
||||
}
|
||||
@@ -119,6 +121,14 @@ public class OutputMessageData {
|
||||
return fromProtoMessage(protoMessage, null);
|
||||
}
|
||||
|
||||
public String getToRobotId() {
|
||||
return toRobotId;
|
||||
}
|
||||
|
||||
public void setToRobotId(String toRobotId) {
|
||||
this.toRobotId = toRobotId;
|
||||
}
|
||||
|
||||
public static OutputMessageData fromProtoMessage(WFCMessage.Message protoMessage, OutputClient fromClient) {
|
||||
OutputMessageData data = new OutputMessageData();
|
||||
data.messageId = protoMessage.getMessageId();
|
||||
|
||||
@@ -2,11 +2,8 @@ package cn.wildfirechat.pojos;
|
||||
|
||||
public class PojoConferenceInfo {
|
||||
public String roomId;
|
||||
public String serverId;
|
||||
public String description;
|
||||
public int max_publishers;
|
||||
public int num_publishers;
|
||||
public int bitrate;
|
||||
public boolean advance;
|
||||
public boolean recording;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReplyMessageData {
|
||||
private long messageUid;
|
||||
private MessagePayload payload;
|
||||
private boolean only2Sender;
|
||||
|
||||
public long getMessageUid() {
|
||||
return messageUid;
|
||||
}
|
||||
|
||||
public void setMessageUid(long messageUid) {
|
||||
this.messageUid = messageUid;
|
||||
}
|
||||
|
||||
public MessagePayload getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(MessagePayload payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public boolean isOnly2Sender() {
|
||||
return only2Sender;
|
||||
}
|
||||
|
||||
public void setOnly2Sender(boolean only2Sender) {
|
||||
this.only2Sender = only2Sender;
|
||||
}
|
||||
|
||||
public static boolean isValide(ReplyMessageData sendMessageData) {
|
||||
if(sendMessageData.messageUid <=0 ||
|
||||
sendMessageData.getPayload() == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RepublishChannelMessageData {
|
||||
private List<String> targets;
|
||||
private long messageId;
|
||||
|
||||
public List<String> getTargets() {
|
||||
return targets;
|
||||
}
|
||||
|
||||
public void setTargets(List<String> targets) {
|
||||
this.targets = targets;
|
||||
}
|
||||
|
||||
public long getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
public void setMessageId(long messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public class SendMessageData {
|
||||
private MessagePayload payload;
|
||||
private List<String> toUsers;
|
||||
private boolean isMeshMessage;
|
||||
private boolean isUserMessage;
|
||||
|
||||
public String getSender() {
|
||||
return sender;
|
||||
@@ -61,6 +62,14 @@ public class SendMessageData {
|
||||
isMeshMessage = meshMessage;
|
||||
}
|
||||
|
||||
public boolean isUserMessage() {
|
||||
return isUserMessage;
|
||||
}
|
||||
|
||||
public void setUserMessage(boolean userMessage) {
|
||||
isUserMessage = userMessage;
|
||||
}
|
||||
|
||||
public static boolean isValide(SendMessageData sendMessageData) {
|
||||
if(sendMessageData == null ||
|
||||
sendMessageData.getConv() == null ||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package cn.wildfirechat.pojos.mesh;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PojoAddJoinGroupRequest {
|
||||
public String domainId;
|
||||
public String operator;
|
||||
public String group_id;
|
||||
public List<String> userIds;
|
||||
public String reason;
|
||||
public String extra;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos.mesh;
|
||||
|
||||
|
||||
public class PojoDomainPingRequest {
|
||||
public String domainId;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos.mesh;
|
||||
|
||||
|
||||
public class PojoDomainPingResponse {
|
||||
public boolean success;
|
||||
public String errorMessage;
|
||||
public String myDomainName;
|
||||
}
|
||||
@@ -226,6 +226,7 @@ public class ProtoConstants {
|
||||
|
||||
public interface SystemSettingType {
|
||||
int Group_Max_Member_Count = 1;
|
||||
int NOT_ALLOW_USER_NAMES = 2;
|
||||
}
|
||||
|
||||
public interface SearchUserType {
|
||||
|
||||
@@ -67311,6 +67311,641 @@ public final class WFCMessage {
|
||||
// @@protoc_insertion_point(class_scope:ApplicationConfigRequest)
|
||||
}
|
||||
|
||||
public interface StringPairOrBuilder
|
||||
extends com.google.protobuf.MessageOrBuilder {
|
||||
|
||||
// required string key = 1;
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
boolean hasKey();
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
java.lang.String getKey();
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
com.google.protobuf.ByteString
|
||||
getKeyBytes();
|
||||
|
||||
// optional string value = 2;
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
boolean hasValue();
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
java.lang.String getValue();
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
com.google.protobuf.ByteString
|
||||
getValueBytes();
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code StringPair}
|
||||
*/
|
||||
public static final class StringPair extends
|
||||
com.google.protobuf.GeneratedMessage
|
||||
implements StringPairOrBuilder {
|
||||
// Use StringPair.newBuilder() to construct.
|
||||
private StringPair(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
|
||||
super(builder);
|
||||
this.unknownFields = builder.getUnknownFields();
|
||||
}
|
||||
private StringPair(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
|
||||
|
||||
private static final StringPair defaultInstance;
|
||||
public static StringPair getDefaultInstance() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
public StringPair getDefaultInstanceForType() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
private final com.google.protobuf.UnknownFieldSet unknownFields;
|
||||
@java.lang.Override
|
||||
public final com.google.protobuf.UnknownFieldSet
|
||||
getUnknownFields() {
|
||||
return this.unknownFields;
|
||||
}
|
||||
private StringPair(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
initFields();
|
||||
int mutable_bitField0_ = 0;
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||
com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
default: {
|
||||
if (!parseUnknownField(input, unknownFields,
|
||||
extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 10: {
|
||||
bitField0_ |= 0x00000001;
|
||||
key_ = input.readBytes();
|
||||
break;
|
||||
}
|
||||
case 18: {
|
||||
bitField0_ |= 0x00000002;
|
||||
value_ = input.readBytes();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(this);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(
|
||||
e.getMessage()).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
makeExtensionsImmutable();
|
||||
}
|
||||
}
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return cn.wildfirechat.proto.WFCMessage.internal_static_StringPair_descriptor;
|
||||
}
|
||||
|
||||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return cn.wildfirechat.proto.WFCMessage.internal_static_StringPair_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
cn.wildfirechat.proto.WFCMessage.StringPair.class, cn.wildfirechat.proto.WFCMessage.StringPair.Builder.class);
|
||||
}
|
||||
|
||||
public static com.google.protobuf.Parser<StringPair> PARSER =
|
||||
new com.google.protobuf.AbstractParser<StringPair>() {
|
||||
public StringPair parsePartialFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return new StringPair(input, extensionRegistry);
|
||||
}
|
||||
};
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Parser<StringPair> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
private int bitField0_;
|
||||
// required string key = 1;
|
||||
public static final int KEY_FIELD_NUMBER = 1;
|
||||
private java.lang.Object key_;
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
public boolean hasKey() {
|
||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||
}
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
public java.lang.String getKey() {
|
||||
java.lang.Object ref = key_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
return (java.lang.String) ref;
|
||||
} else {
|
||||
com.google.protobuf.ByteString bs =
|
||||
(com.google.protobuf.ByteString) ref;
|
||||
java.lang.String s = bs.toStringUtf8();
|
||||
if (bs.isValidUtf8()) {
|
||||
key_ = s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
public com.google.protobuf.ByteString
|
||||
getKeyBytes() {
|
||||
java.lang.Object ref = key_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
com.google.protobuf.ByteString b =
|
||||
com.google.protobuf.ByteString.copyFromUtf8(
|
||||
(java.lang.String) ref);
|
||||
key_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (com.google.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
|
||||
// optional string value = 2;
|
||||
public static final int VALUE_FIELD_NUMBER = 2;
|
||||
private java.lang.Object value_;
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
public boolean hasValue() {
|
||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||
}
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
public java.lang.String getValue() {
|
||||
java.lang.Object ref = value_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
return (java.lang.String) ref;
|
||||
} else {
|
||||
com.google.protobuf.ByteString bs =
|
||||
(com.google.protobuf.ByteString) ref;
|
||||
java.lang.String s = bs.toStringUtf8();
|
||||
if (bs.isValidUtf8()) {
|
||||
value_ = s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
public com.google.protobuf.ByteString
|
||||
getValueBytes() {
|
||||
java.lang.Object ref = value_;
|
||||
if (ref instanceof java.lang.String) {
|
||||
com.google.protobuf.ByteString b =
|
||||
com.google.protobuf.ByteString.copyFromUtf8(
|
||||
(java.lang.String) ref);
|
||||
value_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (com.google.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
key_ = "";
|
||||
value_ = "";
|
||||
}
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized != -1) return isInitialized == 1;
|
||||
|
||||
if (!hasKey()) {
|
||||
memoizedIsInitialized = 0;
|
||||
return false;
|
||||
}
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
getSerializedSize();
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
output.writeBytes(1, getKeyBytes());
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
output.writeBytes(2, getValueBytes());
|
||||
}
|
||||
getUnknownFields().writeTo(output);
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeBytesSize(1, getKeyBytes());
|
||||
}
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeBytesSize(2, getValueBytes());
|
||||
}
|
||||
size += getUnknownFields().getSerializedSize();
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
@java.lang.Override
|
||||
protected java.lang.Object writeReplace()
|
||||
throws java.io.ObjectStreamException {
|
||||
return super.writeReplace();
|
||||
}
|
||||
|
||||
public static cn.wildfirechat.proto.WFCMessage.StringPair parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static cn.wildfirechat.proto.WFCMessage.StringPair parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static cn.wildfirechat.proto.WFCMessage.StringPair parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static cn.wildfirechat.proto.WFCMessage.StringPair parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static cn.wildfirechat.proto.WFCMessage.StringPair parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input);
|
||||
}
|
||||
public static cn.wildfirechat.proto.WFCMessage.StringPair parseFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input, extensionRegistry);
|
||||
}
|
||||
public static cn.wildfirechat.proto.WFCMessage.StringPair parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseDelimitedFrom(input);
|
||||
}
|
||||
public static cn.wildfirechat.proto.WFCMessage.StringPair parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseDelimitedFrom(input, extensionRegistry);
|
||||
}
|
||||
public static cn.wildfirechat.proto.WFCMessage.StringPair parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input);
|
||||
}
|
||||
public static cn.wildfirechat.proto.WFCMessage.StringPair parseFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return PARSER.parseFrom(input, extensionRegistry);
|
||||
}
|
||||
|
||||
public static Builder newBuilder() { return Builder.create(); }
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder(cn.wildfirechat.proto.WFCMessage.StringPair prototype) {
|
||||
return newBuilder().mergeFrom(prototype);
|
||||
}
|
||||
public Builder toBuilder() { return newBuilder(this); }
|
||||
|
||||
@java.lang.Override
|
||||
protected Builder newBuilderForType(
|
||||
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code StringPair}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessage.Builder<Builder>
|
||||
implements cn.wildfirechat.proto.WFCMessage.StringPairOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return cn.wildfirechat.proto.WFCMessage.internal_static_StringPair_descriptor;
|
||||
}
|
||||
|
||||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return cn.wildfirechat.proto.WFCMessage.internal_static_StringPair_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
cn.wildfirechat.proto.WFCMessage.StringPair.class, cn.wildfirechat.proto.WFCMessage.StringPair.Builder.class);
|
||||
}
|
||||
|
||||
// Construct using cn.wildfirechat.proto.WFCMessage.StringPair.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
|
||||
}
|
||||
}
|
||||
private static Builder create() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
key_ = "";
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
value_ = "";
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder clone() {
|
||||
return create().mergeFrom(buildPartial());
|
||||
}
|
||||
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return cn.wildfirechat.proto.WFCMessage.internal_static_StringPair_descriptor;
|
||||
}
|
||||
|
||||
public cn.wildfirechat.proto.WFCMessage.StringPair getDefaultInstanceForType() {
|
||||
return cn.wildfirechat.proto.WFCMessage.StringPair.getDefaultInstance();
|
||||
}
|
||||
|
||||
public cn.wildfirechat.proto.WFCMessage.StringPair build() {
|
||||
cn.wildfirechat.proto.WFCMessage.StringPair result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public cn.wildfirechat.proto.WFCMessage.StringPair buildPartial() {
|
||||
cn.wildfirechat.proto.WFCMessage.StringPair result = new cn.wildfirechat.proto.WFCMessage.StringPair(this);
|
||||
int from_bitField0_ = bitField0_;
|
||||
int to_bitField0_ = 0;
|
||||
if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
to_bitField0_ |= 0x00000001;
|
||||
}
|
||||
result.key_ = key_;
|
||||
if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
to_bitField0_ |= 0x00000002;
|
||||
}
|
||||
result.value_ = value_;
|
||||
result.bitField0_ = to_bitField0_;
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||
if (other instanceof cn.wildfirechat.proto.WFCMessage.StringPair) {
|
||||
return mergeFrom((cn.wildfirechat.proto.WFCMessage.StringPair)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(cn.wildfirechat.proto.WFCMessage.StringPair other) {
|
||||
if (other == cn.wildfirechat.proto.WFCMessage.StringPair.getDefaultInstance()) return this;
|
||||
if (other.hasKey()) {
|
||||
bitField0_ |= 0x00000001;
|
||||
key_ = other.key_;
|
||||
onChanged();
|
||||
}
|
||||
if (other.hasValue()) {
|
||||
bitField0_ |= 0x00000002;
|
||||
value_ = other.value_;
|
||||
onChanged();
|
||||
}
|
||||
this.mergeUnknownFields(other.getUnknownFields());
|
||||
return this;
|
||||
}
|
||||
|
||||
public final boolean isInitialized() {
|
||||
if (!hasKey()) {
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
cn.wildfirechat.proto.WFCMessage.StringPair parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
parsedMessage = (cn.wildfirechat.proto.WFCMessage.StringPair) e.getUnfinishedMessage();
|
||||
throw e;
|
||||
} finally {
|
||||
if (parsedMessage != null) {
|
||||
mergeFrom(parsedMessage);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private int bitField0_;
|
||||
|
||||
// required string key = 1;
|
||||
private java.lang.Object key_ = "";
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
public boolean hasKey() {
|
||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||
}
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
public java.lang.String getKey() {
|
||||
java.lang.Object ref = key_;
|
||||
if (!(ref instanceof java.lang.String)) {
|
||||
java.lang.String s = ((com.google.protobuf.ByteString) ref)
|
||||
.toStringUtf8();
|
||||
key_ = s;
|
||||
return s;
|
||||
} else {
|
||||
return (java.lang.String) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
public com.google.protobuf.ByteString
|
||||
getKeyBytes() {
|
||||
java.lang.Object ref = key_;
|
||||
if (ref instanceof String) {
|
||||
com.google.protobuf.ByteString b =
|
||||
com.google.protobuf.ByteString.copyFromUtf8(
|
||||
(java.lang.String) ref);
|
||||
key_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (com.google.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
public Builder setKey(
|
||||
java.lang.String value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000001;
|
||||
key_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
public Builder clearKey() {
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
key_ = getDefaultInstance().getKey();
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>required string key = 1;</code>
|
||||
*/
|
||||
public Builder setKeyBytes(
|
||||
com.google.protobuf.ByteString value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000001;
|
||||
key_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
// optional string value = 2;
|
||||
private java.lang.Object value_ = "";
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
public boolean hasValue() {
|
||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||
}
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
public java.lang.String getValue() {
|
||||
java.lang.Object ref = value_;
|
||||
if (!(ref instanceof java.lang.String)) {
|
||||
java.lang.String s = ((com.google.protobuf.ByteString) ref)
|
||||
.toStringUtf8();
|
||||
value_ = s;
|
||||
return s;
|
||||
} else {
|
||||
return (java.lang.String) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
public com.google.protobuf.ByteString
|
||||
getValueBytes() {
|
||||
java.lang.Object ref = value_;
|
||||
if (ref instanceof String) {
|
||||
com.google.protobuf.ByteString b =
|
||||
com.google.protobuf.ByteString.copyFromUtf8(
|
||||
(java.lang.String) ref);
|
||||
value_ = b;
|
||||
return b;
|
||||
} else {
|
||||
return (com.google.protobuf.ByteString) ref;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
public Builder setValue(
|
||||
java.lang.String value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000002;
|
||||
value_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
public Builder clearValue() {
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
value_ = getDefaultInstance().getValue();
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional string value = 2;</code>
|
||||
*/
|
||||
public Builder setValueBytes(
|
||||
com.google.protobuf.ByteString value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
bitField0_ |= 0x00000002;
|
||||
value_ = value;
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:StringPair)
|
||||
}
|
||||
|
||||
static {
|
||||
defaultInstance = new StringPair(true);
|
||||
defaultInstance.initFields();
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:StringPair)
|
||||
}
|
||||
|
||||
private static com.google.protobuf.Descriptors.Descriptor
|
||||
internal_static_AddFriendRequest_descriptor;
|
||||
private static
|
||||
@@ -67691,6 +68326,11 @@ public final class WFCMessage {
|
||||
private static
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internal_static_ApplicationConfigRequest_fieldAccessorTable;
|
||||
private static com.google.protobuf.Descriptors.Descriptor
|
||||
internal_static_StringPair_descriptor;
|
||||
private static
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internal_static_StringPair_fieldAccessorTable;
|
||||
|
||||
public static com.google.protobuf.Descriptors.FileDescriptor
|
||||
getDescriptor() {
|
||||
@@ -67877,9 +68517,10 @@ public final class WFCMessage {
|
||||
"rget_id\030\001 \002(\t\022\014\n\004type\030\002 \002(\005\022\014\n\004host\030\003 \002(" +
|
||||
"\t\"o\n\030ApplicationConfigRequest\022\r\n\005appId\030\001" +
|
||||
" \002(\t\022\017\n\007appType\030\002 \002(\005\022\021\n\ttimestamp\030\003 \002(\003" +
|
||||
"\022\r\n\005nonce\030\004 \002(\t\022\021\n\tsignature\030\005 \002(\tB/\n\025cn" +
|
||||
".wildfirechat.protoB\nWFCMessageZ\n./go;pr" +
|
||||
"oto"
|
||||
"\022\r\n\005nonce\030\004 \002(\t\022\021\n\tsignature\030\005 \002(\t\"(\n\nSt" +
|
||||
"ringPair\022\013\n\003key\030\001 \002(\t\022\r\n\005value\030\002 \001(\tB/\n\025" +
|
||||
"cn.wildfirechat.protoB\nWFCMessageZ\n./go;",
|
||||
"proto"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
@@ -68342,6 +68983,12 @@ public final class WFCMessage {
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_ApplicationConfigRequest_descriptor,
|
||||
new java.lang.String[] { "AppId", "AppType", "Timestamp", "Nonce", "Signature", });
|
||||
internal_static_StringPair_descriptor =
|
||||
getDescriptor().getMessageTypes().get(76);
|
||||
internal_static_StringPair_fieldAccessorTable = new
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_StringPair_descriptor,
|
||||
new java.lang.String[] { "Key", "Value", });
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<!--<relativePath>../pom.xml</relativePath>-->
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>1.3.7</version>
|
||||
<version>1.4.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>distribution</artifactId>
|
||||
|
||||
@@ -167,6 +167,16 @@ robot.callback_with_sender_info false
|
||||
## 机器人回调信息是否带上目标的信息,单聊时是对方用户信息,群聊时是群组信息,频道时是频道信息
|
||||
robot.callback_with_target_info false
|
||||
|
||||
## 是否允许@会话外的机器人。如果为true,单聊或者群聊时,可以@不在会话中的机器人。当机器人收到消息后,可以回复消息。
|
||||
## 如果为false,不能@不在会话中的机器人。机器人不在会话中时,也不能回复消息。
|
||||
robot.mention_external_robot true
|
||||
|
||||
## 机器人获取信息允许的字段,可以获取userId/displayName/portrait,其他需要这里配置允许。
|
||||
## 第一位(1)是name, 第二位(2)是mobile,第三(4)位是email,第四位(8)是address,第五位(16)是company,第六位(32)是extra,
|
||||
## 第七位(64)是updateDt,第八位(128)是gender,第九位(256)是social,第十位(512)是type。
|
||||
## 比如允许获取name和email就是5(1+4),允许获取name和mobile和company和type就是531(1+2+16+512),允许全部是1023(1+2+...+512)
|
||||
#robot.get_user_info_mask 1023
|
||||
|
||||
## 频道回调信息是否带上用户clientId和平台类型。
|
||||
channel.callback_with_client_info false
|
||||
|
||||
@@ -186,8 +196,8 @@ friend.disable_search false
|
||||
##禁止按照昵称搜索用户。
|
||||
friend.disable_nick_name_search false
|
||||
|
||||
##禁止按照用户id搜索用户,默认为true。
|
||||
friend.disable_user_id_search true
|
||||
##禁止按照用户id搜索用户,默认为false。
|
||||
friend.disable_user_id_search false
|
||||
|
||||
##禁止发送好友邀请,通过server api添加好友不受此限制(force参数需要为true)
|
||||
friend.disable_friend_request false
|
||||
@@ -202,7 +212,13 @@ friend.reject_request_duration 2592000000
|
||||
friend.request_expiration_duration 604800000
|
||||
|
||||
##好友请求限制频率,一个用户24小时之内允许请求好友的次数,默认不限频。
|
||||
#friend.request_rate_limit 30
|
||||
friend.request_rate_limit 30
|
||||
|
||||
##如果搜索电话号码,24小时内搜索错误号码几次就不再允许电话号码搜素。防止有人遍历搜索电话号码
|
||||
friend.search_mobile_empty_rate_limit 5
|
||||
|
||||
##如果搜索用户,24小时内搜索次数。防止有人遍历用户名或者用户ID乱加好友。另外可以禁止ID搜索friend.disable_user_id_search
|
||||
friend.search_rate_limit 100
|
||||
|
||||
##请求添加机器人为好友时,机器人是否自动接受,默认为true
|
||||
friend.robot_auto_accept true
|
||||
@@ -258,6 +274,19 @@ group.enable_mark_deletion true
|
||||
## 注意,修改本配置不会对已经同步的信息产生影响。
|
||||
#user.hide_properties 3,4
|
||||
|
||||
## 销毁用户时,用户信息会被清空,deleted字段设置为1,这个开关控制是否保留用户昵称,默认为true。
|
||||
user.keep_display_name_when_destroy true
|
||||
|
||||
## 销毁用户时deleted字段设置为1,这个开关控制是否保留其他信息,默认是false。
|
||||
user.keep_full_info_when_destroy false
|
||||
|
||||
## 销毁用户时,如果user.keep_full_info_when_destroy为true,会保留所有信息,这个开关控制是否保留这个用户信息的电话号码,默认为false。
|
||||
## 当保留所有信息且保留电话号码时,用户如果再注册会用到原来的UID,能够看到原来用户的消息,需要考虑一下是否让已删除用户再次注册登录看到之前的消息。
|
||||
user.keep_mobile_when_destroy false
|
||||
|
||||
## 销毁用户时是否保留归属于这个用户的所有消息记录,默认为false。
|
||||
user.keep_messages_when_destroy false
|
||||
|
||||
# 好友/好友请求/用户设置 这三类数据同步的最大条目数。之前是客户第一次登录时,会把所有的对应数据一次下载到客户端,但如果有特别多的信息,会导致无法同步到客户端,
|
||||
# 因此需要分段多次同步,此开关定义了每次同步的数据的条数。此需要客户端支持,客户端SDK在2021.5.25日后支持此功能。如果确认所有客户端都在这个日志之后才可以打开此设置。
|
||||
#sync.data_part_size 1000
|
||||
@@ -311,6 +340,13 @@ qiniu.bucket_portrait_name storage
|
||||
qiniu.bucket_portrait_domain http://cdn2.wildfirechat.cn
|
||||
qiniu.bucket_favorite_name storage
|
||||
qiniu.bucket_favorite_domain http://cdn2.wildfirechat.cn
|
||||
## custom的桶是给客户预留的,客户可以上传自己的文件到这3个桶中,野火不会用到这几个桶。如果不需要,可以忽略这几个配置
|
||||
qiniu.bucket_custom1_name temp1
|
||||
qiniu.bucket_custom1_domain http://temp1.wildfirechat.cn
|
||||
qiniu.bucket_custom2_name temp2
|
||||
qiniu.bucket_custom2_domain http://temp2.wildfirechat.cn
|
||||
qiniu.bucket_custom3_name temp3
|
||||
qiniu.bucket_custom3_domain http://temp3.wildfirechat.cn
|
||||
|
||||
##媒体类型分类
|
||||
#Media_Type_GENERAL = 0,
|
||||
@@ -455,6 +491,10 @@ push.harmony.server.address http://localhost:8085/harmony/push
|
||||
## 如果开启 message.sensitive.forward.url 配置,命中敏感词的消息还会被回调到这个地址
|
||||
sensitive.filter.type 2
|
||||
|
||||
## 敏感词是否只处理消息。如果为true,只过滤消息;如果为false,会同时过滤用户昵称、群组名和群昵称。
|
||||
## 除了消息之外的信息只支持内部敏感词处理,不支持外置审核。
|
||||
sensitive.only_message false
|
||||
|
||||
## 敏感词添加或者删除有2种方式,一种是通过Server API进行,这种方式会立即生效。另外一种方法是修改数据库,直接中数据库的t_sensitive_word表中处理
|
||||
## 修改数据库的方法不会立即生效,IM服务会2个小时重新加载一次敏感词。所以如果直接修改敏感词表,需要等2个小时,或者重启才能生效。
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
<version>1.3.7</version>
|
||||
<version>1.4.4</version>
|
||||
<name>Wildfire Chat</name>
|
||||
<description>Wildfire Chat Server</description>
|
||||
<inceptionYear>2019</inceptionYear>
|
||||
|
||||
@@ -9,8 +9,59 @@
|
||||
8. *** 从0.78 版本起把MySQL数据库中关键字都改为大小写敏感,另外生成id的方法也做了改变,只生成小写的id,避免出现id重复的问题,建议所有客户都升级 ***
|
||||
9. *** 从0.79 版本起把log4j升级到log4j2,因为log4j已经不再维护而且还有已知的漏洞,建议所有客户都升级,升级时注意更新log4j2的配置文件 ***
|
||||
10. *** 0.97版本更改了启动脚本```wildfirechat.sh```,如果是升级服务,请注意更新启动脚本。***
|
||||
11. *** 1.3.8版本添加了server api发送消息的限制,限制消息体最大内容不能超过64KB,如果升级请注意业务系统发送消息大小。***
|
||||
|
||||
# 更新记录
|
||||
--------------
|
||||
Release note 1.4.4:
|
||||
1. Server SDK添加mesh相关修改
|
||||
2. 添加设置好友Extra的接口。
|
||||
3. 解决创建账户时,没有传昵称使用了账户的问题。
|
||||
4. 添加获取用户机器人列表的Server API。
|
||||
5. 机器人回调消息中加上目标机器人ID。
|
||||
6. 机器人获取用户信息添加配置确定能获取哪些字段。
|
||||
|
||||
--------------
|
||||
Release note 1.4.3:
|
||||
1. 添加内置存储上传文件文件名有效性检查。
|
||||
2. 接受好友请求通知的发送者改成接受者发送。
|
||||
3. 对象存储添加预留类型供扩展使用。
|
||||
4. 同步专业版数据库表格式。
|
||||
5. 解决server sdk有轻微内存泄漏的问题。
|
||||
|
||||
--------------
|
||||
Release note 1.4.2:
|
||||
1. 解决部分情况下Server SDK没有解析出文本消息的问题。
|
||||
|
||||
--------------
|
||||
Release note 1.4.1:
|
||||
1. 解决移动端和PAD同时存在时推送计数错误问题。
|
||||
2. 添加配置,当销毁用户时是否销毁用户信息和用户的消息。
|
||||
3. 添加配置,现在搜索用户的次数。
|
||||
|
||||
--------------
|
||||
Release note 1.4.0:
|
||||
1. 添加对用户IP来源的记录。
|
||||
2. 移除无用的plugin,可以在java8环境下编译通过。
|
||||
3. Server SDK解决某些Java版本下消息没有注册的问题。
|
||||
4. Server SDK解决解析图片缩略图不存在的错误问题。
|
||||
5. Server SDK解决发送带引用的消息客户端无法解析的问题。
|
||||
|
||||
--------------
|
||||
Release note 1.3.9:
|
||||
1. 解决server sdk反复初始化内存泄漏的问题。
|
||||
2. 群组支持用户@不在群组中的机器人。
|
||||
3. 单聊会话支持@机器人。
|
||||
4. 机器人支持回复消息,可以回复单聊或者群聊消息。
|
||||
|
||||
--------------
|
||||
Release note 1.3.8:
|
||||
1. 添加限制,server api发送消息,限制消息体不能大于64KB。
|
||||
2. 添加配置敏感词是否过滤用户信息群组信息昵称等。
|
||||
3. 配置文件可以设置不允许使用的用户名字群组名称群名片等。
|
||||
4. server api发送消息添加参数,可以以用户权限发送消息。
|
||||
5. server api添加群备注和收藏群组接口。
|
||||
|
||||
--------------
|
||||
Release note 1.3.7:
|
||||
1. 搜索用户可以指定搜索机器人、普通用户或者所有。
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>wildfirechat-parent</artifactId>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<version>1.3.7</version>
|
||||
<version>1.4.4</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -4,16 +4,19 @@ import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.pojos.*;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
import cn.wildfirechat.sdk.utilities.ChannelHttpUtils;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ApplicationType.ApplicationType_Channel;
|
||||
|
||||
//仅专业版支持,社区版不支持
|
||||
public class ChannelServiceApi {
|
||||
public class ChannelServiceApi implements Closeable {
|
||||
private final ChannelHttpUtils channelHttpUtils;
|
||||
|
||||
public ChannelServiceApi(String imurl, String channelId, String secret) {
|
||||
@@ -65,6 +68,21 @@ public class ChannelServiceApi {
|
||||
return channelHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||
}
|
||||
|
||||
public IMResult<String> recallMessage(long messageUid) throws Exception {
|
||||
String path = APIPath.Channel_Msg_Recall;
|
||||
RecallMessageData messageData = new RecallMessageData();
|
||||
messageData.setMessageUid(messageUid);
|
||||
return channelHttpUtils.httpJsonPost(path, messageData, String.class);
|
||||
}
|
||||
|
||||
public IMResult<Void> republishMessage(long messageUid, List<String> targets) throws Exception {
|
||||
String path = APIPath.Channel_Msg_Republish;
|
||||
RepublishChannelMessageData messageData = new RepublishChannelMessageData();
|
||||
messageData.setMessageId(messageUid);
|
||||
messageData.setTargets(targets);
|
||||
return channelHttpUtils.httpJsonPost(path, messageData, Void.class);
|
||||
}
|
||||
|
||||
public IMResult<Void> subscribe(String userId) throws Exception {
|
||||
String path = APIPath.Channel_Subscribe;
|
||||
InputChannelSubscribe input = new InputChannelSubscribe();
|
||||
@@ -113,4 +131,8 @@ public class ChannelServiceApi {
|
||||
return configData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
channelHttpUtils.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,12 @@ import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
|
||||
public class ConferenceAdmin {
|
||||
public static IMResult<PojoConferenceInfoList> listConferences() throws Exception {
|
||||
public static IMResult<PojoConferenceInfoList> listConferences(int count, int offset) throws Exception {
|
||||
String path = APIPath.Conference_List;
|
||||
return AdminHttpUtils.httpJsonPost(path, null, PojoConferenceInfoList.class);
|
||||
InputCountOffset inputCountOffset = new InputCountOffset();
|
||||
inputCountOffset.count = count;
|
||||
inputCountOffset.offset = offset;
|
||||
return AdminHttpUtils.httpJsonPost(path, inputCountOffset, PojoConferenceInfoList.class);
|
||||
}
|
||||
|
||||
public static IMResult<Boolean> existsConferences(String conferenceId) throws Exception {
|
||||
|
||||
@@ -82,6 +82,37 @@ public class GeneralAdmin {
|
||||
}
|
||||
|
||||
//以下仅专业版支持
|
||||
//如果是单聊会话,target和userId代表会话的2个用户。如果是其他会话userId无意义
|
||||
public static IMResult<FilesPojo> getConversationFiles(int conversationType, String target, int line, String userId, int offset, boolean desc, int count) throws Exception {
|
||||
String path = APIPath.Get_Conversation_Files;
|
||||
GetConversationFilesPojo input = new GetConversationFilesPojo();
|
||||
input.conversationType = conversationType;
|
||||
input.target = target;
|
||||
input.line = line;
|
||||
input.userId = userId;
|
||||
input.offset = offset;
|
||||
input.desc = desc;
|
||||
input.count = count;
|
||||
return AdminHttpUtils.httpJsonPost(path, input, FilesPojo.class);
|
||||
}
|
||||
|
||||
public static IMResult<FilesPojo> getUserFiles(String userId, int offset, boolean desc, int count) throws Exception {
|
||||
String path = APIPath.Get_User_Files;
|
||||
GetUserFilesPojo input = new GetUserFilesPojo();
|
||||
input.userId = userId;
|
||||
input.offset = offset;
|
||||
input.desc = desc;
|
||||
input.count = count;
|
||||
return AdminHttpUtils.httpJsonPost(path, input, FilesPojo.class);
|
||||
}
|
||||
|
||||
public static IMResult<FilesPojo.FilePojo> getFile(long messageId) throws Exception {
|
||||
String path = APIPath.Get_Message_File;
|
||||
LongPojo input = new LongPojo();
|
||||
input.value = messageId;
|
||||
return AdminHttpUtils.httpJsonPost(path, input, FilesPojo.FilePojo.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> setConversationTop(String userId, int conversationType, String target, int line, boolean isTop) throws Exception {
|
||||
String key = conversationType + "-" + line + "-" + target;
|
||||
String value = isTop?"1":"0";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.wildfirechat.sdk;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.*;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
@@ -178,6 +179,36 @@ public class GroupAdmin {
|
||||
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> setGroupRemark(String userId, String groupId, String remark) throws Exception {
|
||||
return GeneralAdmin.setUserSetting(userId, 26, groupId, remark);
|
||||
}
|
||||
|
||||
public static IMResult<String> getGroupRemark(String userId, String groupId) throws Exception {
|
||||
IMResult<UserSettingPojo> imResult = GeneralAdmin.getUserSetting(userId, 26, groupId);
|
||||
IMResult<String> result = new IMResult<>();
|
||||
result.code = imResult.code;;
|
||||
result.msg = imResult.msg;;
|
||||
if(imResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
result.result = imResult.result.getValue();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IMResult<Void> setFavGroup(String userId, String groupId, boolean fav) throws Exception {
|
||||
return GeneralAdmin.setUserSetting(userId, 6, groupId, fav?"1":"0");
|
||||
}
|
||||
|
||||
public static IMResult<Boolean> isFavGroup(String userId, String groupId) throws Exception {
|
||||
IMResult<UserSettingPojo> imResult = GeneralAdmin.getUserSetting(userId, 6, groupId);
|
||||
IMResult<Boolean> result = new IMResult<>();
|
||||
result.code = imResult.code;;
|
||||
result.msg = imResult.msg;;
|
||||
if(imResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
result.result = "1".equals(imResult.getResult().getValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IMResult<OutputGroupIds> getUserGroups(String user) throws Exception {
|
||||
String path = APIPath.Get_User_Groups;
|
||||
InputUserId inputUserId = new InputUserId();
|
||||
|
||||
@@ -58,6 +58,9 @@ public class Main {
|
||||
//测试解析数据库中消息内容
|
||||
testReadMessageContentFromDB();
|
||||
|
||||
//计算消息分表
|
||||
testMessageSharding();
|
||||
|
||||
//Robot和Channel都是使用的80端口,第三方可以创建或者为第三方创建,第三方可以使用robot或者channel与IM系统进行对接。
|
||||
testRobot();
|
||||
testChannel();
|
||||
@@ -616,7 +619,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult = GroupAdmin.setGroupMemberAlias("user1", groupInfo.getTarget_id(), "user3", "test user3", null, null);
|
||||
voidIMResult = GroupAdmin.setGroupMemberAlias("user1", groupInfo.getTarget_id(), "user2", "test user2", null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("set group member alias success");
|
||||
} else {
|
||||
@@ -1003,13 +1006,24 @@ public class Main {
|
||||
testStreamingText(sender, conversation);
|
||||
}
|
||||
|
||||
static void testReadMessageContentFromDB() throws Exception {
|
||||
//需要注意几点:
|
||||
// 1 WFCMessage类不能混淆,如果混淆 WFCMessage.MessageContent.parseFrom(data) 就会失败。
|
||||
// 2 MessageContentFactory方法会自动查找所有的消息类,包括文本/图片/语音等。也有可能在某些环境下找不到这些类。可以检查MessageContentFactory
|
||||
// 类的源码,修改registerAllMessageContent方法,确保能找到所有的内容类。也可以显式调用注册的方法把所有已知消息都注册一遍,比如:
|
||||
// MessageContentFactory.registerCustomMessageContent(TextMessageContent.class); //这里示例只写了文本的,其他所有已知消息都需要注册一遍。
|
||||
//消息相关表分为2类,分表是:t_messages_x和t_user_messages_y,并且是分表存储的。表内存储数据和分表规则请参考 https://docs.wildfirechat.cn/faq/server.html 问题2
|
||||
static void testMessageSharding() {
|
||||
String userId = "user1";
|
||||
int hashId = Math.abs(userId.hashCode())%128;
|
||||
String userMessageTable = "t_user_messages_" + hashId;
|
||||
System.out.println("user:" + userId + " user messages table is " + userMessageTable);
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Date date = new Date();
|
||||
calendar.setTime(date);
|
||||
int month = calendar.get(Calendar.MONTH);
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
year %= 3;
|
||||
String messageTable = "t_messages_" + (year * 12 + month);
|
||||
System.out.println("This month save message to table " + messageTable);
|
||||
}
|
||||
|
||||
static void testReadMessageContentFromDB() throws Exception {
|
||||
//从数据库t_messages_x表中读取到消息内容字段_data的二进制数据为
|
||||
byte[] data = {8,1,18,5,72,101,108,108,111,64,3};
|
||||
//1. 先把二进制数据转化为协议栈消息内容。
|
||||
@@ -1399,6 +1413,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
//使用完需要释放
|
||||
RobotService robotService = new RobotService(IMUrl, robotId, robotSecret);
|
||||
|
||||
//***********************************************
|
||||
@@ -1605,7 +1620,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult = robotService.setGroupMemberAlias(groupInfo.getTarget_id(), "user3", "test user3", null, null);
|
||||
voidIMResult = robotService.setGroupMemberAlias(groupInfo.getTarget_id(), "user2", "test user2", null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("set group member alias success");
|
||||
} else {
|
||||
@@ -1798,6 +1813,9 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
//使用完需要释放
|
||||
robotService.close();
|
||||
}
|
||||
|
||||
//***测试频道API功能,仅专业版支持***
|
||||
@@ -1868,7 +1886,7 @@ public class Main {
|
||||
}
|
||||
|
||||
|
||||
//2. 初始化api,注意端口是80,不是18080
|
||||
//2. 初始化api,注意端口是80,不是18080 //使用完需要释放
|
||||
ChannelServiceApi channelServiceApi = new ChannelServiceApi(IMUrl, channelId, secret);
|
||||
|
||||
|
||||
@@ -2024,6 +2042,9 @@ public class Main {
|
||||
}
|
||||
OutputApplicationConfigData config = channelServiceApi.getApplicationSignature();
|
||||
System.out.println(config);
|
||||
|
||||
//使用完需要释放
|
||||
channelServiceApi.close();
|
||||
}
|
||||
static void testSensitiveApi() throws Exception {
|
||||
List<String> words = Arrays.asList("a","b","c");
|
||||
@@ -2125,7 +2146,7 @@ public class Main {
|
||||
会议相关接口,仅音视频高级版服务支持
|
||||
*/
|
||||
public static void testConference() throws Exception {
|
||||
IMResult<PojoConferenceInfoList> listResult = ConferenceAdmin.listConferences();
|
||||
IMResult<PojoConferenceInfoList> listResult = ConferenceAdmin.listConferences(100, 0);
|
||||
if(listResult == null || listResult.getErrorCode() != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get conference list failure");
|
||||
System.exit(-1);
|
||||
@@ -2143,7 +2164,7 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
listResult = ConferenceAdmin.listConferences();
|
||||
listResult = ConferenceAdmin.listConferences(100, 0);
|
||||
if(listResult == null || listResult.getErrorCode() != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get conference list failure");
|
||||
System.exit(-1);
|
||||
@@ -2183,7 +2204,7 @@ public class Main {
|
||||
System.out.println("recording conference success");
|
||||
}
|
||||
|
||||
listResult = ConferenceAdmin.listConferences();
|
||||
listResult = ConferenceAdmin.listConferences(100, 0);
|
||||
if(listResult == null || listResult.getErrorCode() != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get conference list failure");
|
||||
System.exit(-1);
|
||||
|
||||
@@ -82,11 +82,12 @@ public class MeshAdmin {
|
||||
return AdminHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||
}
|
||||
|
||||
public static IMResult<SendMessageResult> publishMessage(SendMessageData messageData, List<String> receivers) throws Exception {
|
||||
public static IMResult<SendMessageResult> publishMessage(SendMessageData messageData, List<String> receivers, long messageId) throws Exception {
|
||||
String path = APIPath.Msg_Publish;
|
||||
PojoPublishMessageReq req = new PojoPublishMessageReq();
|
||||
req.messageData = messageData;
|
||||
req.receivers = receivers;
|
||||
req.messageId = messageId;
|
||||
return AdminHttpUtils.httpJsonPost(path, req, SendMessageResult.class);
|
||||
}
|
||||
|
||||
@@ -140,6 +141,17 @@ public class MeshAdmin {
|
||||
return AdminHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> addJoinGroupRequest(String operator, String groupId, List<String> userIds, String reason, String extra) throws Exception {
|
||||
String path = APIPath.Group_Join_Request_Add;
|
||||
PojoAddJoinGroupRequest addGroupMember = new PojoAddJoinGroupRequest();
|
||||
addGroupMember.operator = operator;
|
||||
addGroupMember.group_id = groupId;
|
||||
addGroupMember.userIds = userIds;
|
||||
addGroupMember.reason = reason;
|
||||
addGroupMember.extra = extra;
|
||||
return AdminHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<PojoGroupInfoList> batchGroupInfos(List<String> groupIds) throws Exception {
|
||||
return GroupAdmin.batchGroupInfos(groupIds);
|
||||
}
|
||||
@@ -227,4 +239,10 @@ public class MeshAdmin {
|
||||
return AdminHttpUtils.httpJsonPost(path, event, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<PojoDomainPingResponse> pingDomain(String domainId) throws Exception {
|
||||
String path = APIPath.Ping_Domain;
|
||||
PojoDomainPingRequest request = new PojoDomainPingRequest();
|
||||
request.domainId = domainId;
|
||||
return AdminHttpUtils.httpJsonPost(path, request, PojoDomainPingResponse.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,21 @@ public class MessageAdmin {
|
||||
public static IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload) throws Exception {
|
||||
return sendMessage(sender, conversation, payload, null);
|
||||
}
|
||||
|
||||
//toUsers为发送给会话中部分用户用的,正常为null,仅当需要指定群/频道/聊天室中部分接收用户时使用
|
||||
public static IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload, List<String> toUsers) throws Exception {
|
||||
return sendMessage(sender, conversation, payload, toUsers, false);
|
||||
}
|
||||
|
||||
//toUsers为发送给会话中部分用户用的,正常为null,仅当需要指定群/频道/聊天室中部分接收用户时使用
|
||||
public static IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload, List<String> toUsers, boolean isUserMessage) throws Exception {
|
||||
String path = APIPath.Msg_Send;
|
||||
SendMessageData messageData = new SendMessageData();
|
||||
messageData.setSender(sender);
|
||||
messageData.setConv(conversation);
|
||||
messageData.setPayload(payload);
|
||||
messageData.setToUsers(toUsers);
|
||||
messageData.setUserMessage(isUserMessage);
|
||||
if (payload.getType() == 1 && (payload.getSearchableContent() == null || payload.getSearchableContent().isEmpty())) {
|
||||
System.out.println("Payload错误,Payload格式应该跟客户端消息encode出来的Payload对齐,这样客户端才能正确识别。比如文本消息,文本需要放到searchableContent属性。请与客户端同事确认Payload的格式,或则去 https://gitee.com/wfchat/android-chat/tree/master/client/src/main/java/cn/wildfirechat/message 找到消息encode的实现方法!");
|
||||
}
|
||||
|
||||
@@ -8,11 +8,13 @@ import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.wildfirechat.proto.ProtoConstants.ApplicationType.ApplicationType_Robot;
|
||||
|
||||
public class RobotService {
|
||||
public class RobotService implements Closeable {
|
||||
private final RobotHttpUtils robotHttpUtils;
|
||||
|
||||
public RobotService(String url, String robotId, String robotSecret) {
|
||||
@@ -37,6 +39,15 @@ public class RobotService {
|
||||
return robotHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||
}
|
||||
|
||||
public IMResult<SendMessageResult> replyMessage(long messageUid, MessagePayload payload, boolean only2Sender) throws Exception {
|
||||
String path = APIPath.Robot_Message_Reply;
|
||||
ReplyMessageData messageData = new ReplyMessageData();
|
||||
messageData.setMessageUid(messageUid);
|
||||
messageData.setOnly2Sender(only2Sender);
|
||||
messageData.setPayload(payload);
|
||||
return robotHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||
}
|
||||
|
||||
public IMResult<String> recallMessage(long messageUid) throws Exception {
|
||||
String path = APIPath.Robot_Message_Recall;
|
||||
RecallMessageData messageData = new RecallMessageData();
|
||||
@@ -423,4 +434,9 @@ public class RobotService {
|
||||
requestPojo.rl = removeList;
|
||||
return robotHttpUtils.httpJsonPost(path, requestPojo, Void.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
robotHttpUtils.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,13 @@ public class UserAdmin {
|
||||
return AdminHttpUtils.httpJsonPost(path, getRobotInfo, OutputRobot.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputStringList> getUserRobots(String userId) throws Exception {
|
||||
String path = APIPath.User_Get_User_Robots;
|
||||
InputUserId getRobotInfo = new InputUserId();
|
||||
getRobotInfo.setUserId(userId);
|
||||
return AdminHttpUtils.httpJsonPost(path, getRobotInfo, OutputStringList.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputGetIMTokenData> getUserToken(String userId, String clientId, int platform) throws Exception {
|
||||
String path = APIPath.User_Get_Token;
|
||||
InputGetToken getToken = new InputGetToken(userId, clientId, platform);
|
||||
|
||||
@@ -36,7 +36,9 @@ public class ImageMessageContent extends MediaMessageContent {
|
||||
public MessagePayload encode() {
|
||||
MessagePayload payload = super.encode();
|
||||
payload.setSearchableContent("[图片]");
|
||||
payload.setBase64edData(Base64.getEncoder().encodeToString(thumbnailBytes));
|
||||
if(thumbnailBytes != null) {
|
||||
payload.setBase64edData(Base64.getEncoder().encodeToString(thumbnailBytes));
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
@@ -45,7 +47,9 @@ public class ImageMessageContent extends MediaMessageContent {
|
||||
@Override
|
||||
public void decode(MessagePayload payload) {
|
||||
super.decode(payload);
|
||||
thumbnailBytes = Base64.getDecoder().decode(payload.getBase64edData());
|
||||
if(payload.getBase64edData() != null) {
|
||||
thumbnailBytes = Base64.getDecoder().decode(payload.getBase64edData());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,12 +8,39 @@ import cn.wildfirechat.sdk.utilities.ClassUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class MessageContentFactory {
|
||||
private static final Map<Integer, Class<? extends MessageContent>> contentClassMap = new ConcurrentHashMap<>();
|
||||
|
||||
private static List<Class> buildinMessageContents = Arrays.asList(
|
||||
ArticlesMessageContent.class,
|
||||
StreamTextGeneratedMessageContent.class,
|
||||
CallStartMessageContent.class,
|
||||
StreamTextGeneratingMessageContent.class,
|
||||
CardMessageContent.class,
|
||||
MultiCallOngoingMessageContent.class,
|
||||
TextMessageContent.class,
|
||||
DeleteMessageContent.class,
|
||||
NotDeliveredMessageContent.class,
|
||||
TipNotificationMessageContent.class,
|
||||
FileMessageContent.class,
|
||||
PTTSoundMessageContent.class,
|
||||
TypingMessageContent.class,
|
||||
ImageMessageContent.class,
|
||||
RecallMessageContent.class,
|
||||
UnknownMessageContent.class,
|
||||
LinkMessageContent.class,
|
||||
RichNotificationMessageContent.class,
|
||||
VideoMessageContent.class,
|
||||
LocationMessageContent.class,
|
||||
SoundMessageContent.class,
|
||||
StickerMessageContent.class
|
||||
);
|
||||
|
||||
static {
|
||||
registerAllMessageContent();
|
||||
}
|
||||
@@ -59,6 +86,15 @@ public class MessageContentFactory {
|
||||
}
|
||||
|
||||
private static void registerAllMessageContent() {
|
||||
try {
|
||||
for (Class buildinMessageContent : buildinMessageContents) {
|
||||
MessageContent content = (MessageContent)buildinMessageContent.newInstance();
|
||||
contentClassMap.put(content.getContentType(), buildinMessageContent);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
for (Class cls : ClassUtil.getAllAssignedClass(MessageContent.class)) {
|
||||
if(!Modifier.isAbstract(cls.getModifiers())) {
|
||||
|
||||
@@ -12,7 +12,7 @@ public class UnknownMessageContent extends MessageContent {
|
||||
|
||||
@Override
|
||||
public int getContentType() {
|
||||
return ProtoConstants.ContentType.Text;
|
||||
return ProtoConstants.ContentType.Unknown;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,13 +50,18 @@ public class QuoteInfo {
|
||||
object.put("i", userId);
|
||||
object.put("n", userDisplayName);
|
||||
object.put("d", messageDigest);
|
||||
return object;
|
||||
JSONObject quote = new JSONObject();
|
||||
quote.put("quote", object);
|
||||
return quote;
|
||||
}
|
||||
|
||||
public void decode(JSONObject object) {
|
||||
messageUid = (long) object.get("u");
|
||||
userId = (String) object.get("i");
|
||||
userDisplayName = (String) object.get("n");
|
||||
messageDigest = (String) object.get("d");
|
||||
JSONObject quote = (JSONObject)object.get("quote");
|
||||
if(quote != null) {
|
||||
messageUid = (long) quote.get("u");
|
||||
userId = (String) quote.get("i");
|
||||
userDisplayName = (String) quote.get("n");
|
||||
messageDigest = (String) quote.get("d");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,193 +1,135 @@
|
||||
package cn.wildfirechat.sdk.utilities;
|
||||
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import ikidou.reflect.TypeBuilder;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.config.ConnectionConfig;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class AdminHttpUtils extends JsonUtils {
|
||||
public class AdminHttpUtils extends HttpUtils {
|
||||
// ======================== 常量定义(消除硬编码)========================
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AdminHttpUtils.class);
|
||||
public static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
private static String adminUrl;
|
||||
private static String adminSecret;
|
||||
private static CloseableHttpClient httpClient;
|
||||
// 连接池配置常量
|
||||
private static final int DEFAULT_CONNECT_TIMEOUT = 15000;
|
||||
private static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT = 3000;
|
||||
private static final int DEFAULT_SOCKET_TIMEOUT = 15000;
|
||||
private static final int MAX_CONN_TOTAL = 100;
|
||||
private static final int MAX_CONN_PER_ROUTE = 50;
|
||||
private static final long IDLE_CONNECTION_EVICT_TIME = 60L;
|
||||
private static final int VALIDATE_AFTER_INACTIVITY = 1000;
|
||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
|
||||
private static final int NONCE_MAX_RANGE = 1000000;
|
||||
|
||||
// ======================== 线程安全的全局变量 ========================
|
||||
private static volatile String adminUrl;
|
||||
private static volatile String adminSecret;
|
||||
private static volatile CloseableHttpClient httpClient;
|
||||
|
||||
|
||||
// ======================== 初始化方法 ========================
|
||||
public static void init(String url, String secret) {
|
||||
init(url, secret, 15000);
|
||||
init(url, secret, DEFAULT_SOCKET_TIMEOUT);
|
||||
}
|
||||
|
||||
public static void init(String url, String secret, int timeout) {
|
||||
/**
|
||||
* 初始化HTTP客户端和配置
|
||||
* @param url IM服务管理地址
|
||||
* @param secret 管理密钥
|
||||
* @param timeout 套接字超时时间(毫秒)
|
||||
*/
|
||||
public static synchronized void init(String url, String secret, int timeout) {
|
||||
// 参数校验
|
||||
if (isNullOrEmpty(url) || isNullOrEmpty(secret)) {
|
||||
throw new IllegalArgumentException("IM服务地址或密钥不能为空");
|
||||
}
|
||||
adminUrl = url.trim();
|
||||
adminSecret = secret.trim();
|
||||
|
||||
// 若已存在HttpClient,先关闭再重新初始化(支持配置更新)
|
||||
if (httpClient != null) {
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (IOException e) {
|
||||
LOG.error("关闭旧HttpClient连接池失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化连接池
|
||||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
||||
cm.setValidateAfterInactivity(1000);
|
||||
int connectTimeout = 15000; // 连接超时时间
|
||||
int connectionRequestTimeout = 3000; // 从连接池获取连接的超时时间
|
||||
cm.setValidateAfterInactivity(VALIDATE_AFTER_INACTIVITY);
|
||||
|
||||
// 构建请求配置
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
.setConnectTimeout(connectTimeout)
|
||||
.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT)
|
||||
.setSocketTimeout(timeout)
|
||||
.setConnectionRequestTimeout(connectionRequestTimeout)
|
||||
.setConnectionRequestTimeout(DEFAULT_CONNECTION_REQUEST_TIMEOUT)
|
||||
.build();
|
||||
|
||||
// 构建HttpClient
|
||||
httpClient = HttpClients.custom()
|
||||
.setDefaultRequestConfig(requestConfig)
|
||||
.setConnectionManager(cm)
|
||||
.evictExpiredConnections()
|
||||
.evictIdleConnections(60L, TimeUnit.SECONDS)
|
||||
.setRetryHandler(DefaultHttpRequestRetryHandler.INSTANCE)
|
||||
.setMaxConnTotal(100)
|
||||
.setMaxConnPerRoute(50)
|
||||
.evictIdleConnections(IDLE_CONNECTION_EVICT_TIME, TimeUnit.SECONDS)
|
||||
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, false)) // 重试3次,不重试IO异常
|
||||
.setMaxConnTotal(MAX_CONN_TOTAL)
|
||||
.setMaxConnPerRoute(MAX_CONN_PER_ROUTE)
|
||||
.build();
|
||||
|
||||
LOG.info("AdminHttpUtils初始化完成,IM服务地址:{}", adminUrl);
|
||||
}
|
||||
|
||||
// ======================== HTTP GET请求 ========================
|
||||
public static <T> IMResult<T> httpGet(String path, Class<T> clazz) throws Exception {
|
||||
if (isNullOrEmpty(adminUrl) || isNullOrEmpty(adminSecret)) {
|
||||
LOG.error("野火IM Server SDK必须先初始化才能使用,是不是忘记初始化了!!!!");
|
||||
throw new Exception("SDK没有初始化");
|
||||
}
|
||||
|
||||
// 前置校验
|
||||
validateInitStatus(adminUrl, adminSecret, httpClient);
|
||||
if (isNullOrEmpty(path)) {
|
||||
throw new Exception("路径缺失");
|
||||
throw new IllegalArgumentException("请求路径不能为空");
|
||||
}
|
||||
HttpGet get = null;
|
||||
|
||||
HttpGet httpGet = new HttpGet(adminUrl + path);
|
||||
try {
|
||||
get = new HttpGet(adminUrl + path);
|
||||
HttpResponse response = httpClient.execute(get);
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
String content = null;
|
||||
if (response.getEntity().getContentLength() > 0) {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
String NL = System.getProperty("line.separator");
|
||||
while ((line = in.readLine()) != null) {
|
||||
sb.append(line).append(NL);
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
content = sb.toString();
|
||||
LOG.info("http request response content: {}", content);
|
||||
}
|
||||
|
||||
if(statusCode != HttpStatus.SC_OK){
|
||||
LOG.info("Request error: " + statusCode + " error msg:" + content);
|
||||
throw new Exception("Http request error with code:" + statusCode);
|
||||
} else {
|
||||
return fromJsonObject(content, clazz);
|
||||
}
|
||||
HttpResponse response = httpClient.execute(httpGet);
|
||||
return handleResponse(response, clazz, adminUrl, adminSecret);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
LOG.error("HTTP GET请求失败,路径:{}", path, e);
|
||||
throw new Exception("HTTP GET请求异常:" + e.getMessage(), e);
|
||||
} finally {
|
||||
if(get != null) {
|
||||
get.releaseConnection();
|
||||
}
|
||||
httpGet.releaseConnection();
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== HTTP JSON POST请求 ========================
|
||||
public static <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception {
|
||||
if (isNullOrEmpty(adminUrl) || isNullOrEmpty(adminSecret)) {
|
||||
LOG.error("野火IM Server SDK必须先初始化才能使用,是不是忘记初始化了!!!!");
|
||||
throw new Exception("SDK没有初始化");
|
||||
}
|
||||
|
||||
if (isNullOrEmpty(path)) {
|
||||
throw new Exception("路径缺失");
|
||||
}
|
||||
|
||||
String url = adminUrl + path;
|
||||
HttpPost post = null;
|
||||
|
||||
try {
|
||||
int nonce = (int)(Math.random() * 100000 + 3);
|
||||
return httpJsonPost(adminUrl, adminSecret, httpClient, path, object, clazz, httpPost -> {
|
||||
// 构建签名头
|
||||
int nonce = SECURE_RANDOM.nextInt(NONCE_MAX_RANGE) + 1; // 安全随机数
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String str = nonce + "|" + adminSecret + "|" + timestamp;
|
||||
String sign = DigestUtils.sha1Hex(str);
|
||||
String signStr = nonce + "|" + adminSecret + "|" + timestamp;
|
||||
String sign = DigestUtils.sha1Hex(signStr);
|
||||
|
||||
post = new HttpPost(url);
|
||||
post.setHeader("Content-type", "application/json; charset=utf-8");
|
||||
post.setHeader("Connection", "Keep-Alive");
|
||||
post.setHeader("nonce", nonce + "");
|
||||
post.setHeader("timestamp", "" + timestamp);
|
||||
post.setHeader("sign", sign);
|
||||
|
||||
String jsonStr = "";
|
||||
if (object != null) {
|
||||
jsonStr = gson.toJson(object);
|
||||
}
|
||||
LOG.info("http request:{} content: {}", url, jsonStr);
|
||||
|
||||
StringEntity entity = new StringEntity(jsonStr, Charset.forName("UTF-8"));
|
||||
entity.setContentEncoding("UTF-8");
|
||||
entity.setContentType("application/json");
|
||||
post.setEntity(entity);
|
||||
HttpResponse response = httpClient.execute(post);
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
String content = null;
|
||||
if (response.getEntity().getContentLength() > 0) {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
String NL = System.getProperty("line.separator");
|
||||
while ((line = in.readLine()) != null) {
|
||||
sb.append(line).append(NL);
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
content = sb.toString();
|
||||
LOG.info("http request response content: {}", content);
|
||||
}
|
||||
|
||||
if(statusCode != HttpStatus.SC_OK){
|
||||
LOG.info("Request error: " + statusCode + " error msg:" + content);
|
||||
throw new Exception("Http request error with code:" + statusCode);
|
||||
} else {
|
||||
IMResult<T> result = fromJsonObject(content, clazz);
|
||||
if(result != null){
|
||||
if(result.getErrorCode() == ErrorCode.ERROR_CODE_AUTH_FAILURE) {
|
||||
LOG.error("鉴权失败,IM服务地址或者密钥配置错误,请检查IM服务{}的配置文件中的http.admin.secret_key是否是{}", adminUrl, adminSecret);
|
||||
} else if(result.getErrorCode() == ErrorCode.ERROR_CODE_SIGN_EXPIRED) {
|
||||
LOG.error("时间验证失败,请确保当前服务和IM服务{}的时间是一致的", adminUrl);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
} finally {
|
||||
if(post != null) {
|
||||
post.releaseConnection();
|
||||
}
|
||||
}
|
||||
// 设置请求头
|
||||
httpPost.setHeader("Content-type", "application/json; charset=utf-8");
|
||||
httpPost.setHeader("Connection", "Keep-Alive");
|
||||
httpPost.setHeader("nonce", String.valueOf(nonce));
|
||||
httpPost.setHeader("timestamp", String.valueOf(timestamp));
|
||||
httpPost.setHeader("sign", sign);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.MalformedURLException;
|
||||
@@ -28,9 +30,8 @@ import java.nio.charset.Charset;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class ChannelHttpUtils extends JsonUtils {
|
||||
public class ChannelHttpUtils extends HttpUtils implements Closeable {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChannelHttpUtils.class);
|
||||
public static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
private String imurl;
|
||||
private String channelId;
|
||||
@@ -40,7 +41,7 @@ public class ChannelHttpUtils extends JsonUtils {
|
||||
private final int port;
|
||||
|
||||
private void checkPort() {
|
||||
if (port != 80 && port != 443) {
|
||||
if (port != 80 && port != 443 && port != -1) {
|
||||
if (port == 18080) {
|
||||
LOG.warn("您传入的频道API地址中的端口是18080,18080端口默认为管理API端口,频道API端口应该为IM服务的HTTP端口,默认为80,请确认是否使用错误!");
|
||||
} else {
|
||||
@@ -54,8 +55,12 @@ public class ChannelHttpUtils extends JsonUtils {
|
||||
this.channelId = channelId.trim();
|
||||
this.channelSecret = secret.trim();
|
||||
try {
|
||||
URL url = new URL(this.imurl);
|
||||
this.port = url.getPort();
|
||||
URL u = new URL(this.imurl);
|
||||
int port = u.getPort();
|
||||
if(port == -1) {
|
||||
port = u.getDefaultPort();
|
||||
}
|
||||
this.port = port;
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -82,71 +87,19 @@ public class ChannelHttpUtils extends JsonUtils {
|
||||
}
|
||||
|
||||
public <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
if (isNullOrEmpty(imurl) || isNullOrEmpty(path)) {
|
||||
LOG.error("Not init IM SDK correctly. Do you forget init it?");
|
||||
throw new Exception("SDK url or secret lack!");
|
||||
}
|
||||
|
||||
String url = imurl + path;
|
||||
HttpPost post = null;
|
||||
try {
|
||||
return httpJsonPost(imurl, channelId, httpClient, path, object, clazz, post -> {
|
||||
int nonce = (int)(Math.random() * 100000 + 3);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String str = nonce + "|" + channelSecret + "|" + timestamp;
|
||||
String sign = DigestUtils.sha1Hex(str);
|
||||
|
||||
|
||||
post = new HttpPost(url);
|
||||
post.setHeader("Content-type", "application/json; charset=utf-8");
|
||||
post.setHeader("Connection", "Keep-Alive");
|
||||
post.setHeader("nonce", nonce + "");
|
||||
post.setHeader("timestamp", "" + timestamp);
|
||||
post.setHeader("cid", channelId);
|
||||
post.setHeader("sign", sign);
|
||||
|
||||
|
||||
String jsonStr = "";
|
||||
if (object != null) {
|
||||
jsonStr = gson.toJson(object);
|
||||
}
|
||||
LOG.info("http request:{} content: {}", url, jsonStr);
|
||||
|
||||
StringEntity entity = new StringEntity(jsonStr, Charset.forName("UTF-8"));
|
||||
entity.setContentEncoding("UTF-8");
|
||||
entity.setContentType("application/json");
|
||||
post.setEntity(entity);
|
||||
HttpResponse response = httpClient.execute(post);
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if(statusCode != HttpStatus.SC_OK){
|
||||
LOG.info("Request error: "+statusCode);
|
||||
throw new Exception("Http request error with code:" + statusCode);
|
||||
}else{
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity()
|
||||
.getContent(),"utf-8"));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String line;
|
||||
String NL = System.getProperty("line.separator");
|
||||
while ((line = in.readLine()) != null) {
|
||||
sb.append(line + NL);
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
String content = sb.toString();
|
||||
LOG.info("http request response content: {}", content);
|
||||
|
||||
return fromJsonObject(content, clazz);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
checkPort();
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}finally{
|
||||
if(post != null){
|
||||
post.releaseConnection();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getChannelId() {
|
||||
@@ -156,4 +109,9 @@ public class ChannelHttpUtils extends JsonUtils {
|
||||
public String getChannelSecret() {
|
||||
return channelSecret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
httpClient.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
package cn.wildfirechat.sdk.utilities;
|
||||
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class HttpUtils extends JsonUtils {
|
||||
// ======================== 常量定义(消除硬编码)========================
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HttpUtils.class);
|
||||
public static final Gson GSON = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
public static interface HeaderCallback {
|
||||
public void addHeaders(HttpPost httpPost);
|
||||
}
|
||||
|
||||
// ======================== HTTP JSON POST请求 ========================
|
||||
public static <T> IMResult<T> httpJsonPost(String adminUrl, String adminSecret, HttpClient httpClient, String path, Object object, Class<T> clazz, HeaderCallback headerCallback) throws Exception {
|
||||
// 前置校验
|
||||
validateInitStatus(adminUrl, adminSecret, httpClient);
|
||||
if (isNullOrEmpty(path)) {
|
||||
throw new IllegalArgumentException("请求路径不能为空");
|
||||
}
|
||||
|
||||
String url = adminUrl + path;
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
try {
|
||||
headerCallback.addHeaders(httpPost);
|
||||
|
||||
// 设置请求体
|
||||
String jsonStr = object == null ? "" : GSON.toJson(object);
|
||||
LOG.info("HTTP POST请求:{},请求体:{}", url, truncateLogContent(jsonStr));
|
||||
StringEntity entity = new StringEntity(jsonStr, StandardCharsets.UTF_8);
|
||||
entity.setContentEncoding(StandardCharsets.UTF_8.name());
|
||||
entity.setContentType("application/json");
|
||||
httpPost.setEntity(entity);
|
||||
|
||||
// 执行请求并处理响应
|
||||
HttpResponse response = httpClient.execute(httpPost);
|
||||
return handleResponse(response, clazz, adminUrl, adminSecret);
|
||||
} catch (Exception e) {
|
||||
LOG.error("HTTP POST请求失败,路径:{}", path, e);
|
||||
throw new Exception("HTTP POST请求异常:" + e.getMessage(), e);
|
||||
} finally {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== 私有工具方法 ========================
|
||||
/**
|
||||
* 校验初始化状态
|
||||
*/
|
||||
protected static void validateInitStatus(String adminUrl, String adminSecret, HttpClient httpClient) {
|
||||
if (isNullOrEmpty(adminUrl) || isNullOrEmpty(adminSecret) || httpClient == null) {
|
||||
String errorMsg = "野火IM Server SDK未初始化,请调用AdminConfig.initAdmin(AdminUrl, AdminSecret)完成初始化";
|
||||
LOG.error(errorMsg);
|
||||
throw new IllegalStateException(errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理HTTP响应,统一解析逻辑
|
||||
*/
|
||||
protected static <T> IMResult<T> handleResponse(HttpResponse response, Class<T> clazz, String adminUrl, String adminSecret) throws Exception {
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
String content = readResponseContent(response);
|
||||
|
||||
// 非200状态码处理
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
String errorMsg = String.format("HTTP请求失败,状态码:%d,响应内容:%s", statusCode, truncateLogContent(content));
|
||||
LOG.error(errorMsg);
|
||||
throw new Exception(errorMsg);
|
||||
}
|
||||
|
||||
// 解析响应体
|
||||
IMResult<T> result = fromJsonObject(content, clazz);
|
||||
if (result != null) {
|
||||
if (result.getErrorCode() == ErrorCode.ERROR_CODE_AUTH_FAILURE) {
|
||||
LOG.error("鉴权失败,请检查IM服务地址({})或密钥({})配置", adminUrl, maskSecret(adminSecret));
|
||||
} else if (result.getErrorCode() == ErrorCode.ERROR_CODE_SIGN_EXPIRED) {
|
||||
LOG.error("签名过期,请确保当前服务与IM服务({})时间同步", adminUrl);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取响应体(兼容分块传输,修复getContentLength=-1问题)
|
||||
*/
|
||||
protected static String readResponseContent(HttpResponse response) throws IOException {
|
||||
if (response.getEntity() == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 使用try-with-resources自动关闭所有流,避免资源泄漏
|
||||
try (InputStream is = response.getEntity().getContent();
|
||||
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
|
||||
BufferedReader br = new BufferedReader(isr)) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
String nl = System.getProperty("line.separator");
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line).append(nl);
|
||||
}
|
||||
String content = sb.toString().trim();
|
||||
LOG.info("HTTP响应内容:{}", truncateLogContent(content));
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 截断超长日志内容(避免日志爆炸)
|
||||
*/
|
||||
protected static String truncateLogContent(String content) {
|
||||
if (content == null) {
|
||||
return "";
|
||||
}
|
||||
int maxLength = 1024;
|
||||
return content.length() > maxLength ? content.substring(0, maxLength) + "..." : content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 掩码处理密钥(避免日志泄露敏感信息)
|
||||
*/
|
||||
protected static String maskSecret(String secret) {
|
||||
if (isNullOrEmpty(secret) || secret.length() <= 4) {
|
||||
return "******";
|
||||
}
|
||||
return secret.substring(0, 2) + "******" + secret.substring(secret.length() - 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 空值判断(补充实现,避免依赖外部未定义方法)
|
||||
*/
|
||||
public static boolean isNullOrEmpty(String str) {
|
||||
return str == null || str.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -3,29 +3,35 @@ package cn.wildfirechat.sdk.utilities;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import ikidou.reflect.TypeBuilder;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class RobotHttpUtils extends JsonUtils {
|
||||
public class RobotHttpUtils extends HttpUtils implements Closeable {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RobotHttpUtils.class);
|
||||
public static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
@@ -37,7 +43,7 @@ public class RobotHttpUtils extends JsonUtils {
|
||||
private final int port;
|
||||
|
||||
private void checkPort() {
|
||||
if (port != 80 && port != 443) {
|
||||
if (port != 80 && port != 443 && port != -1) {
|
||||
if (port == 18080) {
|
||||
LOG.warn("您传入的机器人API地址中的端口是18080,18080端口默认为管理API端口,机器人API端口应该为IM服务的HTTP端口,默认为80,请确认是否使用错误!");
|
||||
} else {
|
||||
@@ -52,7 +58,11 @@ public class RobotHttpUtils extends JsonUtils {
|
||||
this.robotSecret = robotSecret.trim();
|
||||
try {
|
||||
URL u = new URL(this.url);
|
||||
this.port = u.getPort();
|
||||
int port = u.getPort();
|
||||
if(port == -1) {
|
||||
port = u.getDefaultPort();
|
||||
}
|
||||
this.port = port;
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -78,73 +88,21 @@ public class RobotHttpUtils extends JsonUtils {
|
||||
.build();
|
||||
}
|
||||
|
||||
public <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
if (isNullOrEmpty(url) || isNullOrEmpty(path)) {
|
||||
LOG.error("Not init IM SDK correctly. Do you forget init it?");
|
||||
throw new Exception("SDK url or secret lack!");
|
||||
}
|
||||
|
||||
String url = this.url + path;
|
||||
HttpPost post = null;
|
||||
try {
|
||||
public <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
return httpJsonPost(url, robotId, httpClient, path, object, clazz, post -> {
|
||||
int nonce = (int)(Math.random() * 100000 + 3);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String str = nonce + "|" + robotSecret + "|" + timestamp;
|
||||
String sign = DigestUtils.sha1Hex(str);
|
||||
|
||||
|
||||
post = new HttpPost(url);
|
||||
post.setHeader("Content-type", "application/json; charset=utf-8");
|
||||
post.setHeader("Connection", "Keep-Alive");
|
||||
post.setHeader("nonce", nonce + "");
|
||||
post.setHeader("timestamp", "" + timestamp);
|
||||
post.setHeader("rid", robotId);
|
||||
post.setHeader("sign", sign);
|
||||
|
||||
String jsonStr = null;
|
||||
if (object != null) {
|
||||
jsonStr = gson.toJson(object);
|
||||
}
|
||||
LOG.info("http request:{} content: {}", url, jsonStr);
|
||||
|
||||
if(!StringUtil.isNullOrEmpty(jsonStr)) {
|
||||
StringEntity entity = new StringEntity(jsonStr, Charset.forName("UTF-8"));
|
||||
entity.setContentEncoding("UTF-8");
|
||||
entity.setContentType("application/json");
|
||||
post.setEntity(entity);
|
||||
}
|
||||
HttpResponse response = httpClient.execute(post);
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if(statusCode != HttpStatus.SC_OK){
|
||||
LOG.info("Request error: "+statusCode);
|
||||
throw new Exception("Http request error with code:" + statusCode);
|
||||
}else{
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity()
|
||||
.getContent(),"utf-8"));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String line;
|
||||
String NL = System.getProperty("line.separator");
|
||||
while ((line = in.readLine()) != null) {
|
||||
sb.append(line + NL);
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
String content = sb.toString();
|
||||
LOG.info("http request response content: {}", content);
|
||||
|
||||
return fromJsonObject(content, clazz);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
checkPort();
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}finally{
|
||||
if(post != null){
|
||||
post.releaseConnection();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getRobotId() {
|
||||
@@ -154,4 +112,9 @@ public class RobotHttpUtils extends JsonUtils {
|
||||
public String getRobotSecret() {
|
||||
return robotSecret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
httpClient.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user