微信小程序之(zhī)生物識别 - 新聞資訊 - 雲南小程序開發|雲南軟件開發|雲南網站建設-昆明融晨信息技術有限公司

159-8711-8523

雲南網建設/小程序開發/軟件開發

知識

不(bù)管是(shì)網站,軟件還是(shì)小程序,都要(yào / yāo)直接或間接能爲(wéi / wèi)您産生價值,我們在(zài)追求其視覺表現的(de)同時(shí),更側重于(yú)功能的(de)便捷,營銷的(de)便利,運營的(de)高效,讓網站成爲(wéi / wèi)營銷工具,讓軟件能切實提升企業内部管理水平和(hé / huò)效率。優秀的(de)程序爲(wéi / wèi)後期升級提供便捷的(de)支持!

您當前位置>首頁 » 新聞資訊 » 小程序相關 >

微信小程序之(zhī)生物識别

發表時(shí)間:2022-9-6

發布人(rén):融晨科技

浏覽次數:98

今天閑來(lái)沒事,了(le/liǎo)解下生物識别。

生物識别有三個(gè)接口


1、wx.checkIsSupportSoterAuthentication 用來(lái)獲取本機支持的(de)生物識别方式(人(rén)臉、指紋、聲紋)

2、wx.startSoterAuthentication 進行生物認證

3、wx.checkIsSoterEnrolledInDevice 檢測是(shì)否錄入生物信息

有興趣的(de)童鞋可以(yǐ)拿代碼去玩玩試試看

wxml代碼

 bindtap="checkIsFingerPrint">檢測是(shì)否可以(yǐ)指紋識别
 bindtap="checkIsFacial">檢測是(shì)否可以(yǐ)人(rén)臉識别
 bindtap="HaveFingerPrint">該設備是(shì)否錄入指紋
 bindtap="FingerPrint">識别指紋

js代碼

Page({

  /**
   * 頁面的(de)初始數據
   */
  data: {
    isfingerPrint : false,    //可否使用指紋識别  默認false
    isfacial: false,          //可否使用人(rén)臉識别  默認false
  },

  /**
   * 生命周期函數--監聽頁面加載
   */
  onLoad: function (options) {
    var that = this
    //查看支持的(de)生物認證   比如ios的(de)指紋識别   安卓部分機器是(shì)不(bù)能用指紋識别的(de)
    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("支持人(rén)臉識别", res.supportMode[i]);
          }
        }
      }
    })
  },
  //是(shì)否可以(yǐ)指紋識别
  checkIsFingerPrint:function(){
    var boole = this.data.isfingerPrint
    var txt = "不(bù)可以(yǐ)使用指紋識别"
    if (boole) {
      txt = "可以(yǐ)使用指紋識别"
    }
    show("提示",txt,false);
  },
  //是(shì)否可以(yǐ)人(rén)臉識别
  checkIsFacial: function () {
    var boole = this.data.isfacial
    var txt = "不(bù)可以(yǐ)使用人(rén)臉識别"
    if (boole){
      txt = "可以(yǐ)使用人(rén)臉識别"
    }
    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);
      }
    })


  },
  //是(shì)否有指紋
  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 提示的(de)标題
 * msg 提示的(de)内容
 * q   是(shì)否有取消按鈕(布爾值)
 * succ 用戶點擊确定的(de)回調(非必須)
 * fail 用戶點擊取消的(de)回調(非必須)
 *
 */
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、如有遇到(dào)新問題,可以(yǐ)在(zài)下方留言或者加QQ群437729329 進行咨詢

相關案例查看更多