在实际项目中,我们可以借助句无忧等第三方服务商提供的违禁词检测服务来实现。
接入API地址:https://www.check51.com/interface/detect.html
API接口
接口地址:https://api.check51.com/api/word/detect-text
请求方式:POST
请求格式:form-data或x-www-form-urlencoded
返回格式:JSON
请求参数说明:
参数名称 | 类型 | 必填 | 示例 | 说明 |
---|---|---|---|---|
appid | string | 是 | 100001 | 应用编号,对应当前账号的句无忧用户编号 |
secretKey | string | 是 | xxxxxxxxxxxxx | 密钥 |
content | string | 是 | \u4eca\u5929\u662f\u6700\u7f8e\u597d\u7684\u4e00\u5929 | 检测内容,最大字符长度为5万,超过5万自动截断。(字符串内容请进行UNICODE中文编码,当前示例原文内容为:今天是最美好的一天) |
isCommonWord | bool | 否 | false | 是否使用句无忧通用词库,默认true |
industryId | int | 否 | 2 | 选择的行业ID,仅支持一个行业输入(默认:0) |
platformId | int | 否 | 8 | 选择的行业ID,仅支持一个平台输入(默认:0) |
isDefined | bool | 否 | true | 是否使用当前应用自定义词库,包括个人词库与黑名单词库(默认:false) |
isDefinedTeam | bool | 否 | true | 是否使用当前应用团队词库(默认:false) |
响应参数说明
参数名称 | 类型 | 说明 |
---|---|---|
code | string | 返回状态码(0000表示检测成功,否则检测异常,原因请参照错误码列表) |
msg | string | 返回状态内容 |
data | object | 返回检测结果 |
+status | int | 检测结果状态(1-通过(无违禁词),2-不通过(存在违禁词)) |
+resContent | string | 文字检测结果(带颜色html标签,请自行增加样式, 禁用词:"jwy-topRisk",敏感词:"jwy-lowRisk") |
+topRiskStr | string | 禁用词汇总(第一、top1) |
+lowRiskStr | string | 敏感词汇总(领先、广告) |
+riskList | Array | 违禁词列表详情 |
++title | string | 违禁词名称 |
++type | string | 风险等级-禁用词/敏感词 |
++sourse | string | 所属行业/平台 |
++reason | string | 违禁原因 |
+contentLength | int | 当前消耗文字字数 |
JSON返回示例
{
"code": "0000",
"msg": "检测成功",
"data": {
"status":2,
"resContent":"在这个信息爆炸的时代,广告已经成为了企业推广产品或服务不可或缺的一种方式。然而,随着广告法规的日益严格,如何在确保广告内容合规的同时",
"topRiskStr":"爆炸、解决",
"lowRiskStr":"推广、消费、广告",
"riskList": [
{
"title": "爆炸",
"type": "禁用词",
"sourse": "通用词库",
"reason": "涉嫌非法危险爆炸物"
},
{
"title": "推广",
"type": "敏感词",
"sourse": "抖音",
"reason": "涉嫌不当用语"
},
{
"title": "广告",
"type": "敏感词",
"sourse": "美妆护理",
"reason": "涉嫌不当用语"
}
],
"contentLength":50
}
}