码迷,mamicode.com
首页 > 微信 > 详细

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

时间:2021-06-28 20:21:21      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:cal   idc   tps   小程序   open   ports   page   sync   ini   

识别银行卡云函数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)
      },
      })
      },
        


})

 

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

标签:cal   idc   tps   小程序   open   ports   page   sync   ini   

原文地址:https://www.cnblogs.com/heilang/p/14941938.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!