uniapp中的生物认证(指纹、人脸识别)

效果图:

实现代码:

<template>
	<view>
		<button @click="checkIsSupportSoterAuthentication">检查支持的认证方式</button>
		<button type="primary" @click="checkIsSoterEnrolledInDeviceFingerPrint">检查是否录入指纹</button>
		<button @click="checkIsSoterEnrolledInDeviceFaceID">检查是否录入FaceID</button>
		<button type="primary" @click="startSoterAuthenticationFingerPrint">开始指纹认证</button>
		<button @click="startSoterAuthenticationFaceID">开始FaceID认证</button>
		{{ result }}
	</view>
</template>

<script>
export default {
	data() {
		return {
			result: ''
		};
	},
	onLoad() {},
	methods: {
		checkIsSupportSoterAuthentication() {
			uni.checkIsSupportSoterAuthentication({
				success(res) {
					uni.showModal({
						content: '支持的认证方式:' + res.supportMode,
						showCancel: false
					});
					console.log(res);
				},
				fail(err) {
					console.log(err);
				}
			});
		},
		checkIsSoterEnrolledInDeviceFingerPrint() {
			uni.checkIsSoterEnrolledInDevice({
				checkAuthMode: 'fingerPrint',
				success(res) {
					if (res.isEnrolled) {
						uni.showToast({
							icon: 'none',
							title: '已录入指纹'
						});
					} else {
						uni.showModal({
							content: '未录入指纹',
							showCancel: false
						});
					}
					console.log(res);
				},
				fail(err) {
					uni.showModal({
						content: '未录入指纹',
						showCancel: false
					});
					console.log(err);
				}
			});
		},
		checkIsSoterEnrolledInDeviceFaceID() {
			uni.checkIsSoterEnrolledInDevice({
				checkAuthMode: 'facial',
				success(res) {
					if (res.isEnrolled) {
						uni.showToast({
							icon: 'none',
							title: '已录入FaceID'
						});
					} else {
						uni.showModal({
							content: '未录入FaceID',
							showCancel: false
						});
					}
					console.log(res);
				},
				fail(err) {
					uni.showModal({
						content: '未录入FaceID',
						showCancel: false
					});
					console.log(err);
				}
			});
		},
		startSoterAuthenticationFingerPrint() {
			uni.startSoterAuthentication({
				requestAuthModes: ['fingerPrint'],
				challenge: '123456',
				authContent: '请用指纹解锁',
				success(res) {
					uni.showToast({
						icon: 'none',
						title: '指纹验证成功'
					});
					console.log(res);
				},
				fail(err) {
					uni.showModal({
						content: '指纹验证失败,errCode:' + err.errCode,
						showCancel: false
					});
					console.log(err);
				}
			});
		},
		startSoterAuthenticationFaceID() {
			uni.startSoterAuthentication({
				requestAuthModes: ['facial'],
				challenge: '123456',
				authContent: '请用FaceID解锁',
				success(res) {
					uni.showToast({
						icon: 'none',
						title: 'FaceID验证成功'
					});
					console.log(res);
				},
				fail(err) {
					uni.showModal({
						content: 'FaceID验证失败,errCode:' + err.errCode,
						showCancel: false
					});
					console.log(err);
				}
			});
		}
	}
};
</script>

<style></style>

 

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值