php实名认证,身份证号,姓名加照片比对
阿里云接口
/**
* 检测人脸
*/
public function checkFace($idcard,$name,$img_base64)
{
$host = "https://zfah.market.alicloudapi.com";
$path = "/efficient/idfaceIdentity";
$method = "POST";
$appcode = C('FACE.AppCode');
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
//根据API的要求,定义相对应的Content-Type
array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8");
$bodys = "base64Str=".$img_base64."&liveChk=0&name=".$name."&number=".$idcard;
$url = $host . $path;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$" . $host, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
$result = curl_exec($curl);
// /**
// {
// "error_code": 0,
// "reason": "成功",
// "result": {
// "IdCardNo": "321302************",
// "Name": "纪*",
// "Validate_Result": 1,
// "Similarity": 89
// }
// }
// */
// /**
// {
// "error_code": 0,
// "reason": "成功",
// "result": {
// "IdCardNo": "321302************",
// "Name": "纪*",
// "Validate_Result": 4,
// "Similarity": 0
// }
// }
// */
$flag = false;
$reason = '';
$similarity = '';
$result = json_decode($result,true);
setlog($result,[],'face');
if ($result['error_code'] != 0) {
$reason = '验证失败';
} else {
$validate_result = $result['result']['Validate_Result'];
$similarity = $result['result']['Similarity'];
if ($validate_result == -1) {
$reason = '身份证和姓名不一致';
}
if ($validate_result == -2) {
$reason = '公安库中无此身份证记录';
$flag = true;
}
if ($validate_result == -3) {
$reason = '公安身份证库中没有此号码的照片';
$flag = true;
}
if ($validate_result == -4) {
$reason = '照片参数不合格';
}
if ($validate_result == -5) {
$reason = '照片相片体积过大';
}
if ($validate_result == -6) {
$reason = '请检查图片编码';
}
if ($validate_result == -7) {
$reason = '照片相片体积过小';
}
if ($validate_result == 1) {
if ($similarity == -1) {
$reason = '照片模糊,请选择清晰度较高的人脸图片';
} else {
$reason = '系统分析为同一人';
$flag = true;
}
}
if ($validate_result == 2) {
if ($similarity == -1) {
$reason = '照片模糊,请选择清晰度较高的人脸图片';
} else {
$reason = '系统分析可能为同一人';
$flag = true;
}
}
if ($validate_result == 3) {
$reason = '系统分析为不是同人';
}
if ($validate_result == 4) {
$reason = '没检测到人脸';
}
if ($validate_result == 5) {
$reason = '疑似非活体';
}
if ($validate_result == 6) {
$reason = '出现多张脸';
}
if ($validate_result == 6) {
$reason = '身份证和姓名一致,官方人脸比对失败';
}
}
$response = [
'result' => $flag,
'reason' => $reason,
'similarity' => $similarity
];
return $response;
}
按次数收费。
实名更安全,比如小区业主实名,人脸识别进出。