首先我們先確認(rèn)我們的百度云人臉庫(kù)里已經(jīng)上傳了我們的個(gè)人信息照片;

然后我們?cè)诤笈_(tái)寫刷臉登陸的接口login我們要把拍照獲取的照片存儲(chǔ)到服務(wù)器;
public function login(){
// 上傳文件路徑
$dir = "./Uploads/temp/";
if(!file_exists($dir)){
mkdir($dir,0777,true);
}
$upload = new \Think\Upload();
$upload->maxSize = 2048000 ;// 設(shè)置附件上傳大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 設(shè)置附件上傳類型
$upload->savepath = '';
$upload->autoSub = false;
$upload->rootPath = $dir; // 設(shè)置附件上傳根目錄
// 上傳單個(gè)文件
$info = $upload->uploadOne($_FILES['file']);
if(!$info) {// 上傳錯(cuò)誤提示錯(cuò)誤信息
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 '識(shí)別成功' . json_encode($data,JSON_UNESCAPED_UNICODE);
}else{
echo '識(shí)別失敗' . $data['score'];
}
}
}
}然后進(jìn)行前臺(tái)設(shè)計(jì);
<camera device-position="{{device?'back':'front'}}" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>
<view class="weui-cells__title" >開(kāi)關(guān)</view>
<view class="weui-cells weui-cells_after-title">
<view class="weui-cell weui-cell_switch">
<view class="weui-cell__bd">切換攝像頭</view>
<view class="weui-cell__ft" >
<switch bindtap="devicePosition" />
</view>
</view>
</view>
<button type="primary" bindtap="takePhoto">刷臉登錄</button>我們還可以控制相機(jī)的前后鏡頭;
devicePosition() {
this.setData({
device: !this.data.device,
})
console.log("當(dāng)前相機(jī)攝像頭為:", this.data.device ? "后置" : "前置");
camera() {
let { ctx, type, startRecord } = this.data; },
data: {
src: null,
},在js里面調(diào)用接口;
takePhoto() {
const ctx = wx.createCameraContext()
ctx.takePhoto({
quality: 'high',
success: (res) => {
this.setData({
src: res.tempImagePath
})
console.log(res)
wx.uploadFile({
url: '', //僅為示例,非真實(shí)的接口地址
filePath: this.data.src,
name: 'file',
formData: {
},
success: function (res) {
// var data = res.data
// var json = JSON.parse(data)
console.log(res)
wx.showModal({
title: "提示",
content: res.data,
showCancel: false,
confirmText: "確定"
})
}
})
}
})
},刷臉登錄就成功了。
以上就是教你用PHP實(shí)現(xiàn)微信小程序人臉識(shí)別刷臉登錄功能的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司其它相關(guān)文章!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
分享名稱:PHP制作微信小程序人臉識(shí)別功能-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://chinadenli.net/article40/cosdho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、做網(wǎng)站、標(biāo)簽優(yōu)化、搜索引擎優(yōu)化、用戶體驗(yàn)、營(yíng)銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容