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

小程序实现人脸识别功能

调用api   wx.startFacialRecognitionVerify

第一步:

// 修改方法expertUpdate() {wx.startFacialRecognitionVerify({name: _this.registerForm.realName, //身份证名称idCardNumber: _this.registerForm.idCard, //身份证号码checkAliveType: 1, //屏幕闪烁(人脸核验的交互方式,默认0,读数字)success(res) {console.log(res)  //认证结果if(res.errCode == 0){//识别成功  这个时候可以调后端的接口 (带着返的res.verifyResult)_this.verifyUser(res.verifyResult)}else{tipInfo("识别失败")}},complete(res) {console.log(res)},fail(e) {console.log("err", err)//失败处理方法wx.showToast('请保持光线充足,面部正对手机,且无遮挡')}})}

第二步:调方法 校验后端的接口

 // 人脸识别  根据上一个方法把verify_result传过来  //后端的校验接口verifyUser(verify_result) {//看后端实际要求 要传身份证号码不let obj = {uuid: this.infoForm.idCard,verify_result: verify_result}//后端接口=>verifyUserverifyUser(obj).then(res => {if (res.code == '0') {this.$refs.uForm.validate().then(res => {let obj = {pkid: uni.getStorageSync('expert_info').pkid,memberId: uni.getStorageSync('expert_info').memberId,avatar: this.fileList1[0].url,realName: this.infoForm.realName,orgName: this.infoForm.orgName,idCard: this.infoForm.idCard,province: this.infoForm.province,city: this.infoForm.city,district: this.infoForm.district,phone: this.infoForm.phone,professorLevel: this.infoForm.professorLevel,adept: this.infoForm.adept,intro: this.infoForm.intro,smsCode: this.infoForm.smsCode,annex: this.fileList2,}//修改方法expertUpdate(obj).then(res => {console.log(res, '修改成功了吗');if (res.code == '0') {uni.$u.toast('修改成功', 5000)uni.navigateBack()//修改成功后 是返回上一步  还是跳转其他页面 根据实际情况} else {uni.$u.toast(res.msg, 5000)}})console.log(res);}).catch(error => {console.log(error);uni.$u.toast('请先按要求填写', 5000)})}})},

注释:完整方法  这个是实现小程序个人信息完善,加了一个判断,如果 输入框没有值则需要走人脸识别验证方法  如果有值 只是修改其他项 就不需要验证  修改完成之后 名字和身份证号码直接禁用

 // 修改方法expertUpdate() {if (this.fileList1.length == 0) {uni.$u.toast('请上传头像')return false}// 判断 realName 是否为空if (!this.infoForm.realName) {uni.$u.toast('请填写姓名');return false;}// 验证 realName 是否为中文const chineseRegex = /^[\u4e00-\u9fa5]+$/;if (!chineseRegex.test(this.infoForm.realName)) {uni.$u.toast('姓名必须为中文');return false;}// 判断 idCard 是否为空if (!this.infoForm.idCard) {uni.$u.toast('请填写身份证号码');return false;}// 验证 idCard 是否符合身份证标准const idCardRegex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;if (!idCardRegex.test(this.infoForm.idCard)) {uni.$u.toast('身份证号格式不正确');return false;}if (this.fileList2.length == 0) {uni.$u.toast('请上传附件')return false}if (this.infoForm.intro.length > 200) {uni.$u.toast('简介字数不能超过200字!')return false}if (!this.flag) {let _this = thiswx.startFacialRecognitionVerify({name: _this.infoForm.realName,idCardNumber: _this.infoForm.idCard,checkAliveType: 1,success(res) {console.log(res)_this.verifyUser(res.verifyResult)// console.log(res)// uni.navigateBack()},complete(res) {console.log(res)},fail(e) {// console.log(res)// console.log(_this.infoForm.realName)// console.log(_this.infoForm.idCard)console.log(e, 'fail')}})} else {this.$refs.uForm.validate().then(res => {let obj = {pkid: uni.getStorageSync('expert_info').pkid,memberId: uni.getStorageSync('expert_info').memberId,avatar: this.fileList1[0].url,realName: this.infoForm.realName,orgName: this.infoForm.orgName,idCard: this.infoForm.idCard,province: this.infoForm.province,city: this.infoForm.city,district: this.infoForm.district,phone: this.infoForm.phone,professorLevel: this.infoForm.professorLevel,adept: this.infoForm.adept,intro: this.infoForm.intro,smsCode: this.infoForm.smsCode,annex: this.fileList2,}expertUpdate(obj).then(res => {console.log(res, '修改成功了吗');if (res.code == '0') {uni.$u.toast('修改成功', 5000)uni.navigateBack()// this.getExpertInfo()} else {uni.$u.toast(res.msg, 5000)}})console.log(res);}).catch(error => {console.log(error);uni.$u.toast('请先按要求填写', 5000)})}},// 人脸识别verifyUser(verify_result) {let obj = {uuid: this.infoForm.idCard,verify_result: verify_result}verifyUser(obj).then(res => {if (res.code == '0') {this.$refs.uForm.validate().then(res => {let obj = {pkid: uni.getStorageSync('expert_info').pkid,memberId: uni.getStorageSync('expert_info').memberId,avatar: this.fileList1[0].url,realName: this.infoForm.realName,orgName: this.infoForm.orgName,idCard: this.infoForm.idCard,province: this.infoForm.province,city: this.infoForm.city,district: this.infoForm.district,phone: this.infoForm.phone,professorLevel: this.infoForm.professorLevel,adept: this.infoForm.adept,intro: this.infoForm.intro,smsCode: this.infoForm.smsCode,annex: this.fileList2,}expertUpdate(obj).then(res => {console.log(res, '修改成功了吗');if (res.code == '0') {uni.$u.toast('修改成功', 5000)uni.navigateBack()// this.getExpertInfo()} else {uni.$u.toast(res.msg, 5000)}})console.log(res);}).catch(error => {console.log(error);uni.$u.toast('请先按要求填写', 5000)})}})},

http://www.lryc.cn/news/188328.html

相关文章:

  • 【】javax.crypto.IllegalBlockSizeException: Input length not multiple of 8 bytes
  • 312.戳气球
  • get_trade_detail_data函数使用
  • 【融合ChatGPT等AI模型】Python-GEE遥感云大数据分析、管理与可视化及多领域案例实践应用
  • LeetCode862 和至少为k的最短子数组
  • 网卡bonding模式 - bond模式配置介绍
  • 做了个 chrome 插件实现 B 站视频截图功能,直接从当前视频帧无损复制
  • Docker linux 安装
  • windows部署django服务器
  • ChatGPT prompt汇总-个人使用-持续更新....
  • Vue实现简单的接口封装
  • 软件测试工具有什么作用?有哪些好用的测试工具推荐?
  • 写爬虫?前端er何必用python
  • 交通物流模型 | 基于交通图卷积长短时记忆网络的网络级交通流预测
  • web 基础和http 协议
  • Java常量与变量
  • 神经网络中卷积和池化的区别
  • RK3568平台开发系列讲解(驱动篇)RK3568 PWM详解
  • 禾匠商城系统 企业转账到零钱 修改成 商家转账到零钱
  • 点云从入门到精通技术详解100篇-基于激光点云的道路目标检测
  • 【Hello Algorithm】暴力递归到动态规划(一)
  • 凉鞋的 Godot 笔记 107. 脚本窗口文件系统窗口
  • 数据源作用以及spring配置数据源
  • Javaweb中的servlet中的消息体是什么?
  • 饥荒服务器阿里云租用价格表一年和一个月收费报价表
  • 前端 JS 经典:Math 常用方法汇总
  • MongoDB 笔记
  • Maven 项目文档
  • 浏览器中XPath的使用
  • js录制屏幕并输出视频