PHP实现微信小措施人脸辨认刷脸登录成果
发布时间:2021-05-24 19:43:38 所属栏目:编程 来源:网络整理
导读:起首我们先确认我们的百度云人脸库里已经上传了我们的小我私人书息照片 然后我们在靠山写刷脸登岸的接口login我们要把照相获取的照片存储随处事器 maxSize = 2048000 ;// 配置附件上传巨细 $upload->exts = array('jpg','gif','png','jpeg');// 配置附件上传类
起首我们先确认我们的百度云人脸库里已经上传了我们的小我私人书息照片 然后我们在靠山写刷脸登岸的接口login我们要把照相获取的照片存储随处事器 maxSize = 2048000 ;// 配置附件上传巨细
$upload->exts = array('jpg','gif','png','jpeg');// 配置附件上传范例
$upload->savepath = '';
$upload->autoSub = false;
$upload->rootPath = $dir; // 配置附件上传根目次
// 上传单个文件
$info = $upload->uploadOne($_FILES['file']);
if(!$info) {// 上传错误提醒错误信息
echo json_encode(array('error'=>true,'msg'=>$upload->getError()),JSON_UNESCAPED_UNICODE);
}else{// 上传乐成 获取上传文件信息
$file = $dir . $info['savepath'].$info['savename'];
$image = base64_encode(file_get_contents($file));
$client = $this->init_face();
$options['liveness_control'] = 'NORMAL';
$options['max_user_num'] = '1';
$ret = $client->search($image,'BASE64','student',$options);
// echo json_encode($ret,JSON_UNESCAPED_UNICODE);
// exit;
if($ret['error_code']==0){
$user = $ret['result']['user_list'][0];
$no = $user['user_id'];
$score = $user['score'];
if($score>=95){
$data = M('student')->where("no = '{$no}'")->find();
$data['score'] = $score;
// $data['name'] = json_decode($data['name'],true);
// $data['sex'] = json_decode($data['sex'],true);
echo '辨认乐成' . json_encode($data,JSON_UNESCAPED_UNICODE);
}else{
echo '辨认失败' . $data['score'];
}
}
}
}
然后举办前台计划 |