Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3e897ce8
authored
Aug 25, 2021
by
danmo
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
审计功能完善,解决敏感词无法触发问题
1 parent
481f8985
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
15 deletions
linkwe-framework/src/main/java/com/linkwechat/framework/listener/ChatMsgCheckListener.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeChatContactSensitiveMsg.java
linkwe-framework/src/main/java/com/linkwechat/framework/listener/ChatMsgCheckListener.java
View file @
3e897ce
...
@@ -26,6 +26,7 @@ import org.springframework.data.redis.connection.MessageListener;
...
@@ -26,6 +26,7 @@ import org.springframework.data.redis.connection.MessageListener;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -77,27 +78,35 @@ public class ChatMsgCheckListener implements MessageListener {
...
@@ -77,27 +78,35 @@ public class ChatMsgCheckListener implements MessageListener {
private
void
handleSensitiveHit
(
JSONObject
jsonObject
)
{
private
void
handleSensitiveHit
(
JSONObject
jsonObject
)
{
String
from
=
jsonObject
.
getString
(
"from"
);
String
from
=
jsonObject
.
getString
(
"from"
);
String
msgId
=
jsonObject
.
getString
(
"msgid"
);
String
msgId
=
jsonObject
.
getString
(
"msgid"
);
String
content
=
jsonObject
.
getString
(
"contact"
);
String
msgtype
=
jsonObject
.
getString
(
"msgtype"
);
StringBuilder
objectString
=
new
StringBuilder
(
jsonObject
.
getString
(
msgtype
));
if
(
"external_redpacket"
.
equals
(
msgtype
)){
objectString
.
append
(
jsonObject
.
getString
(
"redpacket"
));
}
else
if
(
"docmsg"
.
equals
(
msgtype
)){
objectString
.
append
(
jsonObject
.
getString
(
"doc"
));
}
else
if
(
"markdown"
.
equals
(
msgtype
)
||
"news"
.
equals
(
msgtype
)){
objectString
.
append
(
jsonObject
.
getString
(
"info"
));
}
log
.
info
(
"执行敏感词命中过滤,time=[{}]"
,
System
.
currentTimeMillis
());
log
.
info
(
"执行敏感词命中过滤,time=[{}]"
,
System
.
currentTimeMillis
());
//获取所有的敏感词规则
//获取所有的敏感词规则
List
<
WeSensitive
>
allSensitiveRules
=
weSensitiveMapper
.
selectWeSensitiveList
(
new
WeSensitive
());
List
<
WeSensitive
>
allSensitiveRules
=
weSensitiveMapper
.
selectWeSensitiveList
(
new
WeSensitive
());
//根据规则过滤命中
//根据规则过滤命中
if
(
CollectionUtils
.
isNotEmpty
(
allSensitiveRules
))
{
if
(
CollectionUtils
.
isNotEmpty
(
allSensitiveRules
))
{
String
finalContent
=
content
;
String
finalContent
=
objectString
.
toString
()
;
allSensitiveRules
.
parallelStream
().
forEach
(
weSensitive
->
{
allSensitiveRules
.
forEach
(
weSensitive
->
{
List
<
String
>
patternWords
=
Arrays
.
asList
(
weSensitive
.
getPatternWords
().
split
(
","
));
List
<
String
>
patternWords
=
Arrays
.
asList
(
weSensitive
.
getPatternWords
().
split
(
","
));
List
<
String
>
users
=
weSensitiveService
.
getScopeUsers
(
weSensitive
.
getAuditUserScope
());
List
<
String
>
users
=
weSensitiveService
.
getScopeUsers
(
weSensitive
.
getAuditUserScope
());
log
.
info
(
"handleSensitiveHit: >>>>>>>>>>>>>>>>>>>>>>finalContent:{}, patternWords:{},users:{},from:{}"
,
finalContent
,
JSONObject
.
toJSONString
(
patternWords
),
JSONObject
.
toJSONString
(
users
),
from
);
if
(
StringUtils
.
isNotBlank
(
finalContent
)
if
(
StringUtils
.
isNotBlank
(
finalContent
)
&&
!
CollectionUtils
.
isEmpty
(
users
)
&&
!
CollectionUtils
.
isEmpty
(
users
)
&&
users
.
stream
().
anyMatch
(
from:
:
equals
))
{
&&
users
.
stream
().
anyMatch
(
from:
:
equals
))
{
WeChatContactSensitiveMsg
wccsm
=
hitSensitive
(
patternWords
,
from
,
finalContent
);
WeChatContactSensitiveMsg
wccsm
=
hitSensitive
(
patternWords
,
from
,
finalContent
);
log
.
info
(
"handleSensitiveHit: >>>>>>>>>>>>>>>>>>>>>> wccsm:{}"
,
JSONObject
.
toJSONString
(
wccsm
));
if
(
wccsm
!=
null
)
{
if
(
wccsm
!=
null
)
{
LambdaQueryWrapper
<
WeChatContactMsg
>
wrapper
=
new
LambdaQueryWrapper
<>();
wccsm
.
setMsgId
(
msgId
);
wrapper
.
eq
(
WeChatContactMsg:
:
getMsgId
,
msgId
);
wccsm
.
setFrom
(
from
);
WeChatContactMsg
ccm
=
weChatContactMsgService
.
getOne
(
wrapper
);
wccsm
.
setMsgTime
(
new
Date
(
jsonObject
.
getLong
(
"msgtime"
)));
wccsm
.
setWeChatContactId
(
ccm
.
getId
());
wccsm
.
setFrom
(
ccm
.
getFromId
());
wccsm
.
setMsgTime
(
ccm
.
getMsgTime
());
int
result
=
weChatContactSensitiveMsgMapper
.
insert
(
wccsm
);
int
result
=
weChatContactSensitiveMsgMapper
.
insert
(
wccsm
);
if
(
result
>
0
)
{
if
(
result
>
0
)
{
sendMessage
(
wccsm
,
weSensitive
);
sendMessage
(
wccsm
,
weSensitive
);
...
@@ -110,11 +119,12 @@ public class ChatMsgCheckListener implements MessageListener {
...
@@ -110,11 +119,12 @@ public class ChatMsgCheckListener implements MessageListener {
private
WeChatContactSensitiveMsg
hitSensitive
(
List
<
String
>
patternWords
,
String
user
,
String
content
)
{
private
WeChatContactSensitiveMsg
hitSensitive
(
List
<
String
>
patternWords
,
String
user
,
String
content
)
{
WeChatContactSensitiveMsg
weChatContactSensitiveMsg
=
new
WeChatContactSensitiveMsg
();
WeChatContactSensitiveMsg
weChatContactSensitiveMsg
=
new
WeChatContactSensitiveMsg
();
patternWords
=
patternWords
.
stream
().
filter
(
content:
:
contains
).
collect
(
Collectors
.
toList
());
String
patternWordStr
=
patternWords
.
stream
().
filter
(
content
.
trim
()::
contains
).
collect
(
Collectors
.
joining
(
","
));
if
(!
CollectionUtils
.
isEmpty
(
patternWords
))
{
log
.
info
(
"hitSensitive: >>>>>>>>>>>>>>>>>>>>>> patternWordStr:{}"
,
patternWordStr
);
if
(
StringUtils
.
isNotEmpty
(
patternWordStr
))
{
weChatContactSensitiveMsg
.
setContent
(
content
);
weChatContactSensitiveMsg
.
setContent
(
content
);
weChatContactSensitiveMsg
.
setSendStatus
(
0
);
weChatContactSensitiveMsg
.
setSendStatus
(
0
);
weChatContactSensitiveMsg
.
setPatternWords
(
String
.
join
(
", "
,
patternWords
)
);
weChatContactSensitiveMsg
.
setPatternWords
(
patternWordStr
);
return
weChatContactSensitiveMsg
;
return
weChatContactSensitiveMsg
;
}
}
return
null
;
return
null
;
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/WeChatContactSensitiveMsg.java
View file @
3e897ce
...
@@ -38,9 +38,9 @@ public class WeChatContactSensitiveMsg extends BaseEntity implements Serializabl
...
@@ -38,9 +38,9 @@ public class WeChatContactSensitiveMsg extends BaseEntity implements Serializabl
/**
/**
* 主键id
* 主键id
*/
*/
@Excel
(
name
=
"消息
表关联
id"
)
@Excel
(
name
=
"消息id"
)
@ApiModelProperty
(
"消息
表关联
id"
)
@ApiModelProperty
(
"消息id"
)
private
Long
weChatContact
Id
;
private
String
msg
Id
;
@Excel
(
name
=
"通知发送状态"
)
@Excel
(
name
=
"通知发送状态"
)
@ApiModelProperty
(
"通知发送状态, 0 未发送 1 已发送"
)
@ApiModelProperty
(
"通知发送状态, 0 未发送 1 已发送"
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment