微信小程序有什么指纹

时间:2025-01-20 22:36:58 程序应用

微信小程序提供了 SOTER生物认证中的指纹识别功能,具体相关接口如下:

wx.checkIsSupportSoterAuthentication()

该接口用于获取本机支持的SOTER生物认证方式。

调用该接口后,如果返回的`res.supportMode`包含`fingerPrint`,则表示设备支持指纹识别。

wx.checkIsSoterEnrolledInDevice(options)

该接口用于获取设备内是否录入如指纹等生物信息。

调用该接口时,通过设置`checkAuthMode`为`fingerPrint`,可以检查用户是否已录入指纹信息。

wx.startSoterAuthentication(options)

该接口用于开始验证指纹是否是机主本人。

调用该接口时,需要先确认设备支持指纹识别并且用户已录入指纹信息。

示例代码

```javascript

// index.js

Page({

data: {

isfingerPrint: false, // 是否可以使用指纹识别

isfacial: false

},

onLoad: function () {

this.checkSupport();

},

checkSupport: function () {

wx.checkIsSupportSoterAuthentication({

success: (res) => {

if (res.supportMode.includes('fingerPrint')) {

this.setData({ isfingerPrint: true });

this.checkEnrolled();

} else {

this.setData({ isfingerPrint: false });

}

}

});

},

checkEnrolled: function () {

wx.checkIsSoterEnrolledInDevice({

checkAuthMode: 'fingerPrint',

success: (res) => {

if (res.isEnrolled) {

this.startAuthentication();

} else {

console.log('用户未录入指纹');

}

}

});

},

startAuthentication: function () {

wx.startSoterAuthentication({

success: (res) => {

if (res.result) {

console.log('指纹识别成功');

} else {

console.log('指纹识别失败');

}

},

fail: (err) => {

console.error('指纹识别失败', err);

}

});

}

});

```

建议

在实际开发中,建议先调用`wx.checkIsSupportSoterAuthentication()`确认设备是否支持指纹识别,然后调用`wx.checkIsSoterEnrolledInDevice()`检查用户是否已录入指纹信息,最后再调用`wx.startSoterAuthentication()`进行指纹验证。这样可以确保指纹识别功能的顺利实现。