打开人脸识别小程序
openFace (param) {
// 打开人脸识别小程序
// mchid 服务商商户号 sub_mchid 子商户号 appid 服务商应用ID sub_appid 子商户应用ID
// openid 用户标识 token 预下单token authenticate_number 商户单号
// const { mchid, sub_mchid, appid, sub_appid, openid, token, authenticate_number } = param
// const path = `/pages/card/authen_with_auth?mchid=${mchid}&sub_mchid=${sub_mchid}&appid=${appid}&sub_appid=${sub_appid}&openid=${openid}&token=${token}&authenticate_number=${authenticate_number}`
if (wx.navigateToMiniProgram) {
const path = '/pages/card/authen_with_auth?mchid=123456&sub_mchid=666666&appid=wx1234567889999&sub_appid=wx1234567000000&openid=o17o88-JPyaisuNH-8RXGwcfb4zE&token=qfq-34ewq257w_1re4re&authenticate_number=abcdefghijklmn'
wx.navigateToMiniProgram({
appId: 'wxd24d9057cd83d47a',
path,
success(res) {
// 打开成功
console.log('succ-res', res)
},
fail (err) {
// 调用失败
console.log('err', err)
}
})
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
}
onshow方法中监听小程序人脸识别的结果
onShow(options) {
// 场景数值为1038(从其他小程序跳回),跳回的小程序appid为wxd24d9057cd83d47a
if (options && options.scene === 1038 && options.referrerInfo && options.referrerInfo.appId === 'wxd24d9057cd83d47a') {
const resp = options.referrerInfo.extraData || {};
// msg_type 标识本次返回结果的消息类型,此处为人脸核身的消息,为: AUTHENTICATE_WITH_AUTHORIZATION
// authorize_state授权状态,首次授权时返回:UTHORIZATION_SUCCESS:授权成功;INCONSISTENT_REAL_NAME:实名信息不一致。
// authenticate_state 核身状态:AUTHENTICATE_SUCCESS:核身成功;VERIFY_FACE_FAILED_TOO_MANY:人脸验证失败次数过多。
// authenticate_time 核身时间(时间戳),核身成功时返回
const { msg_type, authenticate_state } = resp
if (msg_type === 'AUTHENTICATE' && authenticate_state === 'AUTHENTICATE_SUCCESS') {
// TODO 处理人脸核身成功返回结果
} else {
Tip.error("人脸核身失败,请稍后再打卡")
}
}
}