package org.fh.util;
import java.util.*;
import net.sf.json.jsonobject;
/**
* 说明:人脸对比
* 作者:f-h
* from:www.fhadmin.cn
*/
public class facematch {
public static string facematch(list<object> list) {
// 请求url
string url = "https://aip.baidubce.com/rest/2.0/face/v3/match";
try {
string param = gsonutils.tojson(list);
// 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
string accesstoken = authservice.getauth();
string result = httputil.post(url, accesstoken, "application/json", param);
return result;
} catch (exception e) {
e.printstacktrace();
}
return null;
}
//photodata1 图片1的 base64码
//photodata2 图片2的 base64码 返回的score大于80 说明是同一个人
public static string getscore(string photodata1,string photodata2) {
list<object> list = new arraylist<object>();
map<string,string> map1 = new hashmap<string,string>();
map1.put("image", photodata1);
map1.put("image_type", "base64");
map1.put("face_type", "live");
map1.put("quality_control", "none");
map1.put("liveness_control", "none");
list.add(map1);
map<string,string> map2 = new hashmap<string,string>();
map2.put("image", photodata2);
map2.put("image_type", "base64");
map2.put("face_type", "live");
map2.put("quality_control", "none");
map2.put("liveness_control", "none");
list.add(map2);
string resultstr = facematch.facematch(list);
jsonobject jsonmsg = jsonobject.fromobject(resultstr);
string error_msg = jsonmsg.getstring("error_msg");
string score = "0";
if("success".equals(error_msg)) {
string result = jsonmsg.getstring("result");
jsonobject jsonresult = jsonobject.fromobject(result);
score = jsonresult.getstring("score");
}
return score;
}
}