public FaceVO faceCompare(String imageReflUrl, String imageUrl, String userId) {
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
paramMap.add("api_key", faceConfig.getApiKey());
paramMap.add("api_secret", faceConfig.getApiSecret());
paramMap.add("comparison_type", 0);
paramMap.add("face_image_type", "raw_image");
paramMap.add("uuid", userId);
paramMap.add("fail_when_multiple_faces", 0);
paramMap.add("face_quality_threshold", 0);
paramMap.add("image_ref1", new FileSystemResource(imageReflUrl));
paramMap.add("image", new FileSystemResource(imageUrl));
String result;
try {
result = restTemplate.postForEntity(faceConfig.getApiUrl(), new HttpEntity<>(paramMap, buildHttpHeaders()), String.class).getBody();
} catch (HttpClientErrorException e) {
result = e.getResponseBodyAsString();
}
return JSONObject.parseObject(result, FaceVO.class);
}
/**
* 设置头信息
*
* @return 请求头
*/
private HttpHeaders buildHttpHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("multipart/form-data"));
return headers;
}