`import qs from 'qs'
`ocrIdCard(access_token,query={}) {
const headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
return http.post('/baiduOCR/rest/2.0/ocr/v1/idcard?access_token='+access_token , query,{
header:headers
})
},
getOcrAcdessTokean() {
const param = qs.stringify({
'grant_type': 'client_credentials',
'client_id': '看文档',
'client_secret': '看文档'
});
return http.post('/baiduOCR/oauth/2.0/token?' +param)
},
ChooseImage(access_token) {
uni.chooseImage({
count: this.limit,
sizeType: this.sizeType,
sourceType: this.sourceType,
success: (res) => {
this.loding = true
this.imgToBase64(res,access_token);
uni.showLoading({
title: '上传中...'
});
uni.hideLoading();
}
});
},
imgToBase64(data,access_token) {
console.log('1111')
plus.zip.compressImage({
src: data.tempFilePaths[0],
dst: "_doc/a.jpg",
overwrite: true,
width: '1920px',
height: '1080px',
format: 'jpg',
quality: 100
},
(e)=>{
let reader = new plus.io.FileReader();
reader.readAsDataURL(e.target);
reader.onloadend = (e) =>{
let base64 = e.target.result.split(',')[1].replace(/[\r\n]/g, "")
this.OCR(base64,access_token)
};
},
function(err) {
plus.nativeUI.alert('未知错误!', function(){});
}
);
},
OCR(img,access_token){
this.$http.ocrIdCard(access_token, {
image:img,
id_card_side: 'front',
}).then(res => {
const result = res.words_result
if (result) {
this.model.idCard = result['公民身份号码'].words
this.model.name = result['姓名'].words
this.model.nationalName = result['民族'].words
}
console.log(res, 'res++结果--------++++++++++')
}).catch(error => {
console.log(error, 'error++结果--------++++++++++')
})
},