微信小程序中如何识别银行卡和身份证

时间:2021-06-28 20:21:21   收藏:0   阅读:0

识别银行卡云函数card2/index.js:

const cloud = require(wx-server-sdk)
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV,
})
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.ocr.bankcard({ //识别银行卡
"type": photo,
"imgUrl": event.imgCard2
})
return result
} catch (err) {
return err
}
}

识别身份证云函数card1/index.js:

const cloud = require(wx-server-sdk)
cloud.init({
})
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.ocr.idcard({
"type": photo,
"imgUrl": event.imgCard
})
console.log(result)
return result
} catch (err) {
return err
}
}

shibie.wxml:

<button bindtap="shibie2">识别银行卡</button>
<text>银行卡号是:{{number}}</text>

<button bindtap="shibie">识别身份证</button>
<view>姓名是:{{name}}</view>
<view>身份证号是:{{id}}</view>
<view>性别是:{{gender}}</view>

shibie.js

Page({
  shibie2(){ //识别银行卡
    var that=this
    wx.cloud.callFunction({
    name:"card2",
    data:{
    imgCard2:"https://6a69-jizhaoliang-2gscmw0o879d5385-1305877130.tcb.qcloud.la/%E9%93%B6%E8%A1%8C%E5%8D%A1.jpg?sign=71270da3612790663bf818d02ee3f994&t=1624794493"
    },
    success(res){
    console.log("识别成功",res)
    that.setData({
    number:res.result.number
    })
    },
    fail(res){
    console.log("识别失败",res)
    },
    })
    },
  
    shibie(){ //识别身份证
      var that=this
      wx.cloud.callFunction({
      name:"card1",
      data:{
      imgCard:"https://6a69-jizhaoliang-2gscmw0o879d5385-1305877130.tcb.qcloud.la/%E8%BA%AB%E4%BB%BD%E8%AF%81.jpg?sign=2fa017e88a2bd0e96f18a0655c8034a6&t=1624794751"
      },
      success(res){
      console.log("识别成功",res)
      that.setData({
      name:res.result.name,
      id:res.result.id,
      gender:res.result.gender
      })
      },
      fail(res){
      console.log("识别失败",res)
      },
      })
      },
        


})

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!