提交 f2b8cf43 编写于 作者: minghao.wu's avatar minghao.wu

fix: 新增是否过滤广告的参数

上级 b4e601ef
......@@ -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;
}
......
......@@ -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;
......
......@@ -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 processText(@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);
}
}
......@@ -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);
......
......@@ -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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册