微信小程序调用云函数,实现OCR银行卡识别成功拿不到银行卡number,很疑惑?
发布于 5 年前 作者 fangjia 14948 次浏览 来自 问答
 //选择图片
  chooseImage: function(callBack{
    let self = this;
    let type = "yinhangka"
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['camera''album'],
      success: function(res{
        let tempFilePath = res.tempFilePaths[0]
        let imgUrl = tempFilePath
        self.uploadImg(type,imgUrl)
        network.uploadFile(tempFilePath).then(res => {
          if (typeof callBack === 'function')
            callBack({
              tempFilePath,
              fjid: res.data.data.fjid
            })
        })
      }
    })
  },
/* 修改开始 */
  // 上传图片到云存储
  uploadImg(type, imgUrl) {
    let that = this
    wx.cloud.uploadFile({
      cloudPath: 'add/' + type + '.png',
      filePath: imgUrl, // 文件路径
      success: res => {
        console.log("上传成功", res.fileID)
        that.getImgUrl(type, res.fileID)
      },
      fail: err => {
        console.log("上传失败", err)
      }
    })
  },
  
  //获取云存储里的图片url
  getImgUrl(type, imgUrl) {
    let that = this
    wx.cloud.getTempFileURL({
      fileList: [imgUrl],
      success: res => {
      let imgUrl = res.fileList[0].tempFileURL
      console.log("获取图片url成功", imgUrl)
      that.shibie(type, imgUrl)
    },
      fail: err => {
        console.log("获取图片url失败", err)
      }
    })
  },
  
  //调用云函数,实现OCR识别
  shibie(type, imgUrl) {
    wx.cloud.callFunction({
      name: "add",
      data: {
        typetype,
        imgUrl: imgUrl
      },
      success(res) {
        console.log("识别成功", res)
      },
      fail(res) {
        console.log("识别失败", res)
      }
    })
  },

  //上传图片
  uploadCard: function(e{
    this.chooseImage(res => {
      var item = this.data.item
      item.src = res.tempFilePath
      this.setData({
        item: item
      })
      this.data.clxxItem = {
        fjid: res.fjid,
        cllx: item.cllx
      }
    })
  },

已经是成功调用了OCR的银行卡方法,就是拿不到number,这个是为什么呢,网上帖子发出来都有个number的:网上帖子截图如下

希望有大神帮忙解答下

1 回复

你云函数没重新上传吧,你这个返回结果,是云函数模板的返回值,没必要犯这种错误吧

回到顶部