当前位置: 首页 > news >正文

SpringBoot集成腾讯云敏感词校验API流程

1.pom.xml中引入腾讯云jar配置信息

<dependency><groupId>com.tencentcloudapi</groupId><artifactId>tencentcloud-sdk-java</artifactId><version>4.0.11</version>
</dependency>

2.application.yaml中添加配置

tencent:tms:secret-id: AKDahCRQ9bolQovlKccMpBsecret-key: tWswkHXWEenfCpCI7fxxhAbiz-type: test_demo

3.项目中映射配置信息

@Data
@Component
@ConfigurationProperties(prefix = "tencent.tms")
public class TencentTmsProperties {private String secretId;private String secretkey;private String bizType;
}

4.封装敏感词校验工具类

@Slf4j
@Component
public class TencentTmsUtils {@Autowiredprivate TencentTmsProperties tencentTmsProperties;/*** 敏感词过滤** @param content* @return*/public Boolean getTmsResult(String content) {if (StringUtils.isEmpty(content) || StringUtils.isEmpty(content.trim())) {return Boolean.TRUE;}Credential cre = new Credential(tencentTmsProperties.getSecretId(), tencentTmsProperties.getSecretkey());TmsClient client = new TmsClient(cre, "ap-shanghai");TextModerationRequest request = new TextModerationRequest();request.setBizType(tencentTmsProperties.getBizType());request.setContent(Base64.encode(content));try {TextModerationResponse response = client.TextModeration(request);if (!ObjectUtils.isEmpty(response)) {return "Pass".equals(response.getSuggestion());}//response.getLabel();//返回值:Normal:正常,Porn:色情,Abuse:谩骂,Ad:广告,Custom//response.getSuggestion();//返回值:Block:建议屏蔽,Review :建议人工复审,Pass:建议通过log.info("敏感词类型:" + response.getLabel() + "处理结果:" + response.getSuggestion());} catch (TencentCloudSDKException e) {log.error("Sensitive word detection failed, because: ", e);}return Boolean.FALSE;}
}

5.业务代码中应用敏感词校验

 // 获取评论内容信息String content = req.getCommentContent();if (!tencentTmsUtils.getTmsResult(content)) {throw new BusinessException("评论内容包含敏感词语");}

http://www.lryc.cn/news/351429.html

相关文章:

  • android 避免混淆类名和方法名,但是方法内容需要被混淆
  • 通过ELRepo修改CentOS 7内核版本的详细步骤
  • C++开源库glog使用封装--自定义日志输出格式,设置日志保留时间
  • linux rc.local不生效
  • ROS2入门21讲__第07讲__节点:机器人的工作细胞
  • k8s node NotReady后会发生什么?
  • uni-starter创建App项目最全流程(日后还有其他功能会不断更新)
  • 动态IP和静态IP区别
  • 蓝牙(2):BR/EDR的连接过程;查询(发现)=》寻呼(连接)=》安全建立=》认证=》pair成功;类比WiFi连接过程。
  • 源码部署EFK
  • CSDN智能总结助手
  • setImmediate是在当前事件循环的所有周期的末尾执行,还是再当前事件循环的当前周期的下一个周期执行?
  • 建材行业工程设计资质动态核查不通过怎么办
  • 二叉数之插入操作
  • 【Python】全局变量与init的区别
  • JAVA学习-练习试用Java实现“位1的个数”
  • HTML静态网页成品作业(HTML+CSS)——魅族商城首页网页(1个页面)
  • Windows DNS 服务器配置转发器
  • 基于FPGA的VGA协议实现----条纹-文字-图片
  • hdfs中MapReduce中的shuffle,combine和partitioner(hadoop,Hdfs)
  • Linux应用入门(二)
  • 高仿果汁导航模板
  • 机器学习之一分类支持向量机(One-class SVM)
  • 签发免费https证书的方式
  • Autodl服务器中Faster-rcnn(jwyang)训练自己数据集(二)
  • 安卓手机文件误删或丢失?教你快速找回的方法!
  • C语言 | Leetcode C语言题解之第108题将有序数组转换为二叉搜索树
  • 关于在企业环境中中间人攻击(MITM)可行性研究的报告
  • GitHub Actions 自动部署 AWS Lambda
  • 【NOIP2013普及组复赛】题4:车站分级