小程序实现人脸识别功能

调用api   wx.startFacialRecognitionVerify

第一步:

      // 修改方法
      expertUpdate() {

       let _this = this
       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
        }

      //后端接口=>verifyUser
        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()
                  //修改成功后 是返回上一步  还是跳转其他页面 根据实际情况
                } 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 = this
          wx.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)
            })
          }
        })
      
      },
      

  • 6
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程序源码(含截图)人脸检测微信小程
微信小程序人脸识别注册登录功能是一种基于人脸识别技术的身份验证方式,通过识别用户的面部特征来实现登录和注册功能。这种技术可以提高用户的使用体验和安全性,因为它可以避免用户忘记密码或泄露密码的风险。 实现微信小程序人脸识别注册登录功能需要以下步骤: 1. 获取用户的人脸图像:用户需要在微信小程序界面上使用手机摄像头拍摄自己的面部图像,或者上传自己的面部照片。 2. 人脸特征提取:通过使用人脸识别算法,提取用户面部图像中的特征点,例如眼睛、鼻子、嘴巴等部位的位置和大小等信息。 3. 人脸特征存储:将用户的面部特征存储到服务器端的数据库中,以便后续的验证和识别。 4. 登录和注册验证:当用户需要登录或注册时,系统会要求用户再次上传自己的面部照片进行验证。系统将对新上传的面部照片提取特征并与之前存储的特征进行比对,如果匹配成功,则允许用户登录或注册,否则拒绝。 5. 安全保障:为了保障用户的面部信息安全,系统需要采取一些措施,例如对人脸特征进行加密存储、限制访问权限等。同时,也需要考虑到一些攻击手段,例如伪造面部图像、使用面具等,采取一些技术手段进行防范。 总之,微信小程序人脸识别注册登录功能是一种比传统的用户名密码登录更加安全和便捷的身份验证方式,将会在未来得到越来越广泛的应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值