uniapp 实人认证

2024-06-20 21:12
文章标签 uniapp 认证 实人

本文主要是介绍uniapp 实人认证,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

首先Dcloud创建云服务空间,开启一键登录并充值

下一步

1. 右键项目 》 创建uniCloud云开发环境 》右键uniCloud》关联云服务空间

2. cloudfunctions右键 新建云函数,任意命名(例:veify),然后右键项目》管理公告模块或扩展库依赖》选择

在这里插入图片描述

3.点击 云函数veify》目录下的 “ index.js ” 改名 “ index.obj.js ” 否则获取不到

3.1 index.obj.js 内代码如下
'use strict';
module.exports = {// __before调用其他方法前会先调用这个方法_before(context) {// 创建实人认证实例this.frvManager = uniCloud.getFacialRecognitionVerifyManager({requestId: this.getUniCloudRequestId()})},async getCertifyId({ realName, idCard, metaInfo }) {// 会先调用_beforetry {const result = await this.frvManager.getCertifyId({ realName, idCard, metaInfo });return result} catch (e) {throw { errCode: 500, message: '获取认证失败,请检查信息的正确性' };}},// 获取认证的结果async getAuthResult(certifyId) {try {const result = await this.frvManager.getAuthResult({ certifyId });return result} catch (e) {throw { errCode: 500, message: '认证失败' };}}
}

3.2 打包自定义包测试

4.在页面上获取云函数

// 注册实人认证
// veify为云函数文件名const uniCloudVerify = uniCloud.importObject('veify');

5,封装认证代码

//点击认证
submit(){let data = {realName:this.params.realName,idCard:this.params.idNumber}this.uniCloudVerifyFunction(data).then(res => {console.log('实名认证yes',res);if(res.authState == 'SUCCESS'){//成功}// 提示成功}).catch(err => {console.log('实名认证no',err);// 提示失败})
},
//封装
async uniCloudVerifyFunction({ realName, idCard }) {// 获取设备信息const metaInfo = uni.getFacialRecognitionMetaInfo();// 获取CertifyIdconst certifyidResult = await uniCloudVerify.getCertifyId({ realName, idCard, metaInfo }) if (certifyidResult.errCode != 0) return Promise.reject({ code: 500, msg: '获取certifyid失败,请联系管理员处理!' })const certifyId = certifyidResult.certifyId;// 开始认证return new Promise((resolve, reject) => {uni.startFacialRecognitionVerify({certifyId: certifyId,success: async res => {console.log(res);const result = await uniCloudVerify.getAuthResult(certifyId);resolve(result);},fail: err => {reject({ code: err.errCode, msg: err.errMsg })}});})
}

完成

下面是我的demo,供参考

<template><view><view class="navBbutPart" ><button class="butsty font30" hover-class="butstyHover" @click="$u.throttle(submit, 1000)"> 人脸验证 </button></view></view>
</template><script>import { accountAuthenticationedit,accountAuthenticationadd } from "@/api/all.js"// 注册实人认证const uniCloudVerify = uniCloud.importObject('getFaceRecognition');export default {name:"getBack",props:{params:{},//是否修改edit:{default:false}},data() {return {};},onLoad() {// console.log(uni.getFacialRecognitionMetaInfo());},methods:{async uniCloudVerifyFunction({ realName, idCard }) {// 获取设备信息const metaInfo = uni.getFacialRecognitionMetaInfo();// 获取CertifyIdconst certifyidResult = await uniCloudVerify.getCertifyId({ realName, idCard, metaInfo }) if (certifyidResult.errCode != 0) return Promise.reject({ code: 500, msg: '获取certifyid失败,请联系管理员处理!' })const certifyId = certifyidResult.certifyId;// 开始认证return new Promise((resolve, reject) => {uni.startFacialRecognitionVerify({certifyId: certifyId,success: async res => {console.log(res);const result = await uniCloudVerify.getAuthResult(certifyId);resolve(result);},fail: err => {reject({ code: err.errCode, msg: err.errMsg })}});})},submit(){let data = {realName:this.params.realName,idCard:this.params.idNumber}this.uniCloudVerifyFunction(data).then(res => {console.log('实名认证yes',res);if(res.authState == 'SUCCESS'){if(!this.edit){accountAuthenticationadd(this.params).then(resapi=>{console.log('实名认证接口',resapi);this.com.back()//返回})}else{accountAuthenticationedit(this.params).then(resapi=>{this.com.back()})}}// 提示成功}).catch(err => {console.log('实名认证no',err);// 提示失败})}}}
</script><style scoped lang="scss">
.navBbutPart{width: 90%;position: fixed;bottom: 200rpx;padding: 0 5%;button{border-radius: 50rpx;}}
</style>

这篇关于uniapp 实人认证的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1079266

相关文章

浅析Spring Security认证过程

类图 为了方便理解Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类 概述 核心验证器 AuthenticationManager 该对象提供了认证方法的入口,接收一个Authentiaton对象作为参数; public interface AuthenticationManager {Authentication authenticate(Authenti

【Kubernetes】K8s 的安全框架和用户认证

K8s 的安全框架和用户认证 1.Kubernetes 的安全框架1.1 认证:Authentication1.2 鉴权:Authorization1.3 准入控制:Admission Control 2.Kubernetes 的用户认证2.1 Kubernetes 的用户认证方式2.2 配置 Kubernetes 集群使用密码认证 Kubernetes 作为一个分布式的虚拟

uniapp设置微信小程序的交互反馈

链接:uni.showToast(OBJECT) | uni-app官网 (dcloud.net.cn) 设置操作成功的弹窗: title是我们弹窗提示的文字 showToast是我们在加载的时候进入就会弹出的提示。 2.设置失败的提示窗口和标签 icon:'error'是设置我们失败的logo 设置的文字上限是7个文字,如果需要设置的提示文字过长就需要设置icon并给

基于SpringBoot的宠物服务系统+uniapp小程序+LW参考示例

系列文章目录 1.基于SSM的洗衣房管理系统+原生微信小程序+LW参考示例 2.基于SpringBoot的宠物摄影网站管理系统+LW参考示例 3.基于SpringBoot+Vue的企业人事管理系统+LW参考示例 4.基于SSM的高校实验室管理系统+LW参考示例 5.基于SpringBoot的二手数码回收系统+原生微信小程序+LW参考示例 6.基于SSM的民宿预订管理系统+LW参考示例 7.基于

【Shiro】Shiro 的学习教程(二)之认证、授权源码分析

目录 1、背景2、相关类图3、解析3.1、加载、解析阶段3.2、认证阶段3.3、授权阶段 1、背景 继上节代码,通过 debug 进行 shiro 源码分析。 2、相关类图 debug 之前,先了解下一些类的结构图: ①:SecurityManager:安全管理器 DefaultSecurityManager: RememberMeManager:实现【记住我】功能

OpenStack离线Train版安装系列—3控制节点-Keystone认证服务组件

本系列文章包含从OpenStack离线源制作到完成OpenStack安装的全部过程。 在本系列教程中使用的OpenStack的安装版本为第20个版本Train(简称T版本),2020年5月13日,OpenStack社区发布了第21个版本Ussuri(简称U版本)。 OpenStack部署系列文章 OpenStack Victoria版 安装部署系列教程 OpenStack Ussuri版

OpenStack Victoria版——3.控制节点-Keystone认证服务组件

3.控制节点-Keystone认证服务组件 更多步骤:OpenStack Victoria版安装部署系列教程 OpenStack部署系列文章 OpenStack Victoria版 安装部署系列教程 OpenStack Ussuri版 离线安装部署系列教程(全) OpenStack Train版 离线安装部署系列教程(全) 欢迎留言沟通,共同进步。 文章目录 创建key

基于springboot+vue+uniapp的“共享书角”图书借还管理系统小程序

开发语言:Java框架:springboot+uniappJDK版本:JDK1.8服务器:tomcat7数据库:mysql 5.7(一定要5.7版本)数据库工具:Navicat11开发软件:eclipse/myeclipse/ideaMaven包:Maven3.3.9 系统展示 后台登录界面 管理员功能界面 出借者管理 图书信息管理 图书归还管理 出租收入管理

uniapp小程序下载缓存服务器上的图片

1. 使用uni.downloadFile,但是注意下载图片的地址里的域名,需要在微信公众平台里面的downloadFile合法域名进行配置。 export default function downloadAndCacheImage(imageUrl, name) {return new Promise((resolve, reject) => {console.log("imageUrl",

uniapp,vite整合windicss

官方文档:https://weapp-tw.icebreaker.top/docs/quick-start/frameworks/hbuilderx 安装: npm i -D tailwindcss postcss autoprefixer# 初始化 tailwind.config.js 文件npx tailwindcss initnpm i -D weapp-tailwindcss# 假