Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
d8714078
Commit
d8714078
authored
Aug 02, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
内容检验fix
parent
e38879ab
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
25 deletions
+28
-25
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+22
-16
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+1
-4
TencentcloudUtils.java
...main/java/com/tanpu/community/util/TencentcloudUtils.java
+5
-5
No files found.
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
d8714078
...
...
@@ -6,6 +6,7 @@ import com.tanpu.biz.common.enums.RelTypeEnum;
import
com.tanpu.biz.common.enums.community.CollectionTypeEnum
;
import
com.tanpu.biz.common.enums.community.ReportTypeEnum
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.constant.ErrorCodeConstant
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.community.api.beans.qo.ESThemeQo
;
...
...
@@ -18,7 +19,10 @@ import com.tanpu.community.api.beans.resp.CreateThemeResp;
import
com.tanpu.community.api.beans.resp.ThemeFullSearchResp
;
import
com.tanpu.community.api.beans.resp.ThemeListResp
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp
;
import
com.tanpu.community.api.enums.*
;
import
com.tanpu.community.api.enums.BlockTypeEnum
;
import
com.tanpu.community.api.enums.OperationTypeEnum
;
import
com.tanpu.community.api.enums.ThemeListTypeEnum
;
import
com.tanpu.community.api.enums.ThemeTypeEnum
;
import
com.tanpu.community.cache.RedisCache
;
import
com.tanpu.community.dao.entity.community.*
;
import
com.tanpu.community.feign.fatools.FeignClientForFatools
;
...
...
@@ -39,7 +43,6 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -144,12 +147,9 @@ public class ThemeManager {
ThemeEntity
themeEntity
=
new
ThemeEntity
();
BeanUtils
.
copyProperties
(
req
,
themeEntity
);
themeEntity
.
setAuthorId
(
userId
);
themeEntity
.
setContent
(
JsonUtil
.
toJson
(
req
.
getContent
()));
// 腾讯云敏感词校验
// TODO 图片校验
checkContent
(
themeEntity
.
getContent
(
));
checkContent
(
req
);
themeEntity
.
setContent
(
JsonUtil
.
toJson
(
req
.
getContent
()
));
//附件校验
checkAttachment
(
req
.
getContent
());
...
...
@@ -493,22 +493,28 @@ public class ThemeManager {
/**
* 腾讯云-内容检测
*
* @param
content
* @param
req
*/
private
void
checkContent
(
String
content
)
{
private
void
checkContent
(
CreateThemeReq
req
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
ThemeContentReq
themeContentReq
:
req
.
getContent
())
{
if
(
RelTypeEnum
.
TEXT
.
type
.
equals
(
themeContentReq
.
getType
())){
sb
.
append
(
themeContentReq
.
getValue
());
}
}
String
content
=
sb
.
toString
();
// 腾讯云接口最多支持5000文字校验,超过5000执行2次
// 检查内容是否涉黄违法
CommonResp
commonResp
=
TencentcloudUtils
.
textModeration
(
content
.
length
()
>
5000
?
content
.
substring
(
0
,
5000
)
:
content
);
if
(!
commonResp
.
isSuccess
()
)
{
throw
new
BizException
(
"内容校验失败,请检查内容后重新发送"
);
boolean
b
=
TencentcloudUtils
.
textModeration
(
content
.
length
()
>
5000
?
content
.
substring
(
0
,
5000
)
:
content
);
if
(!
b
)
{
throw
new
BizException
(
ErrorCodeConstant
.
CONTENT_ILLEGAL
);
}
if
(
content
.
length
()
>
5000
)
{
CommonResp
commonResp2
=
TencentcloudUtils
.
textModeration
(
content
.
substring
(
5000
,
content
.
length
()));
if
(!
commonResp2
.
isSuccess
()
)
{
throw
new
BizException
(
"内容校验失败,请检查内容后重新发送"
);
boolean
result
=
TencentcloudUtils
.
textModeration
(
content
.
substring
(
5000
,
content
.
length
()));
if
(!
result
)
{
throw
new
BizException
(
ErrorCodeConstant
.
CONTENT_ILLEGAL
);
}
}
return
;
}
...
...
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
d8714078
...
...
@@ -66,10 +66,7 @@ public class ConvertUtil {
// 抽取文本内容
List
<
ThemeContentQo
>
themeContentQos
=
JsonUtil
.
toBean
(
entity
.
getContent
(),
new
TypeReference
<
List
<
ThemeContentQo
>>()
{});
StringBuilder
sb
=
new
StringBuilder
();
themeContentQos
.
stream
().
filter
(
q
->
{
// todo enum
return
q
.
getType
().
equals
(
"108"
);
}).
forEach
(
q
->
{
themeContentQos
.
stream
().
filter
(
q
->
RelTypeEnum
.
TEXT
.
type
.
equals
(
q
.
getType
())).
forEach
(
q
->
{
sb
.
append
(
q
.
getValue
());
});
qo
.
textContent
=
sb
.
toString
();
...
...
community-service/src/main/java/com/tanpu/community/util/TencentcloudUtils.java
View file @
d8714078
...
...
@@ -79,7 +79,7 @@ public class TencentcloudUtils {
* @param text
* @return
*/
public
static
CommonResp
textModeration
(
String
text
)
{
public
static
boolean
textModeration
(
String
text
)
{
TextModerationRequest
req
=
new
TextModerationRequest
();
req
.
setContent
(
Base64
.
getEncoder
().
encodeToString
(
text
.
getBytes
(
StandardCharsets
.
UTF_8
)));
TextModerationResponse
res
=
null
;
...
...
@@ -87,16 +87,16 @@ public class TencentcloudUtils {
res
=
getTmsClient
().
TextModeration
(
req
);
// suggestion Block 不通过
if
(
res
.
getSuggestion
().
equals
(
"Block"
))
{
// TODO: 2021/7/20
return
CommonResp
.
error
();
return
false
;
// return CommonResp.error(CommonResp.CONTENT_ILLEGAL, getTextLabel(res.getLabel(), res.getKeywords()));
}
}
catch
(
TencentCloudSDKException
e
)
{
log
.
error
(
"调用腾文本内容安全异常"
);
e
.
printStackTrace
();
return
CommonResp
.
failed
(
"文本检查异常"
);
//调用失败时,不影响用户发布主题
return
true
;
}
return
CommonResp
.
success
()
;
return
true
;
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment