|
@@ -84,76 +84,96 @@ Page({
|
|
|
],
|
|
|
},
|
|
|
goOcr() {
|
|
|
- wx.showLoading({
|
|
|
- title: '加载中',
|
|
|
- })
|
|
|
- var _this = this;
|
|
|
- wx.chooseImage({
|
|
|
- count: 1, // 默认9
|
|
|
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
|
- sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
|
- success: function (res) {
|
|
|
- // console.log('拍照获取图片路径',res);
|
|
|
- // 读取本地文件内容
|
|
|
- wx.showLoading({
|
|
|
- title: '加载中',
|
|
|
- })
|
|
|
- wx.getFileSystemManager().readFile({
|
|
|
- filePath: res.tempFilePaths[0],
|
|
|
- encoding: 'base64',
|
|
|
- success: res => {
|
|
|
- //返回临时文件路径
|
|
|
- // console.log('读取本地文件basema ',res.data)
|
|
|
- let img = 'data:image/png;base64,' + res.data
|
|
|
- const bodys = {
|
|
|
- "base64Str": img
|
|
|
- };
|
|
|
- const AppCode = '4638ef02c8e248e1b12d55b1170e4feb';
|
|
|
- // console.log('读取本地文件basema ',res.data)
|
|
|
- // console.log(JSON.stringify( {base64Str:res.data}))
|
|
|
- wx.request({
|
|
|
- url: 'https://zid.market.alicloudapi.com/thirdnode/ImageAI/idcardfrontrecongnition',
|
|
|
- method: 'POST',
|
|
|
- header: {
|
|
|
- Authorization: 'APPCODE ' + AppCode,
|
|
|
- 'content-type': 'application/x-www-form-urlencoded'
|
|
|
- },
|
|
|
- data: {
|
|
|
- base64Str: img
|
|
|
- },
|
|
|
- dataType: 'json',
|
|
|
- success: (e) => {
|
|
|
- // console.log('身份证ocr识别返回数据',e.data)
|
|
|
- if (e.data.error_code == 0) {
|
|
|
- if (e.data.result) {
|
|
|
- const idcardno = e.data.result.idcardno
|
|
|
- const name = e.data.result.name
|
|
|
- }
|
|
|
- } else {
|
|
|
- wx.hideLoading();
|
|
|
- _this.setData({
|
|
|
- show: false,
|
|
|
- buttonShow: false,
|
|
|
- idButtonShow: true
|
|
|
- });
|
|
|
- wx.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '身份证OCR识别失败',
|
|
|
- })
|
|
|
- }
|
|
|
+ wx.request({
|
|
|
+ url: app.globalData.publicUrl + '/applet/getToken',
|
|
|
+ method: "GET",
|
|
|
+ header: {
|
|
|
+ appletsId: wx.getStorageSync('openId')
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res.data, "0000");
|
|
|
+ if (res.data.data.status == 200) {
|
|
|
+ let token = res.data.data.token;
|
|
|
+ if (token) {
|
|
|
+ wx.showLoading({
|
|
|
+ title: '加载中',
|
|
|
+ })
|
|
|
+ var _this = this;
|
|
|
+ wx.chooseImage({
|
|
|
+ count: 1, // 默认9
|
|
|
+ sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
|
+ sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
|
+ success: function (res) {
|
|
|
+ // console.log('拍照获取图片路径',res);
|
|
|
+ // 读取本地文件内容
|
|
|
+ wx.showLoading({
|
|
|
+ title: '加载中',
|
|
|
+ })
|
|
|
+ wx.getFileSystemManager().readFile({
|
|
|
+ filePath: res.tempFilePaths[0],
|
|
|
+ encoding: 'base64',
|
|
|
+ success: res1 => {
|
|
|
+ //返回临时文件路径
|
|
|
+ console.log('读取本地文件basema ', res1.data)
|
|
|
+ let img = 'data:image/png;base64,' + res1.data
|
|
|
+ wx.request({
|
|
|
+ url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=' + token,
|
|
|
+ method: 'POST',
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/x-www-form-urlencoded'
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ id_card_side: 'front',
|
|
|
+ image: img
|
|
|
+ },
|
|
|
+ dataType: 'json',
|
|
|
+ success: (e) => {
|
|
|
+ if (e.data.idcard_number_type == 1) {
|
|
|
+ let result = e.data.words_result
|
|
|
+ console.log(result, "00000000");
|
|
|
+ _this.data.parameter.forEach(item => {
|
|
|
+ if (item.name == result['性别'].words) {
|
|
|
+ item.checked = true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ result['性别'].words,
|
|
|
+ _this.setData({
|
|
|
+ userName: result['姓名'].words,
|
|
|
+ idCardNumber: result['公民身份号码'].words,
|
|
|
+ parameter: _this.data.parameter,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: "身份证OCR识别失败",
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ complete: (e) => {
|
|
|
+ wx.hideLoading();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 错误信息
|
|
|
+ fail: console.error
|
|
|
+ })
|
|
|
},
|
|
|
+ fail: function () {
|
|
|
+ wx.hideLoading();
|
|
|
+ }
|
|
|
+
|
|
|
})
|
|
|
- },
|
|
|
- // 错误信息
|
|
|
- fail: console.error
|
|
|
- })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: '身份证识别失败,token失效',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
- fail: function () {
|
|
|
- wx.hideLoading();
|
|
|
- }
|
|
|
-
|
|
|
})
|
|
|
-
|
|
|
},
|
|
|
postListChange: function (e) {
|
|
|
this.setData({
|