From 9af2bbf3d00e4b571720a33d10d36926d00ef17d Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Tue, 23 Aug 2022 14:17:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=95=8F=E6=84=9F=E8=AF=8D?= =?UTF-8?q?=E5=91=BD=E4=B8=AD=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- broker/config/wildfirechat.conf | 4 ++++ broker/src/main/java/io/moquette/BrokerConstants.java | 1 + .../main/java/io/moquette/imhandler/SendMessageHandler.java | 6 +++++- distribution/src/main/resources/wildfirechat.conf | 5 ++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index 2309974d..913ec7f6 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -304,6 +304,10 @@ push.ios.server.address http://localhost:8085/ios/push ##需要转发的消息类型,当有多个时以英文逗号分割。如果转发所有消息,请注释掉配置或者设置为空 #message.forward.types 1,2,3 +##敏感消息转发地址 +##注意回调是单线程回调,接收服务必须在同一内网,且异步处理快速返回,否则会有延迟问题!! +#message.sensitive.forward.url http://localhost:8888/im_event/message + ##提醒消息转发地址,@全体用户和@某个用户消息会回调此地址。此转发不受${message.forward.types}限制。 ##注意回调是单线程回调,接收服务必须在同一内网,且异步处理快速返回,否则会有延迟问题!! #message.mentionmsg.forward.url http://localhost:8888/im_event/message diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 845d18bd..eed919cb 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -120,6 +120,7 @@ public final class BrokerConstants { public static final String SENSITIVE_Remote_Fail_When_Matched = "sensitive.remote_fail_when_matched"; public static final String MESSAGE_Forward_Url = "message.forward.url"; + public static final String MESSAGE_Sensitive_Forward_Url = "message.sensitive.forward.url"; public static final String MESSAGE_Forward_Types = "message.forward.types"; public static final String MESSAGE_MentionMsg_Forward_Url = "message.mentionmsg.forward.url"; diff --git a/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java b/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java index 3f725c66..99457cf0 100644 --- a/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java +++ b/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java @@ -34,6 +34,7 @@ import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS; public class SendMessageHandler extends IMHandler { private int mSensitiveType = 0; //命中敏感词时,0 失败,1 吞掉, 2 敏感词替换成*。 private String mForwardUrl = null; + private String mSensitiveMessageForwardUrl = null; private Set mForwardMessageTypes = new HashSet<>(); private String mMentionForwardUrl = null; private int mBlacklistStrategy = 0; //黑名单中时,0失败,1吞掉。 @@ -56,7 +57,7 @@ public class SendMessageHandler extends IMHandler { } } } - + mSensitiveMessageForwardUrl = mServer.getConfig().getProperty(BrokerConstants.MESSAGE_Sensitive_Forward_Url); mMentionForwardUrl = mServer.getConfig().getProperty(BrokerConstants.MESSAGE_MentionMsg_Forward_Url); try { @@ -194,6 +195,9 @@ public class SendMessageHandler extends IMHandler { Set matched = m_messagesStore.handleSensitiveWord(message.getContent().getSearchableContent()); if (matched != null && !matched.isEmpty()) { m_messagesStore.storeSensitiveMessage(message); + if (!StringUtil.isNullOrEmpty(mSensitiveMessageForwardUrl)) { + publisher.forwardMessage(message, mSensitiveMessageForwardUrl, outputClient); + } if (mSensitiveType == 0) { errorCode = ErrorCode.ERROR_CODE_SENSITIVE_MATCHED; } else if (mSensitiveType == 1) { diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index 9343fee6..1dffc245 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -300,11 +300,14 @@ push.ios.server.address http://localhost:8085/ios/push ##需要转发的消息类型,当有多个时以英文逗号分割。如果转发所有消息,请注释掉配置或者设置为空 #message.forward.types 1,2,3 +##敏感消息转发地址 +##注意回调是单线程回调,接收服务必须在同一内网,且异步处理快速返回,否则会有延迟问题!! +#message.sensitive.forward.url http://localhost:8888/im_event/message + ##提醒消息转发地址,@全体用户和@某个用户消息会回调此地址。此转发不受${message.forward.types}限制。 ##注意回调是单线程回调,接收服务必须在同一内网,且异步处理快速返回,否则会有延迟问题!! #message.mentionmsg.forward.url http://localhost:8888/im_event/message - ##设备信息转发地址 ##注意回调是单线程回调,接收服务必须在同一内网,且异步处理快速返回,否则会有延迟问题!! #things_message.forward.url http://localhost:8087/im_event/things/message