Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
P
pica-cloud-analysis
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
Close sidebar
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
com.pica.cloud.online.exam
pica-cloud-analysis
提交
b7d2be5a
提交
b7d2be5a
编写于
12月 11, 2018
作者:
minghao.wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: 增加processTextV2版本 返回所有的hint
上级
f971cca3
流水线
#2173
已通过 于阶段
in 24 second
变更
5
流水线
1
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
169 行增加
和
22 行删除
+169
-22
AnalysisFeignService.java
...ne/exam/analysis/client/service/AnalysisFeignService.java
+7
-2
AnalysisFeignServiceImpl.java
...nalysis/client/service/impl/AnalysisFeignServiceImpl.java
+6
-1
AntiSpamController.java
...e/exam/analysis/server/controller/AntiSpamController.java
+42
-4
AntiSpamService.java
.../online/exam/analysis/server/service/AntiSpamService.java
+2
-0
AntiSpamServiceImpl.java
...xam/analysis/server/service/impl/AntiSpamServiceImpl.java
+112
-15
未找到文件。
client/src/main/java/com/pica/cloud/online/exam/analysis/client/service/AnalysisFeignService.java
浏览文件 @
b7d2be5a
...
...
@@ -13,8 +13,13 @@ import org.springframework.web.bind.annotation.RequestMethod;
*/
@FeignClient
(
value
=
"10902-PICA-CLOUD-ANALYSIS"
)
public
interface
AnalysisFeignService
{
@RequestMapping
(
value
=
"/analysis/antispam/text"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
PicaResponse
processText
(
@RequestBody
String
content
,
@RequestMapping
(
value
=
"/analysis/antispam/text
/v1
"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
PicaResponse
processText
V1
(
@RequestBody
String
content
,
@RequestHeader
(
value
=
"sysCode"
)
String
sysCode
,
@RequestHeader
(
value
=
"token"
)
String
token
);
@RequestMapping
(
value
=
"/analysis/antispam/text/v2"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
PicaResponse
processTextV2
(
@RequestBody
String
content
,
@RequestHeader
(
value
=
"sysCode"
)
String
sysCode
,
@RequestHeader
(
value
=
"token"
)
String
token
);
}
client/src/main/java/com/pica/cloud/online/exam/analysis/client/service/impl/AnalysisFeignServiceImpl.java
浏览文件 @
b7d2be5a
...
...
@@ -9,7 +9,12 @@ import com.pica.cloud.online.exam.analysis.client.service.AnalysisFeignService;
*/
public
class
AnalysisFeignServiceImpl
implements
AnalysisFeignService
{
@Override
public
PicaResponse
processText
(
String
content
,
String
sysCode
,
String
token
)
{
public
PicaResponse
processTextV1
(
String
content
,
String
sysCode
,
String
token
)
{
return
null
;
}
@Override
public
PicaResponse
processTextV2
(
String
content
,
String
sysCode
,
String
token
)
{
return
null
;
}
}
server/src/main/java/com/pica/cloud/online/exam/analysis/server/controller/AntiSpamController.java
浏览文件 @
b7d2be5a
...
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import
com.pica.cloud.foundation.entity.PicaResponse
;
import
com.pica.cloud.foundation.entity.PicaResultCode
;
import
com.pica.cloud.foundation.redis.RedisClient
;
import
com.pica.cloud.foundation.utils.annotation.LoginPermission
;
import
com.pica.cloud.foundation.utils.entity.PicaUser
;
import
com.pica.cloud.online.exam.analysis.common.CommonUtils
;
import
com.pica.cloud.online.exam.analysis.common.util.ReturnUtil
;
...
...
@@ -29,15 +30,12 @@ public class AntiSpamController {
@Autowired
AntiSpamService
antiSpamService
;
@LoginPermission
@ApiOperation
(
value
=
"内容检测"
,
response
=
PicaResponse
.
class
)
@RequestMapping
(
value
=
"/text"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
public
PicaResponse
processText
(
@RequestBody
String
content
,
@RequestHeader
String
sysCode
,
@RequestHeader
String
token
)
{
if
(
token
==
null
)
{
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
SYSTEM_NO_TOKEN
);
}
PicaUser
user
=
CommonUtils
.
getUserByToken
(
redisClient
,
token
);
if
(
user
==
null
||
user
.
getId
().
intValue
()
==
0
)
{
...
...
@@ -65,6 +63,46 @@ public class AntiSpamController {
);
}
@ApiOperation
(
value
=
"内容检测"
,
response
=
PicaResponse
.
class
)
@RequestMapping
(
value
=
"/text/v1"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
public
PicaResponse
processTextV1
(
@RequestBody
String
content
,
@RequestHeader
String
sysCode
,
@RequestHeader
String
token
)
{
return
processText
(
content
,
sysCode
,
token
);
}
@ApiOperation
(
value
=
"内容检测"
,
response
=
PicaResponse
.
class
)
@RequestMapping
(
value
=
"/text/v2"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
public
PicaResponse
processTextV2
(
@RequestBody
String
content
,
@RequestHeader
String
sysCode
,
@RequestHeader
String
token
)
{
PicaUser
user
=
CommonUtils
.
getUserByToken
(
redisClient
,
token
);
if
(
user
==
null
||
user
.
getId
().
intValue
()
==
0
)
{
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
LOGIN_FAILE
);
}
StringBuilder
sbContent
=
new
StringBuilder
();
/**
* type:0 不检测广告 其他: 检测广告, 默认不检测
*/
Integer
type
=
0
;
try
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
content
);
sbContent
.
append
(
jsonObject
.
get
(
"content"
).
toString
());
type
=
(
jsonObject
.
get
(
"type"
)
!=
null
?
Integer
.
parseInt
(
jsonObject
.
get
(
"type"
).
toString
())
:
0
);
}
catch
(
Exception
e
)
{
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
PARAM_IS_INVALID
);
}
return
antiSpamService
.
processStringV2
(
user
.
getId
(),
sysCode
,
sbContent
.
toString
(),
type
!=
0
);
}
@ApiOperation
(
value
=
"图片检测"
,
response
=
PicaResponse
.
class
)
@RequestMapping
(
value
=
"/image"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
public
PicaResponse
processImage
(
@RequestBody
String
content
,
...
...
server/src/main/java/com/pica/cloud/online/exam/analysis/server/service/AntiSpamService.java
浏览文件 @
b7d2be5a
...
...
@@ -17,6 +17,8 @@ public interface AntiSpamService {
*/
PicaResponse
processString
(
Integer
userId
,
String
sysCode
,
String
content
,
boolean
isAdFilterOpen
);
PicaResponse
processStringV2
(
Integer
userId
,
String
sysCode
,
String
content
,
boolean
isAdFilterOpen
);
boolean
processImageContent
(
Integer
userId
,
String
sysCode
,
String
content
);
boolean
processImage
(
Integer
userId
,
String
sysCode
,
String
url
);
...
...
server/src/main/java/com/pica/cloud/online/exam/analysis/server/service/impl/AntiSpamServiceImpl.java
浏览文件 @
b7d2be5a
...
...
@@ -13,6 +13,7 @@ import com.pica.cloud.online.exam.analysis.server.mapper.AntiSpamRecordMapper;
import
com.pica.cloud.online.exam.analysis.server.service.AntiSpamService
;
import
com.pica.cloud.online.exam.analysis.server.utils.HttpClient4Utils
;
import
com.pica.cloud.online.exam.analysis.server.utils.SignatureUtils
;
import
io.swagger.models.auth.In
;
import
org.apache.http.Consts
;
import
org.apache.http.client.HttpClient
;
import
org.slf4j.Logger
;
...
...
@@ -39,15 +40,8 @@ public class AntiSpamServiceImpl implements AntiSpamService {
private
static
HttpClient
httpClient
=
HttpClient4Utils
.
createHttpClient
(
100
,
20
,
2000
,
2000
,
2000
);
private
static
HttpClient
httpClientImage
=
HttpClient4Utils
.
createHttpClient
(
100
,
20
,
10000
,
2000
,
2000
);
@Override
public
PicaResponse
processString
(
Integer
userId
,
String
sysCode
,
String
content
,
boolean
isAdFilterOpen
)
{
/**
* 过滤图片
*/
if
(!
processImageContent
(
userId
,
sysCode
,
content
))
{
return
ReturnUtil
.
getPicaResponse
(
"400002"
,
"图片包含违禁内容,请修改后重新输入"
,
""
);
}
private
String
neteaseResult
(
String
content
,
boolean
isAdFilterOpen
)
{
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
/**
...
...
@@ -83,7 +77,46 @@ public class AntiSpamServiceImpl implements AntiSpamService {
/**
* 4. 发送HTTP请求
*/
String
response
=
HttpClient4Utils
.
sendPost
(
httpClient
,
properties
.
getNeteaseAntispamTextApiUrl
(),
params
,
Consts
.
UTF_8
);
return
HttpClient4Utils
.
sendPost
(
httpClient
,
properties
.
getNeteaseAntispamTextApiUrl
(),
params
,
Consts
.
UTF_8
);
}
private
String
getMessageByLabel
(
Integer
label
)
{
String
msg
=
""
;
switch
(
label
)
{
case
100
:
msg
=
"输入内容包含色情词汇,请修改后重新输入"
;
break
;
case
200
:
msg
=
"输入内容包含广告词汇,请修改后重新输入"
;
break
;
case
400
:
msg
=
"输入内容包含违禁词汇,请修改后重新输入"
;
break
;
case
500
:
msg
=
"输入内容包含涉政词汇,请修改后重新输入"
;
break
;
case
600
:
msg
=
"输入内容包含谩骂词汇,请修改后重新输入"
;
break
;
case
700
:
msg
=
"输入内容包含灌水词汇,请修改后重新输入"
;
break
;
default
:
break
;
}
return
msg
;
}
@Override
public
PicaResponse
processString
(
Integer
userId
,
String
sysCode
,
String
content
,
boolean
isAdFilterOpen
)
{
/**
* 过滤图片
*/
if
(!
processImageContent
(
userId
,
sysCode
,
content
))
{
return
ReturnUtil
.
getPicaResponse
(
"400002"
,
"图片包含违禁内容,请修改后重新输入"
,
""
);
}
String
response
=
neteaseResult
(
content
,
isAdFilterOpen
);
logger
.
info
(
"content:"
+
content
+
" response="
+
response
);
...
...
@@ -122,12 +155,7 @@ public class AntiSpamServiceImpl implements AntiSpamService {
JsonObject
detailsObject
=
lObject
.
getAsJsonObject
(
"details"
);
JsonArray
hintArray
=
detailsObject
.
getAsJsonArray
(
"hint"
);
if
(
label
==
100
)
msg
=
"输入内容包含色情词汇,请修改后重新输入"
;
else
if
(
label
==
200
)
msg
=
"输入内容包含广告词汇,请修改后重新输入"
;
else
if
(
label
==
400
)
msg
=
"输入内容包含违禁词汇,请修改后重新输入"
;
else
if
(
label
==
500
)
msg
=
"输入内容包含涉政词汇,请修改后重新输入"
;
else
if
(
label
==
600
)
msg
=
"输入内容包含谩骂词汇,请修改后重新输入"
;
else
if
(
label
==
700
)
msg
=
"输入内容包含灌水词汇,请修改后重新输入"
;
msg
=
getMessageByLabel
(
label
);
for
(
JsonElement
eleHint
:
hintArray
)
{
hint
.
append
(
eleHint
.
getAsString
()).
append
(
","
);
...
...
@@ -148,6 +176,75 @@ public class AntiSpamServiceImpl implements AntiSpamService {
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
SUCCESS
,
""
);
}
@Override
public
PicaResponse
processStringV2
(
Integer
userId
,
String
sysCode
,
String
content
,
boolean
isAdFilterOpen
)
{
/**
* 过滤图片
*/
if
(!
processImageContent
(
userId
,
sysCode
,
content
))
{
return
ReturnUtil
.
getPicaResponse
(
"400002"
,
"图片包含违禁内容,请修改后重新输入"
,
""
);
}
String
response
=
neteaseResult
(
content
,
isAdFilterOpen
);
logger
.
info
(
"content:"
+
content
+
" response="
+
response
);
/**
* 5. 解析返回值
*/
JsonObject
jObject
=
new
JsonParser
().
parse
(
response
).
getAsJsonObject
();
int
code
=
jObject
.
get
(
"code"
).
getAsInt
();
String
msg
=
jObject
.
get
(
"msg"
).
getAsString
();
if
(
code
==
200
)
{
JsonObject
resultObject
=
jObject
.
getAsJsonObject
(
"result"
);
int
action
=
resultObject
.
get
(
"action"
).
getAsInt
();
JsonArray
labelArray
=
resultObject
.
getAsJsonArray
(
"labels"
);
/**
* action: 0 通过
* action: 1 嫌疑
* action: 2 不通过
*/
if
(
action
==
0
)
{
insertRecord
(
userId
,
sysCode
,
content
,
response
,
(
byte
)
action
,
0
,
""
);
}
else
{
/**
* 保留第一个label 记录所有的提示信息
*/
int
resLabel
=
0
;
StringBuilder
hint
=
new
StringBuilder
();
for
(
JsonElement
labelElement
:
labelArray
)
{
JsonObject
lObject
=
labelElement
.
getAsJsonObject
();
int
label
=
lObject
.
get
(
"label"
).
getAsInt
();
JsonObject
detailsObject
=
lObject
.
getAsJsonObject
(
"details"
);
JsonArray
hintArray
=
detailsObject
.
getAsJsonArray
(
"hint"
);
if
(
resLabel
==
0
)
{
resLabel
=
label
;
msg
=
getMessageByLabel
(
label
);
}
for
(
JsonElement
eleHint
:
hintArray
)
{
hint
.
append
(
eleHint
.
getAsString
()).
append
(
","
);
}
if
(
hint
.
length
()
>
0
)
{
hint
.
deleteCharAt
(
hint
.
length
()
-
1
);
}
}
/**
* 保存记录
*/
insertRecord
(
userId
,
sysCode
,
content
,
response
,
(
byte
)
action
,
resLabel
,
hint
.
toString
());
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
DATA_IS_WRONG
.
code
(),
msg
,
hint
.
toString
());
}
}
else
{
return
ReturnUtil
.
getPicaResponse
(
jObject
.
get
(
"code"
).
getAsString
(),
msg
,
""
);
}
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
SUCCESS
,
""
);
}
@Override
public
boolean
processImageContent
(
Integer
userId
,
String
sysCode
,
String
content
)
{
List
<
String
>
imageUrlList
=
new
ArrayList
<>();
...
...
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录