百度文本内容审核
开通内容审核服务
https://cloud.baidu.com/solution/censoring
选择 试用,“立即领取”
创建应用
开发指南
https://ai.baidu.com/ai-doc/ANTIPORN/ik3h6xdze
导入jar
<!-- 百度sdk -->
<dependency>
<groupId>com.baidu.aip</groupId>
<artifactId>java-sdk</artifactId>
<version>4.16.6</version>
</dependency>
测试代码:
package com.example.contentcheck.utils;
import com.baidu.aip.contentcensor.AipContentCensor;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* 内容审核工具类
*/
public class BaiduTextCheckUtils {
public static final String APP_ID = "39902475";
public static final String API_KEY = "oVPhsxgDXXGwQQEQnCGlut0B";
public static final String SECRET_KEY = "a4q5fwBAv0wUoyw5qKMAKz0X39al3MdK";
private static AipContentCensor client;
static {
client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);
// 可选:设置网络连接参数
client.setConnectionTimeoutInMillis(2000);
client.setSocketTimeoutInMillis(60000);
}
/**
* 内容审核
*
* @param text
*/
public static void textCheck(String text) {
JSONObject response = client.textCensorUserDefined(text);
System.out.println(response.toString());
// 是否合规的状态,1.合规,2.不合规,3.疑似,4.审核失败
int conclusionType = response.getInt("conclusionType");
System.out.println(conclusionType);
// 获取不合规的数据
if (conclusionType != 1) {
JSONArray data = response.getJSONArray("data");
for (int i = 0; i < data.length(); i++) {
JSONObject jsonObject = data.getJSONObject(i);
System.out.println(jsonObject.getString("msg"));
}
}
}
public static void main(String[] args) {
BaiduTextCheckUtils.textCheck("欢迎使用产品,他妈的");
}
}
id main(String[] args) {
BaiduTextCheckUtils.textCheck(“欢迎使用产品,他妈的”);
}
}