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 style="width: 70%;">
<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="action sub-title">
<text class="text-xl text-bold text-blue text-shadow">識別內(nèi)容核對</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">拍攝時(shí)確保身份證</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()">提交認(rèn)證信息</view>
<view class="submitBtn" @click="getIDCard()">提交認(rèn)證</view>
</view>
</view>
</template>
<script>
var that;
const card = uni.requireNativePlugin('DC-CardRecognize');
export default {
data() {
return {
list: [
'隱私說明:請按要求上傳真實(shí)的證件照片元咙,您所上傳的行駛證僅用于平臺賬戶綁定,請放心上傳'
],
// ../static/me/zjx_me_bg6.jpg
imgUrl1: '',
imgUrl2: '',
info: "",
title: 'input',
focus: false,
// 姓名
name: "",
names: "",
// 民族
nationality: "",
// 地址
address: "",
// 身份證號碼
IdNumbers: "",
IdNumber: "",
date: "",
sex: "",
src: "",
httpUrl: "https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=",
imageBase64Str: "",
access_token: "",
APIKey: "",// 你的APIKey
SecretKey: ""http:// 你的SecretKey
}
},
watch: {
},
onReady() {
// 獲取屏幕高度
uni.getSystemInfo({
success: res => {
console.log(res.windowHeight)
}
});
},
onLoad() {
that = this;
//token驗(yàn)證
this.getAccess_token();
},
mounted() {
},
methods: {
getAccess_token() {
var that = this
var accessToken = that.cache("accessToken", null, null);
console.log(accessToken)
if (!accessToken) {
uni.request({
method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
url: "https://aip.baidubce.com/oauth/2.0/token",
data: {
grant_type: "client_credentials",
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;
}
},
//緩存,默認(rèn)有效期28天
cache: function(key, value, seconds) {
var timestamp = Date.parse(new Date()) / 1000
console.log(timestamp + "===" + key)
if (key && value === null) {
//刪除緩存
//獲取緩存
var val = uni.getStorageSync(key);
var tmp = val.split("|")
if (!tmp[1] || timestamp >= tmp[1]) {
console.log("key已失效")
uni.removeStorageSync(key)
return ""
} else {
console.log("key未失效")
return tmp[0]
}
} else if (key && value) {
//設(shè)置緩存
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: "識別中浆西,請等待"
});
uni.request({
url: "https://aip.baidubce.com/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 = res.tempFilePaths[0];
me.tempFile = tempFilePath;
plus.io.resolveLocalFileSystemURL(me.tempFile, function(entry) {
entry.file(function(file) {
var fileReader = new plus.io.FileReader();
fileReader.readAsDataURL(file);
fileReader.onloadend = function(evt) {
//console.log("=="+evt.target.result);
that.imageBase64Str = evt.target.result.split(",")[1];
that.src = evt.target.result;
}
})
})
}
})
}
}
}
</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;
.imgUrl {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
.imgBox {
width: 100%;
height: 100%;
position: relative;
}
.imgEx1 {
background: url(../../static/discern/ex1.png);
background-size: 82%;
background-repeat: no-repeat;
background-position: center;
}
.imgEx2 {
background: url(../../static/discern/ex2.png);
background-size: 82%;
background-repeat: no-repeat;
background-position: center;
}
.leftTop {
height: 28rpx;
width: 4rpx;
background-color: #007aec;
position: absolute;
left: 0;
}
.leftTop2 {
height: 4rpx;
width: 28rpx;
background-color: #007aec;
position: absolute;
top: 0;
}
.leftbottom {
height: 28rpx;
width: 4rpx;
background-color: #007aec;
position: absolute;
bottom: 0;
}
.leftbottom2 {
height: 4rpx;
width: 28rpx;
background-color: #007aec;
position: absolute;
bottom: 0;
}
.rightTop {
height: 28rpx;
width: 4rpx;
background-color: #007aec;
position: absolute;
right: 0;
}
.rightTop2 {
height: 4rpx;
width: 28rpx;
background-color: #007aec;
position: absolute;
right: 0;
top: 0;
}
.rightbottom {
height: 28rpx;
width: 4rpx;
background-color: #007aec;
position: absolute;
right: 0;
bottom: 0;
}
.rightbottom2 {
height: 4rpx;
width: 28rpx;
background-color: #007aec;
position: absolute;
right: 0;
bottom: 0;
}
}
}
.distinguishBox {
padding: 5rpx 30rpx 20rpx;
background: white;
view {
margin-bottom: 20rpx;
}
}
.disLabel {
text-align-last: justify;
text-align: justify;
text-justify: distribute-all-lines;
min-width: 142rpx;
display: inline-block;
margin-right: 5rpx;
}
.requirement {
padding: 10rpx 30rpx 26rpx;
background: white;
view {
margin-bottom: 10rpx;
}
.errorBox {
display: flex;
justify-content: space-between;
margin-top: 30rpx;
view {
width: 23%;
height: 100rpx;
}
.item1 {
background-image: url(../../static/discern/yes.png);
background-repeat: no-repeat;
background-size: 100%;
position: relative;
}
.item2 {
background-image: url(../../static/discern/error1.png);
background-repeat: no-repeat;
background-size: 100%;
position: relative;
}
.item3 {
background-image: url(../../static/discern/error2.png);
background-repeat: no-repeat;
background-size: 100%;
position: relative;
}
.item4 {
background-image: url(../../static/discern/error3.png);
background-repeat: no-repeat;
background-size: 100%;
position: relative;
}
.iconImg {
width: 60rpx;
position: absolute;
bottom: -10px;
left: 50%;
margin-left: -30rpx;
}
}
}
.submitBtn {
width: 90%;
height: 90rpx;
background: #007aec;
line-height: 90rpx;
margin: 50rpx auto;
text-align: center;
font-size: 34rpx;
color: #fff;
border-radius: 12rpx;
}
</style>