微信小程序云开发-云存储的应用-识别通用印刷体

1、创建云函数identify

微信小程序云开发-云存储的应用-识别通用印刷体

2、云函数identify中index.js代码

1 // 云函数入口文件 2 const cloud = require('wx-server-sdk') 3 4 //cloud.init() 5 //环境变量初始化 6 cloud.init({ 7 evn:cloud.DYNAMIC_CURRENT_ENV //标志当前所在环境 8 }) 9 10 // 云函数入口函数 11 exports.main = async (event,context) => { 12 const wxContext = cloud.getWXContext() 13 if(event.action=="1"){ //action为1 返回身份证的信息 14 try { 15 const result = await cloud.openapi.ocr.idcard({ 16 "type": 'photo', 17 "imgUrl": event.imgUrl 18 }) 19 return result 20 } catch (err) { 21 return err 22 } 23 }else if(event.action=="2"){ //action为2 返回银行卡的信息 24 try { 25 const result = await cloud.openapi.ocr.bankcard({ 26 "type": 'photo', 27 "imgUrl": event.imgUrl 28 }) 29 return result 30 } catch (err) { 31 return err 32 } 33 }else if(event.action=="3"){ //action为3 返回驾驶证的信息 34 try { 35 const result = await cloud.openapi.ocr.driverLicense({ 36 "type": 'photo', 37 "imgUrl": event.imgUrl 38 }) 39 return result 40 } catch (err) { 41 return err 42 } 43 }else if(event.action=="4"){ //action为4 返回行驶证的信息 44 try { 45 const result = await cloud.openapi.ocr.vehicleLicense({ 46 "type": 'photo', 47 "imgUrl": event.imgUrl 48 }) 49 return result 50 } catch (err) { 51 return err 52 } 53 }else if(event.action=="5"){ //action为5 返回营业执照的信息 54 try { 55 const result = await cloud.openapi.ocr.businessLicense({ 56 "imgUrl": event.imgUrl 57 }) 58 return result 59 } catch (err) { 60 return err 61 } 62 }else if(event.action=="6"){ //action为6 返回通用印刷体的信息 63 try { 64 const result = await cloud.openapi.ocr.printedText({ 65 "imgUrl": event.imgUrl 66 }) 67 return result 68 } catch (err) { 69 return err 70 } 71 } 72 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zysfzs.html