日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

教你用PHP實現(xiàn)微信小程序人臉識別刷臉登錄功能,首先我們先確認(rèn)我們的百度云人臉庫里已經(jīng)上傳了我們的個人信息照片;

然后我們在后臺寫刷臉登陸的接口login我們要把拍照獲取的照片存儲到服務(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è)置附件上傳根目錄 
    // 上傳單個文件
    $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']; 
            } 
        } 
    } 
}

然后進行前臺設(shè)計;

<camera device-position="{{device?'back':'front'}}" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera> 
<view class="weui-cells__title" >開關(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>

我們還可以控制相機的前后鏡頭;

devicePosition() { 
    this.setData({ 
        device: !this.data.device, 
    }) 
    console.log("當(dāng)前相機攝像頭為:", 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: '', //僅為示例,非真實的接口地址 
                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: "確定"
                    }) 
                } 
            }) 
        } 
    }) 
},

刷臉登錄就成功了。



分享到:
標(biāo)簽:PHP實現(xiàn) 微信小程序 人臉識別 刷臉登錄
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運動步數(shù)有氧達人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定