小程序?qū)崿F(xiàn)人臉識別的項目實踐
調(diào)用api wx.startFacialRecognitionVerify
第一步:
// 修改方法
expertUpdate() {
wx.startFacialRecognitionVerify({
name: _this.registerForm.realName, //身份證名稱
idCardNumber: _this.registerForm.idCard, //身份證號碼
checkAliveType: 1, //屏幕閃爍(人臉核驗的交互方式,默認0,讀數(shù)字)
success(res) {
console.log(res) //認證結(jié)果
if(res.errCode == 0){
//識別成功 這個時候可以調(diào)后端的接口 (帶著返的res.verifyResult)
_this.verifyUser(res.verifyResult)
}else{
tipInfo("識別失敗")
}
},
complete(res) {
console.log(res)
},
fail(e) {
console.log("err", err)//失敗處理方法
wx.showToast('請保持光線充足,面部正對手機,且無遮擋')
}
})
}第二步:調(diào)方法 校驗后端的接口
// 人臉識別 根據(jù)上一個方法把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()
//修改成功后 是返回上一步 還是跳轉(zhuǎn)其他頁面 根據(jù)實際情況
} else {
uni.$u.toast(res.msg, 5000)
}
})
console.log(res);
}).catch(error => {
console.log(error);
uni.$u.toast('請先按要求填寫', 5000)
})
}
})
},注釋:完整方法 這個是實現(xiàn)小程序個人信息完善,加了一個判斷,如果 輸入框沒有值則需要走人臉識別驗證方法 如果有值 只是修改其他項 就不需要驗證 修改完成之后 名字和身份證號碼直接禁用
// 修改方法
expertUpdate() {
if (this.fileList1.length == 0) {
uni.$u.toast('請上傳頭像')
return false
}
// 判斷 realName 是否為空
if (!this.infoForm.realName) {
uni.$u.toast('請?zhí)顚懶彰?);
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('請?zhí)顚懮矸葑C號碼');
return false;
}
// 驗證 idCard 是否符合身份證標(biāo)準
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('簡介字數(shù)不能超過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)
})
}
})
},
到此這篇關(guān)于小程序?qū)崿F(xiàn)人臉識別的項目實踐的文章就介紹到這了,更多相關(guān)小程序 人臉識別內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
學(xué)習(xí)javascript的閉包,原型,和匿名函數(shù)之旅
Javascript中有幾個非常重要的語言特性——對象、原型繼承、閉包。其中閉包 對于那些使用傳統(tǒng)靜態(tài)語言C/C++的程序員來說是一個新的語言特性,本文給大家介紹js的閉包,原型,和匿名函數(shù)之旅,感興趣的朋友一起學(xué)習(xí)吧2015-10-10
JavaScript實現(xiàn)淺拷貝與深拷貝的方法分析
這篇文章主要介紹了JavaScript實現(xiàn)淺拷貝與深拷貝的方法,結(jié)合實例形式總結(jié)分析了JavaScript淺拷貝與深拷貝的定義與使用方法,需要的朋友可以參考下2018-07-07

