uniapp调用微信小程序人脸识别步骤
·
template
<uni-card class="login-card" :is-shadow="true">
<uni-easyinput class="user-input readonly-style-ignore disabled-style-ignore" type="text" v-model="username" placeholder="请输入姓名">
</uni-easyinput>
<uni-easyinput class="pass-input marBottom" type="text" v-model="identityNum"
placeholder="请输入身份证号">
</uni-easyinput>
<uni-easyinput class="pass-input" type="text" v-model="mobile"
placeholder="请输入手机号">
</uni-easyinput>
<view class="login-btn" @tap="faceLogin">开始人脸识别验证</view>
</uni-card>
script
data() {
return {
username: "",//用户姓名
mobile: "",//手机号
identityNum:"",//身份证号码
}
},
methods: {
faceLogin() {
let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
let regPhone = /^1[3456789]\d{9}$/;
const self = this
if (self.username.length === 0) {
return self.$common.msg('请您输入姓名');
}
if (self.identityNum.length === 0) {
return self.$common.msg('请您输入身份证号码');
}else if(!reg.test(self.identityNum)){
return self.$common.msg('请您输入正确的身份证号码');
}
if (self.mobile.length === 0) {
return self.$common.msg('请您输入手机号码');
}else if(regPhone.test(!self.mobile)){
return self.$common.msg('请您输入正确的手机号码');
}
if (!self.isChecked){
return self.$common.msg('请认真阅读《用户协议》以及《隐私协议》');
}
wx.startFacialRecognitionVerify({//小程序获取验证结果
name:self.username,//用户名称
idCardNumber:self.identityNum,//身份证号码
success(res){
if(res.errMsg == 'startFacialRecognitionVerify:ok'){
self.key = res.verifyResult;
console.log(res,'人脸识别结果:success');
uni.removeStorageSync('token');
uni.removeStorageSync('userInfo');
self.$common.login({
url: '/app/sys/naturalLogin',
data: {
username: self.username,//用户姓名
mobile: self.mobile,//手机号
identityNum: self.identityNum,//身份证号码
key: res.verifyResult //小程序验证码
},
success(data) {
console.log(data,'登录信息888',self.key);
if (data.code === 200) {
// 存储返回的token
uni.setStorageSync('token', data.data.token);
uni.setStorageSync('userInfo', data.data.userInfo);
//跳转首页
setTimeout(() => {
uni.reLaunch({
url: '/pagesC/index/index'
})
}, 500)
} else {
return self.$common.msg(data.message);
}
}
})
}
},fail(res){
console.log(res,'人脸识别结果:fail')
}
})
}
}
干货
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)