roose 4 năm trước cách đây
mục cha
commit
51ae276da5
2 tập tin đã thay đổi với 89 bổ sung68 xóa
  1. 86 66
      pages/finishInfo/finishInfo.js
  2. 3 2
      pages/idCard/idCard.wxml

+ 86 - 66
pages/finishInfo/finishInfo.js

@@ -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({

+ 3 - 2
pages/idCard/idCard.wxml

@@ -1,8 +1,9 @@
+<wxs module="urls" src="../../utils/photoUrl.wxs"></wxs>
 <view class="home">
 	<view class="title1">上传照片</view>
 	<view class="title2">生成专属身份卡</view>
 	<image wx:if="{{isTrue}}" src="/images/caream.png" style="width:350rpx;height:350rpx" bindtap="goPhoto"></image>
-	<image wx:else class="image" style="width:350rpx;height:350rpx" src="http://info.windd.cn:8080/test{{imgPath}}" mode='scaleToFill' bindtap="previewImg"></image>
+	<image wx:else class="image" style="width:350rpx;height:350rpx" src="{{urls.url(imgPath)}}" mode='scaleToFill' bindtap="previewImg"></image>
 	<van-icon wx:if="{{!isTrue}}" size='23' name="clear" class="close" data-index="{{index}}" bindtap="closeImage" />
-	<view  class="btn" bindtap="goShenFen">立即生成</view>
+	<view class="btn" bindtap="goShenFen">立即生成</view>
 </view>