From d90bab53add7e7dd1e7e447b7a5d575b092b5c49 Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Tue, 3 Feb 2026 11:24:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E5=9C=A8?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=97=B6=E6=8C=87=E5=AE=9A=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- broker/config/wildfirechat.conf | 6 ++++ .../loServer/action/robot/GetUserAction.java | 34 ++++++++++++++++++- .../java/io/moquette/BrokerConstants.java | 2 +- .../persistence/MemoryMessagesStore.java | 9 +++++ .../java/io/moquette/spi/IMessagesStore.java | 1 + .../src/main/resources/wildfirechat.conf | 6 ++++ 6 files changed, 56 insertions(+), 2 deletions(-) diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index a4241110..8c56aa3e 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -174,6 +174,12 @@ robot.callback_with_target_info false ## 如果为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 diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetUserAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetUserAction.java index d41529ec..d8ec8d68 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetUserAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/GetUserAction.java @@ -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 { diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 97afb24c..a3435759 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -181,7 +181,7 @@ public final class BrokerConstants { 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"; diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 6654c648..91cbc836 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -222,6 +222,7 @@ public class MemoryMessagesStore implements IMessagesStore { private boolean mRobotCallbackWithSenderInfo = false; private boolean mRobotCallbackWithTargetInfo = false; private boolean mRobotMentionExternalRobot = false; + private int mRobotGetUserInfoMask = 0; private boolean mChannelCallbackWithClientInfo = false; private boolean mChannelCallbackWithSenderInfo = false; @@ -684,6 +685,9 @@ public class MemoryMessagesStore implements IMessagesStore { 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")); @@ -5014,6 +5018,11 @@ public class MemoryMessagesStore implements IMessagesStore { return mRobotMentionExternalRobot; } + @Override + public int getRobotGetUserInfoMask() { + return mRobotGetUserInfoMask; + } + @Override public boolean isChannelCallbackWithClientInfo() { return mChannelCallbackWithClientInfo; diff --git a/broker/src/main/java/io/moquette/spi/IMessagesStore.java b/broker/src/main/java/io/moquette/spi/IMessagesStore.java index 2b1da690..8876ec20 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -256,6 +256,7 @@ public interface IMessagesStore { boolean isRobotCallbackWithSenderInfo(); boolean isRobotCallbackWithTargetInfo(); boolean isRobotMentionExternalRobot(); + int getRobotGetUserInfoMask(); boolean isChannelCallbackWithClientInfo(); boolean isChannelCallbackWithSenderInfo(); diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index dcfc9e31..95c00c93 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -171,6 +171,12 @@ robot.callback_with_target_info false ## 如果为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