+
95
-

回答

可以再微信小程序后台申请这个功能调用,注意不是所有的类别都能申请的,要看看你的小程序类别是否在人脸核验的范围内。

请通过mp.weixin.qq.com登录小程序账号在后台“功能-人脸核身”的路径,点击开通按钮

800_auto

申请通过后就可以通过wx.startFacialRecognitionVerify这个方法调用人脸核验

<view class="usertitle">
  <div class='titleText'>人脸识别认证</div>
</view>
<form bindsubmit="facialRecognitionVerify">
  <view class='btnToFaceCheck'>
    <button class='btnToFaceCheck' formType="submit">
      <text>点击此处开始人脸识别认证</text>
    </button>
  </view>
</form>

js

javascript
复制代码
Page({
    onLoad: function (options) {
      var that = this;
      that.setData({faceCheckData:options});
    },
  facialRecognitionVerify: function () {
    // 1.检测设备是否支持人脸识别
      checkIsSupportFacialRecognition({
        checkAliveType: 2,
        success: function(res) {
          if (res.errCode === 0 || res.errMsg === "checkIsSupportFacialRecognition:ok") {
            // 2.调用人脸识别
                wx.startFacialRecognitionVerify({
                   name: "传入参数", //姓名
                   idCardNumber: "传入参数", //身份证号
                   //人脸识别成功回调通知
                  success (res) {
                  var verifyResult = res.verifyResult;
                  console.log(verifyResult)
                },
                //人脸识别失败的回调通知
                    'fail': function (res) {
                        console.log(res,"失败");
                        wx.showModal({
                          title: '提示',
                          showCancel: false,
                          content: "人脸识别失败!" + res.errCode+","+res.errMsg,
                          success: function (res) {
                            if (res.confirm) {
                                wx.navigateTo()
                            }
                          }
                        });
                    }
                   });
        return;
          }
          wx.showToast('微信版本过低,暂时无法使用此功能,请升级微信最新版本')
        },
        fail: res => {
          wx.showToast('微信版本过低,暂时无法使用此功能,请升级微信最新版本')
        }
      });
    }
    })

具体接口文档请参考:

微信人脸核身接口能力 | 微信开放社区 (qq.com)

网友回复

我知道答案,我要回答