记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董敬伟
liquidnet-bus-v1
Commits
97f65d49
Commit
97f65d49
authored
Sep 08, 2021
by
anjiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交chime社交相关
parent
e772ce93
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
315 additions
and
1 deletion
+315
-1
HttpUtil.java
...c/main/java/com/liquidnet/commons/lang/util/HttpUtil.java
+40
-1
ShumeiBiz.java
...java/com/liquidnet/common/third/shumei/biz/ShumeiBiz.java
+70
-0
ShumeiConfig.java
...om/liquidnet/common/third/shumei/config/ShumeiConfig.java
+31
-0
ShumeiConstant.java
...iquidnet/common/third/shumei/constant/ShumeiConstant.java
+52
-0
ShumeiUtil.java
...va/com/liquidnet/common/third/shumei/util/ShumeiUtil.java
+78
-0
pom.xml
...uidnet-service-chime/liquidnet-service-chime-impl/pom.xml
+5
-0
TestShumei.java
...est/java/com/liquidnet/service/chime/test/TestShumei.java
+39
-0
No files found.
liquidnet-bus-common/liquidnet-common-base/src/main/java/com/liquidnet/commons/lang/util/HttpUtil.java
View file @
97f65d49
package
com
.
liquidnet
.
commons
.
lang
.
util
;
package
com
.
liquidnet
.
commons
.
lang
.
util
;
import
com.alibaba.fastjson.JSONObject
;
import
com.liquidnet.commons.lang.util.spring.RestTemplateConfig
;
import
com.liquidnet.commons.lang.util.spring.RestTemplateConfig
;
import
org.springframework.http.*
;
import
org.springframework.http.*
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.LinkedMultiValueMap
;
...
@@ -81,7 +82,6 @@ public class HttpUtil {
...
@@ -81,7 +82,6 @@ public class HttpUtil {
HttpEntity
<
Object
>
httpEntity
=
new
HttpEntity
(
jsonStr
,
httpHeaders
);
HttpEntity
<
Object
>
httpEntity
=
new
HttpEntity
(
jsonStr
,
httpHeaders
);
// 提交方式:表单、json
// 提交方式:表单、json
// ResponseEntity<String> response = restTemplate.exchange(url, method, httpEntity, String.class);
Object
respObj
=
restTemplate
.
postForEntity
(
url
,
httpEntity
,
Object
.
class
).
getBody
();;
Object
respObj
=
restTemplate
.
postForEntity
(
url
,
httpEntity
,
Object
.
class
).
getBody
();;
return
JsonUtils
.
toJson
(
respObj
);
return
JsonUtils
.
toJson
(
respObj
);
}
}
...
@@ -111,6 +111,45 @@ public class HttpUtil {
...
@@ -111,6 +111,45 @@ public class HttpUtil {
return
JsonUtils
.
toJson
(
respObj
);
return
JsonUtils
.
toJson
(
respObj
);
}
}
/**
* josn post提交
* @param url
* @param jsonParam
* @return
*/
public
static
JSONObject
httpPost
(
String
url
,
JSONObject
jsonParam
)
{
JSONObject
rsResultObj
=
null
;
String
result
=
null
;
try
{
MultiValueMap
<
String
,
String
>
commonHeader
=
new
LinkedMultiValueMap
();
commonHeader
.
add
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
commonHeader
.
add
(
"Accept"
,
"application/json;charset=UTF-8"
);
if
(
url
==
null
||
url
.
trim
().
isEmpty
())
{
return
null
;
}
// header
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
if
(
commonHeader
!=
null
)
{
httpHeaders
.
addAll
(
commonHeader
);
}
HttpEntity
<
String
>
httpEntity
=
new
HttpEntity
(
jsonParam
,
httpHeaders
);
ResponseEntity
<
String
>
response
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
if
(
response
.
getStatusCodeValue
()
==
200
)
{
result
=
response
.
getBody
();
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"posturl:"
+
url
+
", err="
+
e
.
getMessage
());
}
if
(
result
!=
null
){
rsResultObj
=
JSONObject
.
parseObject
(
result
);
}
return
rsResultObj
;
}
/**
/**
* put请求
* put请求
*
*
...
...
liquidnet-bus-common/liquidnet-common-third/liquidnet-common-third-shumei/src/main/java/com/liquidnet/common/third/shumei/biz/ShumeiBiz.java
0 → 100644
View file @
97f65d49
package
com
.
liquidnet
.
common
.
third
.
shumei
.
biz
;
import
com.alibaba.fastjson.JSONObject
;
import
com.liquidnet.common.third.shumei.config.ShumeiConfig
;
import
com.liquidnet.commons.lang.util.HttpUtil
;
import
com.liquidnet.commons.lang.util.JsonUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: ShumeiBiz
* @Package com.liquidnet.common.third.shumei.biz
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/9/7 18:49
*/
@Component
public
class
ShumeiBiz
{
@Autowired
private
ShumeiConfig
shumeiConfig
;
/**
*
* @param text
* @param userId
* @return
*/
public
JSONObject
checkText
(
String
userId
,
String
text
){
HashMap
<
String
,
Object
>
payload
=
new
HashMap
<
String
,
Object
>();
payload
.
put
(
"accessKey"
,
shumeiConfig
.
getAccessKey
());
payload
.
put
(
"appId"
,
"default"
);
payload
.
put
(
"eventId"
,
"nickname"
);
payload
.
put
(
"type"
,
"ALL"
);
HashMap
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
data
.
put
(
"text"
,
text
);
data
.
put
(
"tokenId"
,
userId
);
payload
.
put
(
"data"
,
data
);
JSONObject
json
=
JSONObject
.
parseObject
(
JsonUtils
.
toJson
(
payload
));
JSONObject
result
=
HttpUtil
.
httpPost
(
shumeiConfig
.
getTextUrl
(),
json
);
return
result
;
}
public
JSONObject
checkImage
(
String
userId
,
String
imageUrl
){
HashMap
<
String
,
Object
>
payload
=
new
HashMap
<
String
,
Object
>();
payload
.
put
(
"accessKey"
,
shumeiConfig
.
getAccessKey
());
payload
.
put
(
"appId"
,
"default"
);
payload
.
put
(
"eventId"
,
"article"
);
payload
.
put
(
"type"
,
"POLITICS_PORN_AD_BAN_VIOLENCE"
);
//请求的数据内容,最长10MB
HashMap
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
// data.put("img", Utils.readFileToBase64("../files/demo.png"));
data
.
put
(
"img"
,
imageUrl
);
data
.
put
(
"tokenId"
,
userId
);
payload
.
put
(
"data"
,
data
);
JSONObject
json
=
JSONObject
.
parseObject
(
JsonUtils
.
toJson
(
payload
));
JSONObject
result
=
HttpUtil
.
httpPost
(
shumeiConfig
.
getImageUrl
(),
json
);
return
result
;
}
}
liquidnet-bus-common/liquidnet-common-third/liquidnet-common-third-shumei/src/main/java/com/liquidnet/common/third/shumei/config/ShumeiConfig.java
0 → 100644
View file @
97f65d49
package
com
.
liquidnet
.
common
.
third
.
shumei
.
config
;
import
org.springframework.stereotype.Component
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: 数美验证
* @class: ShumeiConfig
* @Package com.liquidnet.common.third.shumei
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/9/7 18:48
*/
@Component
public
class
ShumeiConfig
{
private
static
final
String
TEXT_URL
=
"http://api-text-bj.fengkongcloud.com/text/v4"
;
private
static
final
String
IMAGE_URL
=
"http://api-img-bj.fengkongcloud.com/image/v4"
;
private
static
final
String
ACCESS_KEY
=
"YOtWhwTAchS5MRGL9hOf"
;
public
String
getAccessKey
(){
return
ACCESS_KEY
;
}
public
String
getTextUrl
(){
return
TEXT_URL
;
}
public
String
getImageUrl
()
{
return
IMAGE_URL
;
}
}
liquidnet-bus-common/liquidnet-common-third/liquidnet-common-third-shumei/src/main/java/com/liquidnet/common/third/shumei/constant/ShumeiConstant.java
0 → 100644
View file @
97f65d49
package
com
.
liquidnet
.
common
.
third
.
shumei
.
constant
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: ShumeiConstant
* @Package com.liquidnet.common.third.shumei.constant
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/9/8 10:40
*/
public
class
ShumeiConstant
{
public
enum
ResponseCodeEnum
{
SUCCESS
(
"1100"
,
"成功"
),
QPS_ULTRALIMIT
(
"1901"
,
"QPS 超限"
),
PARAM_ILLEGAL
(
"1902"
,
"参数不合法"
),
SERVER_FAIL
(
"1903"
,
"服务失败"
),
IMAGE_DOWNLOAD_FAIL
(
"1911"
,
"图片下载失败"
),
BALANCE_NOT_ENOUGH
(
"9100"
,
"余额不足"
),
NO_PERMISSION
(
"9101"
,
"无权限操作"
);
private
String
code
;
private
String
message
;
ResponseCodeEnum
(
String
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
public
String
getCode
()
{
return
code
;
}
public
String
getMessage
(){
return
message
;};
}
public
enum
RiskLevelEnum
{
PASS
(
"PASS"
,
"正常"
),
REVIEW
(
"REVIEW"
,
"可疑"
),
REJECT
(
"REJECT"
,
"违规"
);
private
String
code
;
private
String
message
;
RiskLevelEnum
(
String
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
public
String
getCode
()
{
return
code
;
}
public
String
getMessage
(){
return
message
;};
}
}
liquidnet-bus-common/liquidnet-common-third/liquidnet-common-third-shumei/src/main/java/com/liquidnet/common/third/shumei/util/ShumeiUtil.java
0 → 100644
View file @
97f65d49
package
com
.
liquidnet
.
common
.
third
.
shumei
.
util
;
import
com.alibaba.fastjson.JSONObject
;
import
com.liquidnet.common.third.shumei.biz.ShumeiBiz
;
import
com.liquidnet.common.third.shumei.constant.ShumeiConstant
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: 数美工具类
* @class: ShumeiUtil
* @Package com.liquidnet.common.third.shumei.util
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/9/7 17:46
*/
@Slf4j
@Component
public
class
ShumeiUtil
{
@Autowired
private
ShumeiBiz
shumeiBiz
;
public
boolean
checkText
(
String
userId
,
String
text
){
log
.
info
(
"ShumeiUtil.checkText userId:{} text:{}"
,
userId
,
text
);
try
{
JSONObject
result
=
shumeiBiz
.
checkText
(
userId
,
text
);
log
.
info
(
"checkText result :{} "
,
result
);
if
(
result
!=
null
)
{
log
.
info
(
"checkText result code:{} "
,
result
.
get
(
"code"
));
if
(
result
.
get
(
"code"
).
toString
().
equals
(
ShumeiConstant
.
ResponseCodeEnum
.
SUCCESS
.
getCode
()))
{
String
riskLevel
=
result
.
get
(
"riskLevel"
).
toString
();
log
.
info
(
"checkText result riskLevel:{} "
,
riskLevel
);
if
(
riskLevel
.
equalsIgnoreCase
(
ShumeiConstant
.
RiskLevelEnum
.
PASS
.
getCode
())){
return
true
;
}
}
}
else
{
log
.
error
(
"checkText result is null:{} "
,
result
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"ShumeiUtil.checkText error userId:{} text:{}"
,
userId
,
text
);
log
.
error
(
"ShumeiUtil.checkText error msg:{}"
,
e
.
getMessage
());
return
false
;
}
return
false
;
}
public
boolean
checkImage
(
String
userId
,
String
imageUrl
){
log
.
info
(
"ShumeiUtil.checkText userId:{} imageUrl:{}"
,
userId
,
imageUrl
);
try
{
JSONObject
result
=
shumeiBiz
.
checkImage
(
userId
,
imageUrl
);
log
.
info
(
"checkText result :{} "
,
result
);
if
(
result
!=
null
)
{
log
.
info
(
"checkText result code:{} "
,
result
.
get
(
"code"
));
if
(
result
.
get
(
"code"
).
toString
().
equals
(
ShumeiConstant
.
ResponseCodeEnum
.
SUCCESS
.
getCode
()))
{
String
riskLevel
=
result
.
get
(
"riskLevel"
).
toString
();
String
requestId
=
result
.
get
(
"requestId"
).
toString
();
String
riskDescription
=
result
.
get
(
"riskDescription"
).
toString
();
log
.
info
(
"checkText result riskLevel:{} "
,
riskLevel
);
log
.
info
(
"checkText result requestId:{} "
,
requestId
);
log
.
info
(
"checkText result riskDescription:{} "
,
riskDescription
);
if
(
riskLevel
.
equalsIgnoreCase
(
ShumeiConstant
.
RiskLevelEnum
.
PASS
.
getCode
())){
return
true
;
}
}
}
else
{
log
.
error
(
"checkText result is null:{} "
,
result
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"ShumeiUtil.checkText error userId:{} text:{}"
,
userId
,
imageUrl
);
log
.
error
(
"ShumeiUtil.checkText error msg:{}"
,
e
.
getMessage
());
return
false
;
}
return
false
;
}
}
\ No newline at end of file
liquidnet-bus-service/liquidnet-service-chime/liquidnet-service-chime-impl/pom.xml
View file @
97f65d49
...
@@ -46,6 +46,11 @@
...
@@ -46,6 +46,11 @@
<artifactId>
liquidnet-common-third-easemob
</artifactId>
<artifactId>
liquidnet-common-third-easemob
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.liquidnet
</groupId>
<artifactId>
liquidnet-common-third-shumei
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
liquidnet-bus-service/liquidnet-service-chime/liquidnet-service-chime-impl/src/test/java/com/liquidnet/service/chime/test/TestShumei.java
0 → 100644
View file @
97f65d49
package
com
.
liquidnet
.
service
.
chime
.
test
;
import
com.liquidnet.common.third.shumei.util.ShumeiUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: TestShumei
* @Package com.liquidnet.service.chime.test
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/9/8 13:43
*/
@Slf4j
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
TestShumei
{
@Autowired
private
ShumeiUtil
shumeiUtil
;
@Test
public
void
checkText
(){
shumeiUtil
.
checkText
(
"user123"
,
"习近平"
);
}
@Test
public
void
checkImage
(){
//暴力血腥
// String imageUrl = "https://image11.m1905.cn/uploadfile/s2010/0603/20100603015651967.jpg";
//涉黄
String
imageUrl
=
"https://img2.baidu.com/it/u=276463273,2526848266&fm=26&fmt=auto&gp=0.jpg"
;
shumeiUtil
.
checkImage
(
"user123"
,
imageUrl
);
}
}
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