|
|
@@ -3,6 +3,7 @@ package com.iformall.utils; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.sm.AiBaiduCheckResult; |
|
|
|
import okhttp3.*; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
@@ -31,7 +32,7 @@ public class BaiduImageCheckUtil { |
|
|
|
|
|
|
|
public static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build(); |
|
|
|
|
|
|
|
public static AiBaiduCheckResult photoCheck(MultipartFile file) { |
|
|
|
public static ResultData photoCheck(MultipartFile file) { |
|
|
|
try { |
|
|
|
byte[] fileBytes = file.getBytes(); |
|
|
|
String imgStr = Base64Util.encode(fileBytes); |
|
|
@@ -46,27 +47,18 @@ public class BaiduImageCheckUtil { |
|
|
|
JSONObject jsonObject = JSON.parseObject(result); |
|
|
|
//1:合规,2:不合规,3:疑似,4:审核失败 |
|
|
|
Integer type = jsonObject.getInteger("conclusionType"); |
|
|
|
AiBaiduCheckResult checkResult = new AiBaiduCheckResult(); |
|
|
|
if (type == 1) { |
|
|
|
checkResult.setMsg("图片合规"); |
|
|
|
checkResult.setCode(200); |
|
|
|
return new ResultData(); |
|
|
|
} else if (type == 2 || type == 3) { |
|
|
|
checkResult.setMsg("图片不合规"); |
|
|
|
checkResult.setCode(ErrorCode.SYS_SERVER_ERROR.getCode()); |
|
|
|
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"图片不合规"); |
|
|
|
} else if (type == 4) { |
|
|
|
checkResult.setMsg("图片审核失败"); |
|
|
|
checkResult.setCode(ErrorCode.SYS_SERVER_ERROR.getCode()); |
|
|
|
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"图片审核失败"); |
|
|
|
} else { |
|
|
|
checkResult.setMsg("图片审核失败"); |
|
|
|
checkResult.setCode(ErrorCode.SYS_SERVER_ERROR.getCode()); |
|
|
|
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"图片审核失败"); |
|
|
|
} |
|
|
|
return checkResult; |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
AiBaiduCheckResult checkResult = new AiBaiduCheckResult(); |
|
|
|
checkResult.setMsg("图片审核失败"); |
|
|
|
checkResult.setCode(ErrorCode.SYS_SERVER_ERROR.getCode()); |
|
|
|
return checkResult; |
|
|
|
return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"图片审核失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|