uniapp的安卓APP实现腾讯云人脸核身功能(前端部分)

本文介绍如何在uniapp项目中集成腾讯云的人脸核身服务,包括购买服务、引入插件及实现前端调用的方法。文章详细展示了配置参数及回调处理流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
							});
						}
					}
				});
			}

提示:手机静音会导致语音播放不了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值