文章目录
前言
最近项目有一个指纹登录的功能,做个记录。
一、uniapp 生物认证(指纹或者面容ID)
https://uniapp.dcloud.io/api/system/authentication
二、流程图
1.manifest.json勾选配置
2.调用官方api
-
第一步:uni.checkIsSupportSoterAuthentication: 获取本机支持认证方式,res.supportMode = [‘fingerPrint’] 只支持指纹识别,res.supportMode = [‘fingerPrint’, ‘facial’] 支持指纹识别和人脸识别。
-
第二步: uni.checkIsSoterEnrolledInDevice : 获取设备内是否录入指纹信息
-
第三步:uni.startSoterAuthentication开始 SOTER 生物认证
<template>
<view>
<view>{{ result }}</view>
</view>
</template>
<script>
export default {
data() {
return {
result: ''
}
},
onLoad() {
this.checkIsSupportSoterAuthentication()
},
methods: {
/**
* uni.checkIsSupportSoterAuthentication: 获取本机支持认证方式(
* res.supportMode = ['fingerPrint'] 只支持指纹识别
* res.supportMode = [] 不具备任何被SOTER支持的生物识别方式
* res.supportMode = ['fingerPrint', 'facial'] 支持指纹识别和人脸识别
* )
* 需求: 当前业务只要求指纹识别功能,(如你的业务中需要人脸识别,此方法也可以验证)
*
*/
checkIsSupportSoterAuthentication(){
// #ifdef APP-PLUS || MP-WEIXIN
uni.checkIsSupportSoterAuthentication({
success(res) {
console.log(res);
// 如果当前设备支持生物识别方式,且支持指纹识别方式
if(res.supportMode && res.supportMode.includes('fingerPrint')){
/**
* uni.checkIsSoterEnrolledInDevice : 获取设备内是否录入指纹信息
* checkAuthMode: 'fingerPrint', // 检验指纹信息
* */
uni.checkIsSoterEnrolledInDevice({
checkAuthMode: 'fingerPrint', // 检验指纹信息
success(res) {
console.log(res.isEnrolled)
if(res.isEnrolled == true){
/**
* 开始 SOTER 生物认证
* 执行成功,进行后续操作
* */
uni.startSoterAuthentication({
requestAuthModes: ['fingerPrint'],
challenge: '123456',
authContent: '请用指纹解锁',
success(res) {
console.log(res);
uni.showToast({
title: "识别成功",
duration: 5000,
icon:'none'
})
//指纹识别成功后,进行后续工作
},
fail(err) {
console.log(err,'66666666666666666');
},
complete(res) {
console.log(res);
}
})
}else{
this.result = '此设备未录入指纹,请到设置中开启';
}
},
fail(err) {
uni.showModal({
title:'温馨提示',
content:'此设备未录入指纹,请到设置中开启',
showCancel: false,
success:function(res){
// 进行后续逻辑
}
})
}
})
}
else{
this.result = "此设备不支持指纹识别功能"
}
},
fail(err) {
uni.showModal({
title:'温馨提示',
content:'此设备不支持指纹识别功能',
showCancel: false,
success:function(res){
// 进行后续逻辑
}
})
}
})
// #endif
// #ifndef APP-PLUS || MP-WEIXIN
this.result = '此平台不支持指纹识别';
// #endif
}
}
}
</script>
总结
我以为的指纹识别=》一人一码 , 调用后台比对专属识别实际上的指纹识别=》调用本机指纹模块,只能识别是不是机主