<!-- 證件識別 -->
<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>
uniapp實(shí)現(xiàn)身份證實(shí)名認(rèn)證(獲取身份證信息)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來启搂,“玉大人硼控,你說我怎么就攤上這事「於模” “怎么了牢撼?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長疑苫。 經(jīng)常有香客問我熏版,道長,這世上最難降的妖魔是什么捍掺? 我笑而不...
- 正文 為了忘掉前任撼短,我火速辦了婚禮,結(jié)果婚禮上挺勿,老公的妹妹穿的比我還像新娘曲横。我一直安慰自己,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開白布禾嫉。 她就那樣靜靜地躺著灾杰,像睡著了一般。 火紅的嫁衣襯著肌膚如雪熙参。 梳的紋絲不亂的頭發(fā)上艳吠,一...
- 文/蒼蘭香墨 我猛地睜開眼膀捷,長吁一口氣:“原來是場噩夢啊……” “哼迈嘹!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起全庸,我...
- 序言:老撾萬榮一對情侶失蹤秀仲,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后壶笼,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體神僵,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年覆劈,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了保礼。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站白筹,受9級特大地震影響智末,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜徒河,卻給世界環(huán)境...
- 文/蒙蒙 一系馆、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧顽照,春花似錦它呀、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽下隧。三九已至,卻和暖如春谓媒,著一層夾襖步出監(jiān)牢的瞬間淆院,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓抢野,卻偏偏與公主長得像拷淘,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子指孤,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 表情是什么启涯,我認(rèn)為表情就是表現(xiàn)出來的情緒。表情可以傳達(dá)很多信息恃轩。高興了當(dāng)然就笑了结洼,難過就哭了。兩者是相互影響密不可...
- 16宿命:用概率思維提高你的勝算 以前的我是風(fēng)險(xiǎn)厭惡者叉跛,不喜歡去冒險(xiǎn)松忍,但是人生放棄了冒險(xiǎn),也就放棄了無數(shù)的可能筷厘。 ...