小程序?qū)崿F(xiàn)人臉識(shí)別的項(xiàng)目實(shí)踐
調(diào)用api wx.startFacialRecognitionVerify
第一步:
// 修改方法 expertUpdate() { wx.startFacialRecognitionVerify({ name: _this.registerForm.realName, //身份證名稱 idCardNumber: _this.registerForm.idCard, //身份證號(hào)碼 checkAliveType: 1, //屏幕閃爍(人臉核驗(yàn)的交互方式,默認(rèn)0,讀數(shù)字) success(res) { console.log(res) //認(rèn)證結(jié)果 if(res.errCode == 0){ //識(shí)別成功 這個(gè)時(shí)候可以調(diào)后端的接口 (帶著返的res.verifyResult) _this.verifyUser(res.verifyResult) }else{ tipInfo("識(shí)別失敗") } }, complete(res) { console.log(res) }, fail(e) { console.log("err", err)//失敗處理方法 wx.showToast('請(qǐng)保持光線充足,面部正對(duì)手機(jī),且無(wú)遮擋') } }) }
第二步:調(diào)方法 校驗(yàn)后端的接口
// 人臉識(shí)別 根據(jù)上一個(gè)方法把verify_result傳過(guò)來(lái) //后端的校驗(yàn)接口 verifyUser(verify_result) { //看后端實(shí)際要求 要傳身份證號(hào)碼不 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() //修改成功后 是返回上一步 還是跳轉(zhuǎn)其他頁(yè)面 根據(jù)實(shí)際情況 } else { uni.$u.toast(res.msg, 5000) } }) console.log(res); }).catch(error => { console.log(error); uni.$u.toast('請(qǐng)先按要求填寫', 5000) }) } }) },
注釋:完整方法 這個(gè)是實(shí)現(xiàn)小程序個(gè)人信息完善,加了一個(gè)判斷,如果 輸入框沒(méi)有值則需要走人臉識(shí)別驗(yàn)證方法 如果有值 只是修改其他項(xiàng) 就不需要驗(yàn)證 修改完成之后 名字和身份證號(hào)碼直接禁用
// 修改方法 expertUpdate() { if (this.fileList1.length == 0) { uni.$u.toast('請(qǐng)上傳頭像') return false } // 判斷 realName 是否為空 if (!this.infoForm.realName) { uni.$u.toast('請(qǐng)?zhí)顚懶彰?); return false; } // 驗(yàn)證 realName 是否為中文 const chineseRegex = /^[\u4e00-\u9fa5]+$/; if (!chineseRegex.test(this.infoForm.realName)) { uni.$u.toast('姓名必須為中文'); return false; } // 判斷 idCard 是否為空 if (!this.infoForm.idCard) { uni.$u.toast('請(qǐng)?zhí)顚懮矸葑C號(hào)碼'); return false; } // 驗(yàn)證 idCard 是否符合身份證標(biāo)準(zhǔn) const idCardRegex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; if (!idCardRegex.test(this.infoForm.idCard)) { uni.$u.toast('身份證號(hào)格式不正確'); return false; } if (this.fileList2.length == 0) { uni.$u.toast('請(qǐng)上傳附件') return false } if (this.infoForm.intro.length > 200) { uni.$u.toast('簡(jiǎn)介字?jǐn)?shù)不能超過(guò)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('請(qǐng)先按要求填寫', 5000) }) } }, // 人臉識(shí)別 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('請(qǐng)先按要求填寫', 5000) }) } }) },
到此這篇關(guān)于小程序?qū)崿F(xiàn)人臉識(shí)別的項(xiàng)目實(shí)踐的文章就介紹到這了,更多相關(guān)小程序 人臉識(shí)別內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于JS對(duì)象創(chuàng)建常用方式及原理分析
下面小編就為大家?guī)?lái)一篇基于JS對(duì)象創(chuàng)建常用方式及原理分析。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-06-06js實(shí)現(xiàn)頁(yè)面導(dǎo)航層級(jí)指示效果
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)頁(yè)面導(dǎo)航層級(jí)指示效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08學(xué)習(xí)javascript的閉包,原型,和匿名函數(shù)之旅
Javascript中有幾個(gè)非常重要的語(yǔ)言特性——對(duì)象、原型繼承、閉包。其中閉包 對(duì)于那些使用傳統(tǒng)靜態(tài)語(yǔ)言C/C++的程序員來(lái)說(shuō)是一個(gè)新的語(yǔ)言特性,本文給大家介紹js的閉包,原型,和匿名函數(shù)之旅,感興趣的朋友一起學(xué)習(xí)吧2015-10-10JavaScript對(duì)象的四種創(chuàng)建方法
這篇文章主要介紹了JavaScript對(duì)象的四種創(chuàng)建方法,首先我們通過(guò)確定一個(gè)對(duì)象的屬性和方法展開主題相關(guān)內(nèi)容,需要的小伙伴可以參考一下2022-08-08JavaScript實(shí)現(xiàn)淺拷貝與深拷貝的方法分析
這篇文章主要介紹了JavaScript實(shí)現(xiàn)淺拷貝與深拷貝的方法,結(jié)合實(shí)例形式總結(jié)分析了JavaScript淺拷貝與深拷貝的定義與使用方法,需要的朋友可以參考下2018-07-07通過(guò)身份證號(hào)得到出生日期和性別的js代碼
主要是通過(guò)判斷指定位數(shù)的數(shù)字,來(lái)判斷并加以算法實(shí)現(xiàn)男女性別的判斷。2009-11-11