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
提交
33390eb8
提交
33390eb8
编写于
8月 23, 2018
作者:
minghao.wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: 增加内容检测
上级
8c2daa0f
变更
3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
142 行增加
和
0 行删除
+142
-0
AntiSpamController.java
...e/exam/analysis/server/controller/AntiSpamController.java
+16
-0
HttpClient4Utils.java
...d/online/exam/analysis/server/utils/HttpClient4Utils.java
+88
-0
SignatureUtils.java
...oud/online/exam/analysis/server/utils/SignatureUtils.java
+38
-0
未找到文件。
server/src/main/java/com/pica/cloud/online/exam/analysis/server/controller/AntiSpamController.java
0 → 100644
浏览文件 @
33390eb8
package
com
.
pica
.
cloud
.
online
.
exam
.
analysis
.
server
.
controller
;
import
io.swagger.annotations.Api
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @author wuminghao
* @date 2018/8/23 15:42
*/
@RestController
@RequestMapping
(
"/antispam"
)
@Api
(
value
=
"垃圾检测"
,
description
=
"检查文本、图像违禁词汇及广告"
)
public
class
AntiSpamController
{
}
server/src/main/java/com/pica/cloud/online/exam/analysis/server/utils/HttpClient4Utils.java
0 → 100644
浏览文件 @
33390eb8
package
com
.
pica
.
cloud
.
online
.
exam
.
analysis
.
server
.
utils
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
import
java.io.IOException
;
import
java.nio.charset.Charset
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author wuminghao
* @date 2018/8/23 15:44
*/
public
class
HttpClient4Utils
{
/**
* 实例化HttpClient
* @param maxTotal
* @param maxPerRoute
* @param socketTimeout
* @param connectTimeout
* @param connectionRequestTimeout
* @return
*/
public
static
HttpClient
createHttpClient
(
int
maxTotal
,
int
maxPerRoute
,
int
socketTimeout
,
int
connectTimeout
,
int
connectionRequestTimeout
)
{
RequestConfig
defaultRequestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
socketTimeout
)
.
setConnectTimeout
(
connectTimeout
).
setConnectionRequestTimeout
(
connectionRequestTimeout
).
build
();
PoolingHttpClientConnectionManager
cm
=
new
PoolingHttpClientConnectionManager
();
cm
.
setMaxTotal
(
maxTotal
);
cm
.
setDefaultMaxPerRoute
(
maxPerRoute
);
CloseableHttpClient
httpClient
=
HttpClients
.
custom
().
setConnectionManager
(
cm
)
.
setDefaultRequestConfig
(
defaultRequestConfig
).
build
();
return
httpClient
;
}
/**
* 发送post请求
* @param httpClient
* @param url 请求地址
* @param params 请求参数
* @param encoding 编码
* @return
*/
public
static
String
sendPost
(
HttpClient
httpClient
,
String
url
,
Map
<
String
,
String
>
params
,
Charset
encoding
)
{
String
resp
=
""
;
HttpPost
httpPost
=
new
HttpPost
(
url
);
if
(
params
!=
null
&&
params
.
size
()
>
0
)
{
List
<
NameValuePair
>
formParams
=
new
ArrayList
<
NameValuePair
>();
Iterator
<
Map
.
Entry
<
String
,
String
>>
itr
=
params
.
entrySet
().
iterator
();
while
(
itr
.
hasNext
())
{
Map
.
Entry
<
String
,
String
>
entry
=
itr
.
next
();
formParams
.
add
(
new
BasicNameValuePair
(
entry
.
getKey
(),
entry
.
getValue
()));
}
UrlEncodedFormEntity
postEntity
=
new
UrlEncodedFormEntity
(
formParams
,
encoding
);
httpPost
.
setEntity
(
postEntity
);
}
CloseableHttpResponse
response
=
null
;
try
{
response
=
(
CloseableHttpResponse
)
httpClient
.
execute
(
httpPost
);
resp
=
EntityUtils
.
toString
(
response
.
getEntity
(),
encoding
);
}
catch
(
Exception
e
)
{
// log
e
.
printStackTrace
();
}
finally
{
if
(
response
!=
null
)
{
try
{
response
.
close
();
}
catch
(
IOException
e
)
{
// log
e
.
printStackTrace
();
}
}
}
return
resp
;
}
}
server/src/main/java/com/pica/cloud/online/exam/analysis/server/utils/SignatureUtils.java
0 → 100644
浏览文件 @
33390eb8
package
com
.
pica
.
cloud
.
online
.
exam
.
analysis
.
server
.
utils
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Arrays
;
import
java.util.Map
;
/**
* @author wuminghao
* @date 2018/8/23 15:45
*/
public
class
SignatureUtils
{
/**
* 生成签名信息
* @param secretKey 产品私钥
* @param params 接口请求参数名和参数值map,不包括signature参数名
* @return
* @throws UnsupportedEncodingException
*/
public
static
String
genSignature
(
String
secretKey
,
Map
<
String
,
String
>
params
)
throws
UnsupportedEncodingException
{
// 1. 参数名按照ASCII码表升序排序
String
[]
keys
=
params
.
keySet
().
toArray
(
new
String
[
0
]);
Arrays
.
sort
(
keys
);
// 2. 按照排序拼接参数名与参数值
StringBuffer
paramBuffer
=
new
StringBuffer
();
for
(
String
key
:
keys
)
{
paramBuffer
.
append
(
key
).
append
(
params
.
get
(
key
)
==
null
?
""
:
params
.
get
(
key
));
}
// 3. 将secretKey拼接到最后
paramBuffer
.
append
(
secretKey
);
// 4. MD5是128位长度的摘要算法,用16进制表示,一个十六进制的字符能表示4个位,所以签名后的字符串长度固定为32个十六进制字符。
return
DigestUtils
.
md5Hex
(
paramBuffer
.
toString
().
getBytes
(
"UTF-8"
));
}
}
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录