|
|
@@ -22,9 +22,10 @@ import java.util.HashMap; |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Component |
|
|
|
public class BaiduImageCheckUtil { |
|
|
|
public class BaiduCheckUtil { |
|
|
|
// 百度图片审核接口地址 |
|
|
|
private final static String photo_check_url = "https://aip.baidubce.com/rest/2.0/solution/v1/img_censor/v2/user_defined"; |
|
|
|
private final static String text_check_url = "https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined"; |
|
|
|
// 获取token |
|
|
|
private final static String auth_url = "https://aip.baidubce.com/oauth/2.0/token?"; |
|
|
|
// 百度API Key |
|
|
@@ -33,6 +34,32 @@ public class BaiduImageCheckUtil { |
|
|
|
// 百度Secret Key |
|
|
|
private final static String secretKey = "eGmeQkP3Opzph0GB4Y2voiOkGOlwbeWd"; |
|
|
|
|
|
|
|
|
|
|
|
public static ResultData textCheck(String text) { |
|
|
|
try { |
|
|
|
String param = "text=" + URLEncoder.encode(text, "utf-8");; |
|
|
|
String accessToken = getAuth(); |
|
|
|
String result = BaiDuHttpUtil.post(text_check_url, accessToken, param); |
|
|
|
log.info("图片检测"+result); |
|
|
|
JSONObject jsonObject = JSON.parseObject(result); |
|
|
|
//1:合规,2:不合规,3:疑似,4:审核失败 |
|
|
|
Integer type = jsonObject.getInteger("conclusionType"); |
|
|
|
if (type == 1) { |
|
|
|
return new ResultData(); |
|
|
|
} else if (type == 2 || type == 3) { |
|
|
|
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"文字内容不合规"); |
|
|
|
} else if (type == 4) { |
|
|
|
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"文字内容审核失败"); |
|
|
|
} else { |
|
|
|
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"文字内容不合规"); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"文字内容审核失败"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public static ResultData photoCheck(MultipartFile file) { |
|
|
|
try { |
|
|
|
byte[] fileBytes = file.getBytes(); |