一、准备工作

1、创建云函数identify

二、云函数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.businessLicense({
65 "imgUrl": event.imgUrl
66 })
67 return result
68 } catch (err) {
69 return err
70 }
71 }
72 }

二、创建页面并写相应代码

 创建页面IdentifyBusinessLicense,用于OCR识别营业执照

 1、IdentifyBusinessLicense.wxml

 1 <!-- 识别营业执照信息 -->
2 <button bindtap="IdentifyBusinessLicense" type="primary">识别营业执照</button>
3 <!-- 把识别到的营业执照图片显示到页面上 -->
4 <view class="idcard">
5 <image src="{{IdentifyBusinessLicenseURL}}" ></image>
6 </view>
7 <!-- 把识别到的营业执照信息显示到页面上 -->
8 <view class="front" wx:if="{{showdBusinessLicense}}">
9 <view>【证件标题】:{{BusinessLicenseMsg.title}}</view>
10 <view>【注册编号】:{{BusinessLicenseMsg.regNum}}</view>
11 <view>【企业名称】:{{BusinessLicenseMsg.enterpriseName}}</view>
12 <view>【企业类型】:{{BusinessLicenseMsg.typeOfEnterprise}}</view>
13 <view>【企业住所】:{{BusinessLicenseMsg.address}}</view>
14 <view>【法定代表人】:{{BusinessLicenseMsg.legalRepresentative}}</view>
15 <view>【注册资本】:{{BusinessLicenseMsg.registeredCapital}}</view>
16 <view>【成立日期】:{{BusinessLicenseMsg.registeredDate}}</view>
17 <view>【营业期限】:{{BusinessLicenseMsg.validPeriod}}</view>
18 <view>【经营范围】:{{BusinessLicenseMsg.businessScope}}</view>
19 <view>【外廓尺寸】:{{BusinessLicenseMsg.imgSize.h}}*{{BusinessLicenseMsg.imgSize.w}}</view>
20 </view>

2、IdentifyBusinessLicense.wxss

 1 button{
2 margin: 20rpx;
3 }
4 .front{
5 margin: 20rpx;
6 }
7
8 .idcard{
9 text-align: center;
10 }
11 .idcard image{
12 width: 95%rpx;
13 height: 800rpx;
14 }

3、IdentifyBusinessLicense.js

 1 // pages/IdentifyDriverLicense/IdentifyDriverLicense.js
2 Page({
3 //初始化数据
4 data:{
5 showdBusinessLicense:false,
6 BusinessLicenseMsg:{}
7 },
8
9 //识别驾驶证信息
10 IdentifyBusinessLicense(){
11 //选择图片
12 wx.chooseImage({
13 count: 1,
14 sizeType: ['original', 'compressed'],
15 sourceType: ['album', 'camera'],
16 }).then(res=>{
17 console.log("图片选择成功",res);
18 console.log("所选图片的临时链接",res.tempFilePaths[0]);
19 //上传图片
20 wx.cloud.uploadFile({
21 cloudPath: (new Date()).valueOf()+'.png',
22 filePath: res.tempFilePaths[0],
23 }).then(res=>{
24 console.log("图片上传到云存储成功",res);
25 console.log("图片在云存储里的fileID",res.fileID);
26 //将上传成功的图片显示到页面上
27 this.setData({
28 IdentifyBusinessLicenseURL:res.fileID,
29 })
30 //获取图片真实URL
31 wx.cloud.getTempFileURL({
32 fileList:[res.fileID]
33 }).then(res=>{
34 console.log("获取图片真实链接成功",res);
35 //识别身份证背面信息
36 wx.cloud.callFunction({
37 name:"identify",
38 data:{
39 imgUrl:res.fileList[0].tempFileURL, //传递参数给云函数
40 action:"5" //action为1表示身份证,2表示银行卡,3表示驾驶证,4表示行驶证,5表示营业执照,6表示通用印刷体(在云函数中自定义的)
41 }
42 }).then(res=>{
43 console.log("图片识别成功",res);
44 this.setData({
45 BusinessLicenseMsg:res.result,
46 showdBusinessLicense:true
47 })
48 }).catch(err=>{
49 console.log("图片识别失败",err);
50 })
51 }).catch(err=>{
52 console.log("获取图片真实链接失败",err);
53 })
54 }).catch(err=>{
55 console.log("图片上传到云存储失败",err);
56 })
57
58 }).catch(err=>{
59 console.log("图片选择失败",err);
60 })
61 }
62 })

三、效果展示

微信小程序云开发-云存储的应用-识别营业执照的更多相关文章

  1. 微信小程序+腾讯云直播的实时音视频实战笔记

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  2. 微信小程序腾讯云php后台解决方案

    微信小程序腾讯云php后台解决方案 微信小程序前段需要添加必要的文件以配合后端 (1)wafer2-client-sdk sdk提供了几种接口包括登陆,获取用户openid,图片上传等 (2)conf ...

  3. 微信小程序-视频教程-百度云-下载

    链接: https://pan.baidu.com/s/16WGL3whutozx-UXqsDPhhA 提取码: 关注公众号[GitHubCN]回复获取   什么是微信小程序?小程序是一种不需要下载安 ...

  4. 小程序语音红包开发中 汉字转拼音的问题 微信小程序红包开发遇到的坑

    公司最近在开发微信小程序的红包功能,语音红包需要用到文字转拼音的功能. 之前介绍过怎么将中文的汉字转为拼音的,具体看下面这篇文章. 微信语音红包小程序开发如何提高精准度 红包小程序语音识别精准度 微信 ...

  5. 《微信小程序商城开发实战》笔者的新书,欢迎各位粉丝上京东购买

    作者图书京东链接,请点击------>>>    **微信小程序商城开发实战** 附京东真实评价截图: 编辑推荐 在当今移动互联网大潮中,微信应用凭借其庞大的用户基数和极强的用户黏性 ...

  6. Django微信小程序后台开发教程

    本文链接:https://blog.csdn.net/qq_43467898/article/details/83187698Django微信小程序后台开发教程1 申请小程序,创建hello worl ...

  7. vue+uni-app商城实战 | 第一篇:【有来小店】微信小程序快速开发接入Spring Cloud OAuth2认证中心完成授权登录

    一. 前言 本篇通过实战来讲述如何使用uni-app快速进行商城微信小程序的开发以及小程序如何接入后台Spring Cloud微服务. 有来商城 youlai-mall 项目是一套全栈商城系统,技术栈 ...

  8. 微信小程序快速开发

    微信小程序快速开发 一.注册小程序账号,下载IDE 1.官网注册https://mp.weixin.qq.com/,并下载IDE. 2.官方文档一向都是最好的学习资料. 注意:1)注册账号之后会有一个 ...

  9. 【微信小程序】开发实战 之 「配置项」与「逻辑层」

    微信小程序作为微信生态重要的一环,在实际生活.工作.商业中的应用越来越广泛.想学习微信小程序开发的朋友也越来越多,本文将在小程序框架的基础上就微信小程序项目开发所必需的基础知识及语法特点进行了详细总结 ...

  10. BeautyWe.js 一套专注于微信小程序的开发范式

    摘要: 小程序框架... 作者:JerryC 原文:BeautyWe.js 一套专注于微信小程序的开发范式 Fundebug经授权转载,版权归原作者所有. 官网:beautywejs.com Repo ...

随机推荐

  1. GStreamer 1.0 series序列示例

    GStreamer 1.0 series序列示例 OpenEmbedded layer for GStreamer 1.0 这layer层为GStreamer 1.0框架提供了非官方的支持,用于Ope ...

  2. 记 Ant Designer Vue 2.0.1 layout 丢失样式类名问题分析

    现象 <a-layout-sider /> 渲染到页面上会变成 <section class="undefined-has-sider"> 丢失了 layo ...

  3. 如果攻击者操控了 redirect_uri,会怎样?

    读者在看这篇文章之前,请先了解 Oauth2.0 的 Authorization Code 授权流程,可以看 Authorization Code 授权原理和实现方法 在 Token Enpoint ...

  4. Kubernetes 实战——配置应用(ConfigMap、Secret)

    配置容器化应用的方式:①命令行参数:②环境变量:③文件化配置 一.向容器传递命令行参数或环境变量 这两种方式在 Pod 创建后不可被修改 1. 在Docker中定义命令与参数 ENTRYPOINT:容 ...

  5. pytest命令行参数

    1.-v:可以输出用例更加详细的执行信息,如下图 C:\Users\cale\checkapi\test_cc>pytest test_m1.py -v ==================== ...

  6. 二、特殊DNS解析

    一.DNS轮询 1.为站点 www.tedu.cn 提供DNS轮询解析,三台Web服务器节点的IP地址分别为: 192.168.4.10.192.168.4.20.192.168,4.30 步骤: 虚 ...

  7. 【NX二次开发】属性操作相关函数的使用方法

    内容包括:1.属性创建2.判断属性是否存在3.读取属性值4.时间属性转换成字符串5.统计属性的数量6.删除指定属性7.删除全部属性效果: 源码: #include <stdlib.h> # ...

  8. Java进阶 | Proxy动态代理机制详解

    一.Jvm加载对象 在说Java动态代理之前,还是要说一下Jvm加载对象的过程,这个依旧是理解动态代理的基础性原理: Java类即源代码程序.java类型文件,经过编译器编译之后就被转换成字节代码.c ...

  9. split截取字符串

    一.根据单个分隔字符用split截取字符串:string st="GT123_1";split代码:string[] sArray=st.split("_"); ...

  10. NAT网络地址转换技术

    NAT网络地址转换技术 目录 一.NAT概述 1.1.概述 1.2.NAT 的应用场景 二.NAT的类型及配置命令 2.1.静态NAT 2.2.动态NAT 2.3.Easy IP 2.4.NATP 2 ...