1.腾讯云的人脸核身需要付费使用,从腾讯云购买
2.uniapp导入两个插件DC-WBFaceService 和 DC-WBNormal
DC-WBFaceService用来做人脸核身的
DC-WBNormal用来解析腾讯云返回请求
3.前端代码
startWbFaceVerifyService(data) {
const face = uni.requireNativePlugin('DC-WBFaceService');
// 调起 SDK
face.startWbFaceVerifyService({
apiVersion: "1.0.0",
appId: this.appid,
nonce: data.nonceStr,
userId: data.userId,
sign: data.sign,
orderNo: data.orderNo,
licence: this.licence,
faceId: data.faceId,
faceType: '0',
compareType: '0',
sdkConfig: {
//和iOS共有的配置参数
showSuccessPage: true, //是否展示成功页面
showFailurePage: true, //是否展示失败页面
recordVideo: false, //是否录制视频
playVoice: true, //是否播放语音提示
detectCloseEyes: false, //是否检测用户闭眼
theme: '0', //sdk皮肤设置,0黑色,1白色
//android独有的配置参数
isEnableLog: false, //是否打开刷脸native日志,请release版本关闭!!!
//iOS独有的配置参数
windowLevel: '1', //sdk中拉起人脸活体识别界面中使用UIWindow时的windowLevel配置
manualCookie: true //是否由SDK内部处理sdk网络请求的cookie
}
}, result => {
//scene区分回调场景
console.log(result)
let scene = result.scene;
//登录失败,可以通过error获得失败原因
if (scene == 'wb_face_callback_login_failure') {
let res = result.res;
let error = res.error;
uni.showToast({
icon: 'none',
title: error.reason
});
return;
}
//返回刷脸结果
if (scene == "wb_face_callback_verify_result") {
let res = result.res;
//success区分是否刷脸成功
let success = res.success;
console.log(data.orderNo)
if (success) {
this.$apiPhp.post('user/getorcresult', {order_no:data.orderNo}).then((obj) => {
console.log(obj)
if (obj.data.result == 1) {
this.showToast('认证成功')
this.authed = 2
this.identityStatus = 1
this.getIdentity(false)
this.getStatus()
}
})
//刷脸成功
//还可以通过res拿到orderNo,sign,userImageString(用户刷脸base64 string照片)
// console.log("刷脸成功:liverate=" + res.liveRate + ",similarity=" + res.similarity);
// uni.showToast({
// icon: 'none',
// title: "刷脸成功"
// });
} else {
//刷脸失败
let error = res.error;
//可以通过domain区分是本地刷脸错误,还是人脸对比失败,
let domain = error.domain;
//如果是人脸对比失败,可以从res里拿到liveRate和similarity
if (domain == "WBFaceErrorDomainCompareServer") {
// console.log("对比失败,liveRate=" + res.liveRate + "; similarity=" + res.similarity + ";sign=" + res.sign);
uni.showToast({
icon: 'none',
title: "对比失败"
});
return;
}
uni.showToast({
icon: 'none',
title: error.desc
});
}
}
});
}
提示:手机静音会导致语音播放不了