您好,登錄后才能下訂單哦!
本篇文章為大家展示了怎么在微信小程序中實(shí)現(xiàn)刷臉登錄,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
public function login(){ $dir="./***";//自己定義的文件名 if(!file_exists($dir)){ mkdir($dir,0777,true); } $upload = new \Think\Upload();// 實(shí)例化上傳類(lèi) $upload->maxSize = 3145728 ;// 設(shè)置附件上傳大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 設(shè)置附件上傳類(lèi)型 $upload->rootPath = $dir; // 設(shè)置附件上傳根目錄 $upload->savepath=''; // 上傳單個(gè)文件 $info = $upload->uploadOne($_FILES['file']); if(!$info) {// 上傳錯(cuò)誤提示錯(cuò)誤信息 return $this->ajaxReturn(array('error'=>true,'msg'=>$upload->getError())); }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',$this->face_group(),$options); if($ret['error_code']==0){ $user = $ret['result']['user_list'][0]; $no = $user['user_id']; $score = $user['score']; if(!empty($no)){ $data = M('student')->field('no,name,sex')->where("no='{$no}'")->find(); if($data){ //查到此學(xué)號(hào) $data['score'] = $score; echo json_encode($data,JSON_UNESCAPED_UNICODE); }else{ //本地庫(kù)不存在此學(xué)號(hào) echo "本地?cái)?shù)據(jù)庫(kù)沒(méi)有該學(xué)生,百度云庫(kù)信息:個(gè)人信息:{$no},分值:{$score}"; } } }else{ echo "活體檢測(cè)失敗,".json_encode($ret,JSON_UNESCAPED_UNICODE); } } }
里面的search方法是sdk的方法
public function search($image, $imageType, $groupIdList, $options=array()){ $data = array(); $data['image'] = $image; $data['image_type'] = $imageType; $data['group_id_list'] = $groupIdList; $data = array_merge($data, $options); return $this->request($this->searchUrl, json_encode($data), array( 'Content-Type' => 'application/json', )); }
上述內(nèi)容就是怎么在微信小程序中實(shí)現(xiàn)刷臉登錄,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。