uniapp实现身份证实名认证(获取身份证信息)

证件识别uniapp实现⾝份证实名认证(获取⾝份证信息)
image.png
<!-- 证件识别 -->
<template>
<view>
<view class="container">
<view class="cu-bar bg-white margin-top-xs">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">请拍摄并上传您的⾝份证照⽚</text>
<text class="text-ABC text-blue">Driving license</text>
</view>
</view>
<view class="uploadBox">
<view >
<view class="uploadItem">
<view class="imgBox imgEx1">
<view class="leftTop"></view>
<view class="leftTop2"></view>
<view class="leftbottom"></view>
<view class="leftbottom2"></view>
<view class="rightTop"></view>
<view class="rightTop2"></view>
<view class="rightbottom"></view>
<view class="rightbottom2"></view>
</view>
<image class="imgUrl" :src="src"></image>
</view>
<view @tap="scan()" class="leftBtn text-white text-lg text-center">拍摄正⾯</view>
</view>
</view>
<view class="cu-bar bg-white margin-top">
<view class="cu-bar bg-white margin-top">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">识别内容核对</text>
<text class="text-ABC text-blue">distinguish</text>
</view>
</view>
<view class="distinguishBox">
<view>
<text class="text-bold disLabel">姓名:</text>
<text>{{names}}</text>
</view>
<view>
<text class="text-bold disLabel">出⽣:</text>
<text>{{date}}</text>
</view>
<view>
<text class="text-bold disLabel">性别:</text>
<text>{{sex}}</text>
</view>
<view>
<text class="text-bold disLabel">民族:</text>
<text>{{nationality}}</text>
</view>
<view>
<text class="text-bold disLabel">居住地:</text>
<text>{{address}}</text>
</view>
<view>
<text class="text-bold disLabel">⾝份证号:</text>
<text>{{IdNumbers}}</text>
</view>
</view>
<view class="cu-bar bg-white margin-top">
<view class="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">拍摄要求须知</text>
<text class="text-ABC text-blue">requirement</text>
</view>
</view>
<view class="requirement">
<view>
<text class="text-gray">请上传⼤陆公民持有的本⼈有效⾝份证;</text>
</view>
<view>
<text class="text-gray">拍摄时确保⾝份证</text>
<text class="text-red">边框完整,</text>
<text class="text-red">字体清晰,</text>
<text class="text-red">亮度均匀;</text>
</view>
<view class="errorBox">
<view class="item1">
<image class="iconImg" src="../../static/discern/ok.png" mode="widthFix"></image>                    </view>
<view class="item2">
<image class="iconImg" src="../../static/discern/no.png" mode="widthFix"></image>                    </view>
<view class="item3">
<image class="iconImg" src="../../static/discern/no.png" mode="widthFix"></image>                    </view>
<view class="item4">
<image class="iconImg" src="../../static/discern/no.png" mode="widthFix"></image>                    </view>
</view>
</view>
<view class="submitBtn" @click="getIDCards()">提交认证信息</view>
<view class="submitBtn" @click="getIDCard()">提交认证</view>
</view>
</view>
</view>
</template>
<script>
var that;
const card = quireNativePlugin('DC-CardRecognize');
export default {
data() {
return {
list: [
'隐私说明:请按要求上传真实的证件照⽚,您所上传的⾏驶证仅⽤于平台账户绑定,请放⼼上传'                ],
// ../static/me/zjx_me_bg6.jpg
imgUrl1: '',
imgUrl2: '',
info: "",
title: 'input',
focus: false,
// 姓名
name: "",
names: "",
// 民族
nationality: "",
// 地址
address: "",
// ⾝份证号码
IdNumbers: "",
IdNumber: "",
date: "",
sex: "",
src: "",
httpUrl: "aip.baidubce/rest/2.0/ocr/v1/general?access_token=",
imageBase64Str: "",
access_token: "",
APIKey: "",// 你的APIKey
SecretKey: ""// 你的SecretKey
}
},
watch: {
},
onReady() {
// 获取屏幕⾼度
success: res => {
console.log(res.windowHeight)
}
});
},
onLoad() {
that = this;
/
/token验证
},
mounted() {
},
methods: {
getAccess_token() {
var that = this
var accessToken = that.cache("accessToken", null, null);
console.log(accessToken)
if (!accessToken) {
method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
url: "aip.baidubce/oauth/2.0/token",
data: {
grant_type: "client_credentials",
client_id: that.APIKey,
client_id: that.APIKey,
client_secret: that.SecretKey
},
success: function(res) {
console.log(res.data.access_token);
//uni.setStorageSync("Baidu",res.data);
that.access_token = res.data.access_token;
that.cache("accessToken", res.data.access_token, null);
}
})
} else {
that.access_token = accessToken;
}
},
//缓存,默认有效期28天
cache: function(key, value, seconds) {
var timestamp = Date.parse(new Date()) / 1000
console.log(timestamp + "===" + key)
if (key && value === null) {
//删除缓存
//获取缓存
var val = StorageSync(key);
var tmp = val.split("|")
if (!tmp[1] || timestamp >= tmp[1]) {
console.log("key已失效")
return ""
} else {
console.log("key未失效")
return tmp[0]
}
} else if (key && value) {
//设置缓存
if (!seconds) {
var expire = timestamp + (3600 * 24 * 28)
} else {
var expire = timestamp + seconds
}
value = value + "|" + expire
uni.setStorageSync(key, value);
} else {
console.log("key不能空")
}
},
getIDCards() {
if (flag) {
console.log("==")
//百度名⽚识别接⼝处理开始
uni.showLoading({
mask: true,
title: "识别中,请等待"
});
url: "aip.baidubce/rest/2.0/ocr/v1/idcard?access_token=" + that.access_token,                        method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
image: that.imageBase64Str,
id_card_side: "front"
},
success: function(res) {
console.log(res);
var IdCard = res.data.words_result.公民⾝份号码.words;
that.IdNumbers = IdCard
var userName = res.data.words_result.姓名.words;
that.names = userName
that.nationality = res.data.words_result.民族.words;
var address = res.data.words_result.住址.words;
that.address = address
var sex = res.data.words_result.性别.words;
that.sex = sex
var date = res.data.words_result.出⽣.words;
that.date = date
},
complete() {
uni.hideLoading();
}
})
}
},
scan() {
var me = this;
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: function(res) {
var tempFilePath = pFilePaths[0];
pFile, function(entry) {                            entry.file(function(file) {
var fileReader = new plus.io.FileReader();
//console.log("=="+sult);
that.imageBase64Str = sult.split(",")[1];
that.src = sult;
}
})
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
.container {
height: 100%;
}
.uploadBox {
padding: 15rpx 20rpx 40rpx;
background-color: #FFFFFF;
display: flex;
justify-content: center;
// justify-content: space-between;
.leftBtn {
width: 100%;
height: 75rpx;
line-height: 75rpx;
background-color: #007aec;
border-radius: 0 0 12rpx 12rpx;
}
.
uploadItem {
width: 100%;
height: 320rpx;
background-color: #f1f7ff;
border-radius: 15rpx;
padding: 30rpx;
position: relative;

本文发布于:2024-09-25 05:31:48,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/3/383698.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:识别   上传   缓存
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议