微信小程序> 微信小程序之刷脸登录

微信小程序之刷脸登录

浏览量:631 时间: 来源:shenxiaomei11

在camera.wxml中编写代码如下:

camera device-position="{{value}}" flash="off" binderror="error" style="width: 100%; height: 300px;"/camera switch checked bindchange="switch1change" style="margin-top:5px;"/switchbutton type="primary" bindtap="takePhoto" style="margin-top:5px;"刷脸登录/buttonview预览/viewimage mode="widthFix" src="{{src}}"/image

在camera.js中编写代码如下:

// pages/cream/cream.jsPage({  /**   * 页面的初始数据   */  data: {    value: '',    src: ''  },  takePhoto() {    const ctx = wx.createCameraContext()    ctx.takePhoto({      quality: 'high',      success: (res) = {        this.setData({          src: res.tempImagePath        })        wx.showLoading({          title: '正在核验身份.....',        })        this.setData({ logindisabled: true });        wx.uploadFile({          url: '',          filePath: res.tempImagePath,          name: 'file',          success: (res) = {            wx.hideLoading();            this.setData({ logindisabled: false });            var data = res.data            console.log(data);            wx.showModal({              title: '提示',              content: data,              showCancel: false            })          }        })      }    })  },  error(e) {    console.log(e.detail)  },  switch1change: function (e) {    console.log(e)    if (e.detail.value) {      this.setData({ value: 'back' })    } else {      this.setData({ value: 'front' })    }  },})

这样在微信小程序中就编写成功了,然后在控制器中编写代码如下:

    //刷脸登录    public function login(){     $dir="./Uploads/temp/";      if (!file_exists($dir)) {        mkdir($dir,0777,true);      }      $upload = new ThinkUpload();// 实例化上传类      $upload-maxSize = 2048000 ;// 设置附件上传大小      $upload-exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型      $upload-rootPath = $dir; // 设置附件上传根目录      $upload-savePath = ''; // 设置附件上传(子)目录      $upload-autoSub=false;      //上传文件      $info = $upload-uploadOne($_FILES['file']);       if(!$info) {// 上传错误提示错误信息      return $this-ajaxReturn(array('error'=true,'msg'=$upload-getError()),JSON_UNESCAPED_UNICODE);    }else{        // $this-ajaxReturn('上传成功');      $file=$dir.$info['savepath'].$info['savename'];      $image=base64_encode(file_get_contents($file));      $client=$this-face();      $options['liveness_control']='NORMAL';      $options['max_user_num']='1';      $ret=$client-search($image,'BASE64',$this-face_group(),$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 (!empty($no)) {          $data=M('student')-field('no,name,sex')-where("no='{$no}'")-find();          if ($data) {            $data['score']=$score;              echo json_encode($data,JSON_UNESCAPED_UNICODE);              exit;          }else{            echo "本地数据库没有该学生,百度云库信息:个人信息:{$no},分值:{$score}";          }        }      }else{        echo "活体检测失败".json_encode($ret,JSON_UNESCAPED_UNICODE);      }    }    }
这样简单的微信小程序刷脸认证就完成了

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎