百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>网页制作> 教你用PHP实现微信小程序人脸辨认刷脸登录功能
分享文章到:

教你用PHP实现微信小程序人脸辨认刷脸登录功能

发布时间:09/01 来源:未知 浏览: 关键词:
教你用PHP实现微信小程序人脸识别刷脸登录功效

第一我们先确定我们的baidu云人脸库里已经上传了我们的个人信息相片;

然后我们在后台写刷脸登陆的接口login我们要把拍照猎取的相片储备到效劳器;

public function login(){ 
   // 上传文件途径 
   $dir = "./Uploads/temp/"; 
   if(!file_exists($dir)){ 
    mkdir($dir,0777,true); 
   } 
   $upload = new \Think\Upload(); 
   $upload->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']; 
     } 
    } 
   } 
  }

然后停止前台设计;

<camera device-position="{{device?'back':'front'}}" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera> 
    <view class="weui-cells__title" >开关</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("当前相机摄像头为:", this.data.device ? "后置" : "前置"); 
camera() { 
 let { ctx, type, startRecord } = this.data; }, 
data: { 
 src: null, 
},

在js里面调取接口;

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: "肯定"
       }) 
      } 
     }) 
    } 
   }) 
  },

刷脸登录就成功了。

以上就是教你用PHP实现微信小程序人脸识别刷脸登录功效的具体内容,更多请关注百分百源码网其它相关文章!

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有154人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板