|
@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.starters.face.verify.model.baidu;
|
|
|
|
|
|
import cn.com.qmth.examcloud.starters.face.verify.FaceVerifyProperties;
|
|
import cn.com.qmth.examcloud.starters.face.verify.FaceVerifyProperties;
|
|
import cn.com.qmth.examcloud.starters.face.verify.common.Constants;
|
|
import cn.com.qmth.examcloud.starters.face.verify.common.Constants;
|
|
|
|
+import cn.com.qmth.examcloud.starters.face.verify.common.FaceVerifyException;
|
|
import cn.com.qmth.examcloud.starters.face.verify.common.HttpClientBuilder;
|
|
import cn.com.qmth.examcloud.starters.face.verify.common.HttpClientBuilder;
|
|
import cn.com.qmth.examcloud.starters.face.verify.common.JsonHelper;
|
|
import cn.com.qmth.examcloud.starters.face.verify.common.JsonHelper;
|
|
import cn.com.qmth.examcloud.starters.face.verify.model.FaceResult;
|
|
import cn.com.qmth.examcloud.starters.face.verify.model.FaceResult;
|
|
@@ -19,11 +20,11 @@ public class BaiduApiHelper {
|
|
|
|
|
|
public static BaiduSession getAccessToken(String apiKey, String apiSecret) {
|
|
public static BaiduSession getAccessToken(String apiKey, String apiSecret) {
|
|
if (StringUtils.isBlank(apiKey)) {
|
|
if (StringUtils.isBlank(apiKey)) {
|
|
- throw new IllegalArgumentException("Baidu apiKey must be not empty.");
|
|
|
|
|
|
+ throw new IllegalArgumentException("[BAIDU] apiKey must be not empty.");
|
|
}
|
|
}
|
|
|
|
|
|
if (StringUtils.isBlank(apiSecret)) {
|
|
if (StringUtils.isBlank(apiSecret)) {
|
|
- throw new IllegalArgumentException("Baidu apiSecret must be not empty.");
|
|
|
|
|
|
+ throw new IllegalArgumentException("[BAIDU] apiSecret must be not empty.");
|
|
}
|
|
}
|
|
|
|
|
|
String requestUrl = String.format("%s?grant_type=client_credentials&client_id=%s&client_secret=%s", Constants.BAIDU_TOKEN_URL, apiKey, apiSecret);
|
|
String requestUrl = String.format("%s?grant_type=client_credentials&client_id=%s&client_secret=%s", Constants.BAIDU_TOKEN_URL, apiKey, apiSecret);
|
|
@@ -40,17 +41,17 @@ public class BaiduApiHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- log.warn("[baidu] url:{} response:{} body:{}", requestUrl, response.code(), bodyStr);
|
|
|
|
- throw new RuntimeException("获取 Baidu AccessToken 失败!");
|
|
|
|
|
|
+ log.warn("[BAIDU] url:{} response:{} body:{}", requestUrl, response.code(), bodyStr);
|
|
|
|
+ throw new FaceVerifyException("[BAIDU] 获取AccessToken失败!");
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
- throw new RuntimeException("获取 Baidu AccessToken 异常!");
|
|
|
|
|
|
+ throw new FaceVerifyException("[BAIDU] 获取AccessToken异常!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static FaceResult faceVerify(FaceVerifyProperties properties, String jsonParams) {
|
|
public static FaceResult faceVerify(FaceVerifyProperties properties, String jsonParams) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
- throw new IllegalArgumentException("Baidu api params must be not empty.");
|
|
|
|
|
|
+ throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
|
|
}
|
|
}
|
|
|
|
|
|
BaiduSession session = BaiduApiHelper.getAccessToken(properties.getBaiduKey(), properties.getBaiduSecret());
|
|
BaiduSession session = BaiduApiHelper.getAccessToken(properties.getBaiduKey(), properties.getBaiduSecret());
|
|
@@ -65,7 +66,7 @@ public class BaiduApiHelper {
|
|
|
|
|
|
public static FaceResult faceVerifyUseLocalApi(FaceVerifyProperties properties, String jsonParams) {
|
|
public static FaceResult faceVerifyUseLocalApi(FaceVerifyProperties properties, String jsonParams) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
- throw new IllegalArgumentException("Baidu api params must be not empty.");
|
|
|
|
|
|
+ throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
|
|
}
|
|
}
|
|
|
|
|
|
String requestUrl = String.format("%s?appid=%s", properties.getBaiduLocalUrlPrefix() + Constants.BAIDU_FACE_VERIFY_LOCAL_URL, properties.getBaiduLocalAppId());
|
|
String requestUrl = String.format("%s?appid=%s", properties.getBaiduLocalUrlPrefix() + Constants.BAIDU_FACE_VERIFY_LOCAL_URL, properties.getBaiduLocalAppId());
|
|
@@ -77,7 +78,7 @@ public class BaiduApiHelper {
|
|
|
|
|
|
public static FaceResult faceDetect(FaceVerifyProperties properties, String jsonParams) {
|
|
public static FaceResult faceDetect(FaceVerifyProperties properties, String jsonParams) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
- throw new IllegalArgumentException("Baidu api params must be not empty.");
|
|
|
|
|
|
+ throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
|
|
}
|
|
}
|
|
|
|
|
|
BaiduSession session = BaiduApiHelper.getAccessToken(properties.getBaiduKey(), properties.getBaiduSecret());
|
|
BaiduSession session = BaiduApiHelper.getAccessToken(properties.getBaiduKey(), properties.getBaiduSecret());
|
|
@@ -92,7 +93,7 @@ public class BaiduApiHelper {
|
|
|
|
|
|
public static FaceResult faceDetectUseLocalApi(FaceVerifyProperties properties, String jsonParams) {
|
|
public static FaceResult faceDetectUseLocalApi(FaceVerifyProperties properties, String jsonParams) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
- throw new IllegalArgumentException("Baidu api params must be not empty.");
|
|
|
|
|
|
+ throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
|
|
}
|
|
}
|
|
|
|
|
|
String requestUrl = String.format("%s?appid=%s", properties.getBaiduLocalUrlPrefix() + Constants.BAIDU_FACE_DETECT_LOCAL_URL, properties.getBaiduLocalAppId());
|
|
String requestUrl = String.format("%s?appid=%s", properties.getBaiduLocalUrlPrefix() + Constants.BAIDU_FACE_DETECT_LOCAL_URL, properties.getBaiduLocalAppId());
|
|
@@ -104,7 +105,7 @@ public class BaiduApiHelper {
|
|
|
|
|
|
public static FaceResult faceCompare(FaceVerifyProperties properties, String jsonParams, Double expectFaceCompareScore) {
|
|
public static FaceResult faceCompare(FaceVerifyProperties properties, String jsonParams, Double expectFaceCompareScore) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
- throw new IllegalArgumentException("Baidu api params must be not empty.");
|
|
|
|
|
|
+ throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
|
|
}
|
|
}
|
|
|
|
|
|
BaiduSession session = BaiduApiHelper.getAccessToken(properties.getBaiduKey(), properties.getBaiduSecret());
|
|
BaiduSession session = BaiduApiHelper.getAccessToken(properties.getBaiduKey(), properties.getBaiduSecret());
|
|
@@ -119,7 +120,7 @@ public class BaiduApiHelper {
|
|
|
|
|
|
public static FaceResult faceCompareUseLocalApi(FaceVerifyProperties properties, String jsonParams, Double expectFaceCompareScore) {
|
|
public static FaceResult faceCompareUseLocalApi(FaceVerifyProperties properties, String jsonParams, Double expectFaceCompareScore) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
if (StringUtils.isBlank(jsonParams)) {
|
|
- throw new IllegalArgumentException("Baidu api params must be not empty.");
|
|
|
|
|
|
+ throw new IllegalArgumentException("[BAIDU] api params must be not empty.");
|
|
}
|
|
}
|
|
|
|
|
|
String requestUrl = String.format("%s?appid=%s", properties.getBaiduLocalUrlPrefix() + Constants.BAIDU_FACE_COMPARE_LOCAL_URL, properties.getBaiduLocalAppId());
|
|
String requestUrl = String.format("%s?appid=%s", properties.getBaiduLocalUrlPrefix() + Constants.BAIDU_FACE_COMPARE_LOCAL_URL, properties.getBaiduLocalAppId());
|
|
@@ -226,12 +227,12 @@ public class BaiduApiHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- log.warn("[baidu] url:{} response:{} cost:{}ms body:{}", requestUrl, response.code(), cost, bodyStr);
|
|
|
|
|
|
+ log.warn("[BAIDU] url:{} response:{} cost:{}ms body:{}", requestUrl, response.code(), cost, bodyStr);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error(e.getMessage(), e);
|
|
log.error(e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
|
|
- throw new RuntimeException("[baidu] 接口调用异常!");
|
|
|
|
|
|
+ throw new FaceVerifyException("[BAIDU] 人脸接口调用异常!");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|