当前位置: 首页 > ds >正文

uniApp对接实人认证

前端代码部分

<template><view class="wrap"><view class="box"><view class="item flex-row align-items-center space-between"><view class="name"><text style="color:#FF4D4D">*</text>姓名</view><view class="value"><input type="text" placeholder="请输入姓名" placeholder-class="plc" v-model="realName"></view></view><view class="item flex-row align-items-center space-between"><view class="name"><text style="color:#FF4D4D">*</text>身份证号码</view><view class="value"><input type="text" placeholder="请输入身份证号码" placeholder-class="plc" v-model="idCard"></view></view></view><view class="btn" @click="submit">确认并进行人脸认证</view></view>
</template><script>import {error,jumpPage,isLogin,success} from "@/utils/tools"import {prefectUserInfo} from "@/utils/api/api"export default {data() {return {baseUrl: getApp().globalData.baseUrl,userInfo:{},realName: '',idCard: ''}},onLoad() {this.userInfo = uni.getStorageSync('userInfo')},methods: {submit() {const _this = this// 1. 获取设备信息const metaInfo = uni.getFacialRecognitionMetaInfo()if (!metaInfo) {error('提示当前设备不支持刷脸')return}//在调用之前可以自己加一些获取摄像头权限等操作...uniCloud.callFunction({name: 'startFaceVerify',data: {metaInfo,realName: _this.realName,idCard: _this.idCard,step: 1},success({result}) {if(result.code === 500){error(result.msg)return}// 3. 客户端调起sdk刷脸认证uni.startFacialRecognitionVerify({certifyId: result.data,success(success) {//获取认证结果uniCloud.callFunction({name: 'startFaceVerify',data: { certifyId: result.data },success({result}) {const params = {id: _this.userInfo.id,user_face_image: result.data.pictureUrl,realname: _this.realName,idcard: _this.idCard}prefectUserInfo(params).then(response =>{if(response.errorCode === 0){uni.navigateBack()}else{error('认证失败')}})},fail(e) { error('认证失败') }})},fail(e) { error('认证失败') }})},fail(e) { error('认证失败') }})}}}
</script>
<style>page {background: #F7F7F7;}
</style>
<style lang="scss">.wrap {background: #F7F7F7;padding: 15px;display: flex;flex-direction: column;align-items: center;.box {width: 100%;padding: 0px 15px;border-radius: 10px;background: #FFFFFF;.item {width: 100%;height: 50px;.name {font-size: 14px;font-weight: 500;color: #121212;}.value {display: flex;align-items: center;input {width: 225px;font-size: 12px;font-weight: 500;color: #666666;text-align: right;}.plc {font-size: 12px;font-weight: 500;color: #666666;}}}}.btn {width: 305px;height: 44px;border-radius: 22px;display: flex;flex-direction: row;justify-content: center;align-items: center;background: linear-gradient(106deg, #5EBBFF 21%, #5670FE 68%);box-shadow: 0px 4px 10px 0px #BECCFF;font-size: 14px;font-weight: bold;color: #FFFFFF;margin-top: 365px;}}
</style>

云函数部分

// index.js 云函数
'use strict'
const crypto = require('crypto')
exports.main = async (event, context) => {// console.log('这个是什么',event.step);// return// 获取实人认证实例const frvManager = await uniCloud.getFacialRecognitionVerifyManager({requestId: context.requestId})if (event.step == 1) {try {/*** 获取certifyId* @return certifyId 认证id,用于客户端调用认证接口及云函数获取认证结果*/const result = await frvManager.getCertifyId({realName: event.realName,idCard: event.idCard,metaInfo: event.metaInfo,needPicture: true //是否采集人脸照片})if (result.errCode == 0) return {code: 200,data: result.certifyId,msg: '获取certifyId成功'}return {code: 500,data: '',msg: `获取certifyId失败:${ result.errMsg }`}} catch (err) {console.log('err', err);return {code: 500,data: '',msg: '请检查您填写的姓名与身份证号是否正确'}}} else {// 获取认证结果const result = await frvManager.getAuthResult({certifyId: event.certifyId})if (result.authState == 'SUCCESS') return {code: 200,data: result}// 认证失败if (result.authState == 'FAIL') return {code: 500,data: result.certifyId,msg: `认证失败:${ result.errMsg }`}}
}

http://www.xdnf.cn/news/18715.html

相关文章:

  • Clustering Enabled Wireless Channel Modeling Using Big Data Algorithms
  • 【前端debug调试】
  • 如何解决pip安装报错ModuleNotFoundError: No module named ‘arviz’问题
  • 网站速度慢?安全防护弱?EdgeOne免费套餐一次性解决两大痛点
  • chapter05_从spring.xml读取Bean
  • 完整实验命令解析:从集群搭建到负载均衡配置
  • Java:类及方法常见规约
  • Unity中删除不及时的问题
  • 牛客面经2 京东社招-002
  • PyTorch框架之图像识别模型与训练策略
  • 25.深入对象
  • 寻找AI——高保真还原设计图生成App页面
  • 华为/思科/H3C/锐捷操作系统操作指南
  • 鸿蒙应用网络开发实战:HTTP、WebSocket、文件下载与网络检测全攻略
  • 微信小程序和uni-app面试问题总结
  • 网络模型深度解析:CNI、Pod通信与NetworkPolicy
  • Spring Boot 实时广播消息
  • Java集合(Collection、Map、转换)
  • git实战(7)git常用命令速查表
  • GitHub发布革命性工具:GitHub Spark,用自然语言打造全栈智能应用
  • 商品与股指类ETF期权买卖五档Tick分钟级历史行情数据分析
  • Node.js 和 Express 面试问题总结
  • 目标跟踪 YOLO11 单目标跟踪
  • Maven仓库与Maven私服架构
  • Spring Boot 实现 POJO 级联封装复杂属性
  • React Hooks UseRef的用法
  • 高速CANFD收发器ASM1042在割草机器人轮毂电机通信系统中的适配性研究
  • 终结系统裸奔:Debian老旧版本安全加固终极指南
  • 梯度下降(线性回归为例)
  • 总结:Maven多仓库多镜像源配置