微信小程序> 微信小程序之生物识别

微信小程序之生物识别

浏览量:2095 时间: 来源:极乐叔

今天闲来没事,了解下生物识别。

生物识别有三个接口

1、wx.checkIsSupportSoterAuthentication 用来获取本机支持的生物识别方式(人脸、指纹、声纹)2、wx.startSoterAuthentication 进行生物认证3、wx.checkIsSoterEnrolledInDevice 检测是否录入生物信息

有兴趣的童鞋可以拿代码去玩玩试试看

wxml代码

 bindtap="checkIsFingerPrint"检测是否可以指纹识别 bindtap="checkIsFacial"检测是否可以人脸识别 bindtap="HaveFingerPrint"该设备是否录入指纹 bindtap="FingerPrint"识别指纹

js代码

Page({  /**   * 页面的初始数据   */  data: {    isfingerPrint : false,    //可否使用指纹识别  默认false    isfacial: false,          //可否使用人脸识别  默认false  },  /**   * 生命周期函数--监听页面加载   */  onLoad: function (options) {    var that = this    //查看支持的生物认证   比如ios的指纹识别   安卓部分机器是不能用指纹识别的    wx.checkIsSupportSoterAuthentication({      success(res) {        for (var i in res.supportMode){          if (res.supportMode[i] == 'fingerPrint'){            console.log("支持指纹识别", res.supportMode[i]);            that.setData({              isfingerPrint : true            })          } else if (res.supportMode[i] == 'facial'){            console.log("支持人脸识别", res.supportMode[i]);          }        }      }    })  },  //是否可以指纹识别  checkIsFingerPrint:function(){    var boole = this.data.isfingerPrint    var txt = "不可以使用指纹识别"    if (boole) {      txt = "可以使用指纹识别"    }    show("提示",txt,false);  },  //是否可以人脸识别  checkIsFacial: function () {    var boole = this.data.isfacial    var txt = "不可以使用人脸识别"    if (boole){      txt = "可以使用人脸识别"    }    function SUCC() {      console.log("用户点击确定")    }    function FAIL() {      console.log("用户点击取消")    }    show("提示", txt, true,SUCC,FAIL);  },  //进行指纹识别  FingerPrint: function(){    wx.startSoterAuthentication({      requestAuthModes: ['fingerPrint'],      challenge: '123456',      authContent: '请用指纹',      success(res) {        console.log("识别成功",res)        show("提示", "识别成功", false);      },      fail(res){        console.log("识别失败",res)        show("提示", "识别失败", false);      }    })  },  //是否有指纹  HaveFingerPrint:function(){    wx.checkIsSoterEnrolledInDevice({      checkAuthMode: 'fingerPrint',      success(res) {        if (res.isEnrolled == 1){          show("提示", "有指纹", false);        } else if (res.isEnrolled == 0){          show("提示", "无指纹", false);        }      },      fail(res){        show("提示", "异常", fail);      }    })  }})/** * 显示提示信息 * tit 提示的标题 * msg 提示的内容 * q   是否有取消按钮(布尔值) * succ 用户点击确定的回调(非必须) * fail 用户点击取消的回调(非必须) * */function show(tit,msg,q,succ,fail){  wx.showModal({    title: tit,    content: msg,    showCancel:q,    success: function (res) {      if (res.confirm) {        if (succ){          succ();        }      } else if (res.cancel) {        if (fail) {          fail();        }      }    }  })}

tip: 1、如有遇到新问题,可以在下方留言或者加QQ群437729329 进行咨询
版权说明:该文章为小程序社区(http://www.wxapp-union.com/)版主TEl分享,转载请注明出处。

版权声明

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

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

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