Commit 2fdd87b7 authored by 刘基明's avatar 刘基明

文本校验打印违规关键字fix

parent 058d0c2c
......@@ -8,7 +8,6 @@ import com.tanpu.biz.common.enums.RelTypeEnum;
import com.tanpu.biz.common.enums.community.CollectionTypeEnum;
import com.tanpu.biz.common.enums.community.ReportTypeEnum;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.api.ResultCode;
import com.tanpu.common.constant.ErrorCodeConstant;
import com.tanpu.common.enums.fund.ProductTypeEnum;
import com.tanpu.common.exception.BizException;
......@@ -828,17 +827,17 @@ public class ThemeManager {
String content = sb.toString();
// 腾讯云接口最多支持5000文字校验
// 检查内容是否涉黄违法
boolean b;
String b = "";
while (content.length() > 5000) {
b = TencentcloudUtils.textModeration(content.substring(0, 5000));
if (!b) {
throw new BizException(ErrorCodeConstant.CONTENT_ILLEGAL);
if (StringUtils.isNotBlank(b)) {
throw new BizException(ErrorCodeConstant.CONTENT_ILLEGAL.getCode(),ErrorCodeConstant.CONTENT_ILLEGAL.getMsg()+":");
}
content = content.substring(5000);
}
b = TencentcloudUtils.textModeration(content);
if (!b) {
throw new BizException(ErrorCodeConstant.CONTENT_ILLEGAL);
if (StringUtils.isNotBlank(b)) {
throw new BizException(ErrorCodeConstant.CONTENT_ILLEGAL.getCode(),ErrorCodeConstant.CONTENT_ILLEGAL.getMsg()+":");
}
......
......@@ -79,7 +79,7 @@ public class TencentcloudUtils {
* @param text
* @return
*/
public static boolean textModeration(String text) {
public static String textModeration(String text) {
TextModerationRequest req = new TextModerationRequest();
req.setContent(Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8)));
TextModerationResponse res = null;
......@@ -87,16 +87,15 @@ public class TencentcloudUtils {
res = getTmsClient().TextModeration(req);
// suggestion Block 不通过
if (res.getSuggestion().equals("Block")) {
log.error("文本检验违规关键字:"+res.getKeywords());
return false;
return res.getKeywords().toString();
}
} catch (TencentCloudSDKException e) {
log.error("调用腾文本内容安全异常");
e.printStackTrace();
//调用失败时,不影响用户发布主题
return true;
return "";
}
return true;
return "";
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment