wangliang 9 months ago
parent
commit
b03ac64338

+ 7 - 2
sop-business/src/main/java/com/qmth/sop/business/sync/FaceApiUtils.java

@@ -18,6 +18,7 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
+import java.util.Objects;
 
 
 /**
 /**
  * @Description: 百度人脸识别工具类
  * @Description: 百度人脸识别工具类
@@ -26,6 +27,7 @@ import java.util.List;
  */
  */
 @Component
 @Component
 public class FaceApiUtils {
 public class FaceApiUtils {
+
     @Resource
     @Resource
     private SysConfigService sysConfigService;
     private SysConfigService sysConfigService;
 
 
@@ -44,8 +46,8 @@ public class FaceApiUtils {
      * @throws IOException 异常
      * @throws IOException 异常
      */
      */
     public BigDecimal faceMatch(File f1, File f2) throws IOException {
     public BigDecimal faceMatch(File f1, File f2) throws IOException {
-//        String appId = sysConfigService.findByConfigKey(SystemConstant.FACE_VERIFY_BAIDU_LOCAL_APP_ID).getConfigValue();
-//        String uri = sysConfigService.findByConfigKey(SystemConstant.FACE_VERIFY_BAIDU_LOCAL_URL_PREFIX).getConfigValue();
+        //        String appId = sysConfigService.findByConfigKey(SystemConstant.FACE_VERIFY_BAIDU_LOCAL_APP_ID).getConfigValue();
+        //        String uri = sysConfigService.findByConfigKey(SystemConstant.FACE_VERIFY_BAIDU_LOCAL_URL_PREFIX).getConfigValue();
         String url = sysConfigService.findByConfigKey(SystemConstant.BAIDU_FACE_COMPARE_URL).getConfigValue();
         String url = sysConfigService.findByConfigKey(SystemConstant.BAIDU_FACE_COMPARE_URL).getConfigValue();
 
 
         String postUrl = faceVerifyBaiduLocalUrlPrefix + url + "?appId=" + faceVerifyBaiduLocalAppId;
         String postUrl = faceVerifyBaiduLocalUrlPrefix + url + "?appId=" + faceVerifyBaiduLocalAppId;
@@ -62,6 +64,9 @@ public class FaceApiUtils {
         String json = JSONArray.toJSONString(faceMatchParamList);
         String json = JSONArray.toJSONString(faceMatchParamList);
 
 
         String result = HttpUtil.postJson(postUrl, json, null, null, false);
         String result = HttpUtil.postJson(postUrl, json, null, null, false);
+        if (Objects.isNull(result) || Objects.equals(result.trim(), "")) {
+            throw ExceptionResultEnum.ERROR.exception("人脸识别服务不可用!");
+        }
         JSONObject jsonObject = JSONObject.parseObject(result);
         JSONObject jsonObject = JSONObject.parseObject(result);
         String errorCode = jsonObject.getString("error_code");
         String errorCode = jsonObject.getString("error_code");
         String errorMsg = jsonObject.getString("error_msg");
         String errorMsg = jsonObject.getString("error_msg");