|
@@ -25,6 +25,7 @@ import cn.com.qmth.examcloud.commons.helpers.JsonHttpResponseHolder;
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.UrlUtil;
|
|
import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -167,7 +168,7 @@ public class BaiduClient {
|
|
Map<String, String> params = Maps.newHashMap();
|
|
Map<String, String> params = Maps.newHashMap();
|
|
|
|
|
|
params.put("image", imageUrl);
|
|
params.put("image", imageUrl);
|
|
- params.put("image_type", "imageUrl");
|
|
|
|
|
|
+ params.put("image_type", "URL");
|
|
|
|
|
|
httpPost.setEntity(new StringEntity(JsonUtil.toJson(params), "UTF-8"));
|
|
httpPost.setEntity(new StringEntity(JsonUtil.toJson(params), "UTF-8"));
|
|
|
|
|
|
@@ -183,12 +184,12 @@ public class BaiduClient {
|
|
responseHolder = new JsonHttpResponseHolder(statusCode, obj);
|
|
responseHolder = new JsonHttpResponseHolder(statusCode, obj);
|
|
|
|
|
|
if (HttpStatus.SC_OK != responseHolder.getStatusCode()) {
|
|
if (HttpStatus.SC_OK != responseHolder.getStatusCode()) {
|
|
- log.error("[Face++]. compare. statusCode=" + statusCode + "; responseEntity="
|
|
|
|
- + entityStr);
|
|
|
|
|
|
+ log.error("[Baidu AI]. verifyFaceLiveness; statusCode=" + statusCode
|
|
|
|
+ + "; responseEntity=" + entityStr);
|
|
} else {
|
|
} else {
|
|
if (log.isDebugEnabled()) {
|
|
if (log.isDebugEnabled()) {
|
|
- log.debug("[Face++]. compare. statusCode=" + statusCode + "; responseEntity="
|
|
|
|
- + entityStr);
|
|
|
|
|
|
+ log.debug("[Baidu AI]. verifyFaceLiveness; statusCode=" + statusCode
|
|
|
|
+ + "; responseEntity=" + entityStr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -199,11 +200,65 @@ public class BaiduClient {
|
|
}
|
|
}
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
if (log.isDebugEnabled()) {
|
|
- log.debug("[Baidu AI]. compare. imageUrl=" + imageUrl + "; cost "
|
|
|
|
|
|
+ log.debug("[Baidu AI]. verifyFaceLiveness; imageUrl=" + imageUrl + "; cost "
|
|
+ (System.currentTimeMillis() - s) + " ms.");
|
|
+ (System.currentTimeMillis() - s) + " ms.");
|
|
}
|
|
}
|
|
|
|
|
|
return responseHolder;
|
|
return responseHolder;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 活体检测
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @param imageUrl
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public JsonHttpResponseHolder verifyFaceLivenessUseBase64(String base64) {
|
|
|
|
+
|
|
|
|
+ base64 = UrlUtil.encode(base64);
|
|
|
|
+
|
|
|
|
+ String accessToken = getAccessToken();
|
|
|
|
+ String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceverify?access_token="
|
|
|
|
+ + accessToken;
|
|
|
|
+
|
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
|
+ httpPost.setConfig(BaiduClient.requestConfig);
|
|
|
|
+
|
|
|
|
+ Map<String, String> params = Maps.newHashMap();
|
|
|
|
+
|
|
|
|
+ params.put("image", base64);
|
|
|
|
+ params.put("image_type", "BASE64");
|
|
|
|
+
|
|
|
|
+ httpPost.setEntity(new StringEntity(JsonUtil.toJson(params), "UTF-8"));
|
|
|
|
+
|
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
|
+ JsonHttpResponseHolder responseHolder = null;
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ response = httpclient.execute(httpPost);
|
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
|
+ String entityStr = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
|
|
+ JSONObject obj = JSON.parseObject(entityStr);
|
|
|
|
+ responseHolder = new JsonHttpResponseHolder(statusCode, obj);
|
|
|
|
+
|
|
|
|
+ if (HttpStatus.SC_OK != responseHolder.getStatusCode()) {
|
|
|
|
+ log.error("[Baidu AI]. verifyFaceLivenessUseBase64; statusCode=" + statusCode
|
|
|
|
+ + "; responseEntity=" + entityStr);
|
|
|
|
+ } else {
|
|
|
|
+ if (log.isDebugEnabled()) {
|
|
|
|
+ log.debug("[Baidu AI]. verifyFaceLivenessUseBase64; statusCode=" + statusCode
|
|
|
|
+ + "; responseEntity=" + entityStr);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new ExamCloudRuntimeException(e);
|
|
|
|
+ } finally {
|
|
|
|
+ IOUtils.closeQuietly(response);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return responseHolder;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|