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
提交
f2b8cf43
提交
f2b8cf43
编写于
9月 12, 2018
作者:
minghao.wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 新增是否过滤广告的参数
上级
b4e601ef
变更
5
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
76 行增加
和
15 行删除
+76
-15
PropertiesConfiguration.java
...nalysis/server/configuration/PropertiesConfiguration.java
+11
-0
AnalysisController.java
...e/exam/analysis/server/controller/AnalysisController.java
+1
-1
AntiSpamController.java
...e/exam/analysis/server/controller/AntiSpamController.java
+48
-11
AntiSpamService.java
.../online/exam/analysis/server/service/AntiSpamService.java
+9
-1
AntiSpamServiceImpl.java
...xam/analysis/server/service/impl/AntiSpamServiceImpl.java
+7
-2
未找到文件。
server/src/main/java/com/pica/cloud/online/exam/analysis/server/configuration/PropertiesConfiguration.java
浏览文件 @
f2b8cf43
...
...
@@ -22,6 +22,9 @@ public class PropertiesConfiguration {
@Value
(
"${netease.antispam.text.businessid}"
)
private
String
neteaseAntispamTextBusinessId
;
@Value
(
"${netease.antispam.text.ad.businessid}"
)
private
String
neteaseAntispamTextAdBusinessId
;
@Value
(
"${netease.antispam.image.apiurl}"
)
private
String
neteaseAntispamImageApiUrl
;
...
...
@@ -74,6 +77,14 @@ public class PropertiesConfiguration {
this
.
neteaseAntispamTextBusinessId
=
neteaseAntispamTextBusinessId
;
}
public
String
getNeteaseAntispamTextAdBusinessId
()
{
return
neteaseAntispamTextAdBusinessId
;
}
public
void
setNeteaseAntispamTextAdBusinessId
(
String
neteaseAntispamTextAdBusinessId
)
{
this
.
neteaseAntispamTextAdBusinessId
=
neteaseAntispamTextAdBusinessId
;
}
public
String
getNeteaseAntispamImageApiUrl
()
{
return
neteaseAntispamImageApiUrl
;
}
...
...
server/src/main/java/com/pica/cloud/online/exam/analysis/server/controller/AnalysisController.java
浏览文件 @
f2b8cf43
...
...
@@ -549,7 +549,7 @@ public class AnalysisController {
/**
* 如果判断检测的数据中有垃圾 直接返回
*/
PicaResponse
response
=
antiSpamService
.
processString
(
user
!=
null
?
user
.
getId
()
:
0
,
sysCode
,
content
);
PicaResponse
response
=
antiSpamService
.
processString
(
user
!=
null
?
user
.
getId
()
:
0
,
sysCode
,
content
,
false
);
if
(!
response
.
getCode
().
equals
(
PicaResultCode
.
SUCCESS
.
code
()))
{
response
.
setData
(
""
);
return
response
;
...
...
server/src/main/java/com/pica/cloud/online/exam/analysis/server/controller/AntiSpamController.java
浏览文件 @
f2b8cf43
...
...
@@ -28,31 +28,68 @@ public class AntiSpamController {
AntiSpamService
antiSpamService
;
@ApiOperation
(
value
=
"内容检测"
,
response
=
PicaResponse
.
class
)
@RequestMapping
(
value
=
"/"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
public
PicaResponse
process
(
@RequestBody
String
content
,
@RequestMapping
(
value
=
"/
text
"
,
method
=
RequestMethod
.
POST
,
produces
=
"application/json;charset=UTF-8"
)
public
PicaResponse
process
Text
(
@RequestBody
String
content
,
@RequestHeader
String
sysCode
,
@RequestHeader
String
token
)
{
if
(
token
==
null
)
{
PicaResponse
picaResponse
=
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
SYSTEM_NO_TOKEN
);
picaResponse
.
setData
(
""
);
return
picaResponse
;
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
SYSTEM_NO_TOKEN
);
}
PICAUser
user
=
CommonUtils
.
getUserByToken
(
redisClient
,
token
);
if
(
user
==
null
||
user
.
getId
().
intValue
()
==
0
)
{
PicaResponse
picaResponse
=
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
LOGIN_FAILE
);
picaResponse
.
setData
(
""
);
return
picaResponse
;
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
LOGIN_FAILE
);
}
StringBuilder
sbContent
=
new
StringBuilder
();
/**
* type:0 不检测广告 其他: 检测广告, 默认不检测
*/
Integer
type
=
0
;
try
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
content
);
content
=
jsonObject
.
get
(
"content"
).
toString
();
sbContent
.
append
(
jsonObject
.
get
(
"content"
).
toString
());
type
=
(
jsonObject
.
get
(
"type"
)
!=
null
?
Integer
.
parseInt
(
jsonObject
.
get
(
"type"
).
toString
())
:
0
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"parse error: "
+
content
);
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
PARAM_IS_INVALID
);
}
return
antiSpamService
.
processString
(
user
!=
null
?
user
.
getId
()
:
0
,
sysCode
,
content
);
return
antiSpamService
.
processString
(
user
!=
null
?
user
.
getId
()
:
0
,
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
,
@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
)
{
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
LOGIN_FAILE
);
}
StringBuilder
sbContent
=
new
StringBuilder
();
try
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
content
);
sbContent
.
append
(
jsonObject
.
get
(
"content"
).
toString
());
}
catch
(
Exception
e
)
{
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
PARAM_IS_INVALID
);
}
if
(!
antiSpamService
.
processImageContent
(
user
!=
null
?
user
.
getId
()
:
0
,
sysCode
,
sbContent
.
toString
()))
{
return
ReturnUtil
.
getPicaResponse
(
"400002"
,
"图片包含违禁内容,请修改后重新输入"
,
""
);
}
return
ReturnUtil
.
getPicaResponse
(
PicaResultCode
.
SUCCESS
);
}
}
server/src/main/java/com/pica/cloud/online/exam/analysis/server/service/AntiSpamService.java
浏览文件 @
f2b8cf43
...
...
@@ -7,7 +7,15 @@ import com.pica.cloud.foundation.entity.PicaResponse;
* @date 2018/8/27 14:38
*/
public
interface
AntiSpamService
{
PicaResponse
processString
(
Integer
userId
,
String
sysCode
,
String
content
);
/**
* 解析字符串
* @param userId
* @param sysCode
* @param content
* @param isAdFilterOpen 是否过滤广告
* @return
*/
PicaResponse
processString
(
Integer
userId
,
String
sysCode
,
String
content
,
boolean
isAdFilterOpen
);
boolean
processImageContent
(
Integer
userId
,
String
sysCode
,
String
content
);
...
...
server/src/main/java/com/pica/cloud/online/exam/analysis/server/service/impl/AntiSpamServiceImpl.java
浏览文件 @
f2b8cf43
...
...
@@ -37,7 +37,7 @@ 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
)
{
public
PicaResponse
processString
(
Integer
userId
,
String
sysCode
,
String
content
,
boolean
isAdFilterOpen
)
{
/**
* 过滤图片
*/
...
...
@@ -51,7 +51,12 @@ public class AntiSpamServiceImpl implements AntiSpamService {
* 1. 设置公共参数
*/
params
.
put
(
"secretId"
,
properties
.
getNeteaseAntispamSecretId
());
params
.
put
(
"businessId"
,
properties
.
getNeteaseAntispamTextBusinessId
());
if
(!
isAdFilterOpen
)
params
.
put
(
"businessId"
,
properties
.
getNeteaseAntispamTextBusinessId
());
else
params
.
put
(
"businessId"
,
properties
.
getNeteaseAntispamTextAdBusinessId
());
params
.
put
(
"version"
,
"v3.1"
);
params
.
put
(
"timestamp"
,
String
.
valueOf
(
System
.
currentTimeMillis
()));
params
.
put
(
"nonce"
,
String
.
valueOf
(
new
Random
().
nextInt
()));
...
...
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录