当前位置:网站首页>Using nodejs and Tencent cloud API to identify invoices

Using nodejs and Tencent cloud API to identify invoices

2022-06-23 22:16:00 Swing a knife North

It's the end of the year again , It's really hard to collect invoices , I am a thrifty person , Where did you get so many invoices , But a friend gave me a compressed package , Open it up , I drop a mother ,200 Multiple invoices , Taxi invoice , Accounting requires that each invoice be renamed , The naming rule is invoice code - Invoice number - amount of money - full name , This is killing me , If you don't blind one by one , I have to be tired to death , But I am a chicken programmer , Vegetable chicken must think of using programs to complete repetitive work , The first thought is how to identify invoices , Here I have come up with two solutions , The first one is to use various cloud services to realize , After reviewing various cloud services , Discover that Tencent's cloud service identification invoice function supports nodejs, So we simply used Tencent cloud , This is his demo site :

https://cloud.tencent.com/act/event/ocrdemo The page is as follows , Click to start using , Opening service :

And then apply for a couple SecretId and SecretKey:

The entrance is :https://console.cloud.tencent.com/cam/capi

preservation secretID and secretKey.

Then open the interface test website :https://console.cloud.tencent.com/api/explorer?Product=cvm&Version=2017-03-12&Action=DescribeZones&SignVersion= Pictured :

Then initialize the local project , install sdk package

npm install tencentcloud-sdk-nodejsnpm

The entry file code is as follows :

// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const tencentcloud = require("tencentcloud-sdk-nodejs");
const OcrClient = tencentcloud.ocr.v20181119.Client;
const fs = require('fs');
const path = require('path');
let pdfBase64 = fs.readFileSync('./pdf2/012002100311-54213119-39.9- Chen Liming .pdf',{encoding:'base64'});
// console.log(pdfBase64)

const clientConfig = {
  credential: {
    secretId: " Yours secretId",
    secretKey: " Yours secretKey",
  },
  region: "ap-beijing",
  profile: {
    httpProfile: {
      endpoint: "ocr.tencentcloudapi.com",
    },
  },
};

const client = new OcrClient(clientConfig);
const params = {
    "ImageBase64": pdfBase64,
    "IsPdf": true,
    "PdfPageNumber": 1
};
client.VatInvoiceOCR(params).then(
  (data) => {
    console.log(data);
  },
  (err) => {
    console.error("error", err);
  }
);

In the code, my subordinates read a pdf file , This document is an invoice :

Execute the code to read the contents of the invoice , as follows :

{
  Angle: 0,
  Items: [
    {
      AmountWithoutTax: '54.95',
      LineNo: '1',
      Name: '* Meat and meat products *betterme Fried chicken steak with black pepper in honey sauce 700g Healthy light food fitness chicken breast fitness meal fitness food low fat substitute meal low fat ',
      Quantity: '1',
      Spec: ' Fried chicken with honey sauce and black pepper flavor ',
      TaxAmount: '4.95',
      TaxRate: '9%',
      Unit: ' bag ',
      UnitPrice: '54.95'
    },
    {
      AmountWithoutTax: '-18.35',
      LineNo: '2',
      Name: '* Meat and meat products *betterme Fried chicken steak with black pepper in honey sauce 700g Healthy light food fitness chicken breast fitness meal fitness food low fat substitute meal low fat ',
      Quantity: '',
      Spec: '',
      TaxAmount: '-1.65',
      TaxRate: '9%',
      Unit: '',
      UnitPrice: ''
    }
  ],
  PdfPageSize: 1,
  RequestId: '7309a02f-3120-441f-afb8-1594a25ac0f7',
  VatInvoiceInfos: [
    { Name: ' Invoice code ', Polygon: [Object], Value: '012002100311' },
    { Name: ' Invoice name ', Polygon: [Object], Value: ' Tianjin VAT electronic ordinary invoice ' },
    { Name: ' Invoice number ', Polygon: [Object], Value: 'No54213119' },
    { Name: ' Invoice date ', Polygon: [Object], Value: '2021 year 12 month 10 Japan ' },
    { Name: ' Machine number ', Polygon: [Object], Value: '661911908106' },
    { Name: ' Check code ', Polygon: [Object], Value: '69982725101317621468' },
    { Name: ' Name of purchaser ', Polygon: [Object], Value: ' Beijing Huayi Innovation Information Technology Co., Ltd ' },
    {
      Name: ' Password area 1',
      Polygon: [Object],
      Value: '/8*5<56/*19<8*/23>-/4/72+81'
    },
    { Name: ' Purchaser identification number ', Polygon: [Object], Value: '91110108749364121L' },
    {
      Name: ' Password area 2',
      Polygon: [Object],
      Value: '1<51<34<8*554-5-*83+>74<606'
    },
    {
      Name: ' Password area 3',
      Polygon: [Object],
      Value: '456<>*10*40*26838*443/+59<7'
    },
    {
      Name: ' Password area 4',
      Polygon: [Object],
      Value: '2><30*73<3379*952+4-4*2*601'
    },
    {
      Name: ' Goods or taxable services 、 The service name ',
      Polygon: [Object],
      Value: '* Meat and meat products *betterme Fried chicken steak with black pepper in honey sauce 700g Healthy light food fitness chicken breast fitness meal fitness food low fat substitute meal low fat '
    },
    { Name: ' Specifications and models ', Polygon: [Object], Value: ' Fried chicken with honey sauce and black pepper flavor ' },
    { Name: ' Company ', Polygon: [Object], Value: ' bag ' },
    { Name: ' Number ', Polygon: [Object], Value: '1' },
    { Name: ' The unit price ', Polygon: [Object], Value: '54.95' },
    { Name: ' amount of money ', Polygon: [Object], Value: '54.95' },
    { Name: ' tax rate ', Polygon: [Object], Value: '9%' },
    { Name: ' Tax amount ', Polygon: [Object], Value: '4.95' },
    {
      Name: ' Goods or taxable services 、 The service name ',
      Polygon: [Object],
      Value: '* Meat and meat products *betterme Fried chicken steak with black pepper in honey sauce 700g Healthy light food fitness chicken breast fitness meal fitness food low fat substitute meal low fat '
    },
    { Name: ' amount of money ', Polygon: [Object], Value: '-18.35' },
    { Name: ' tax rate ', Polygon: [Object], Value: '9%' },
    { Name: ' Tax amount ', Polygon: [Object], Value: '-1.65' },
    { Name: ' Total amount ', Polygon: [Object], Value: '¥36.60' },
    { Name: ' Total tax amount ', Polygon: [Object], Value: '¥3.30' },
    { Name: ' Total price and tax ( Capitalization )', Polygon: [Object], Value: ' Thirty nine yuan and ninety Jiao ' },
    { Name: ' Amount in figures ', Polygon: [Object], Value: '¥39.90' },
    { Name: ' Name of seller ', Polygon: [Object], Value: ' Tianjin Jingdong Daye Trading Co., Ltd ' },
    { Name: ' remarks ', Polygon: [Object], Value: ' The order number :234161485025' },
    { Name: ' Seller identification number ', Polygon: [Object], Value: '91120110MA06J3WLX8' },
    {
      Name: ' Seller's address 、 Telephone ',
      Polygon: [Object],
      Value: ' Huafeng Road, Huaming high tech Industrial Zone, Dongli District, Tianjin 6 Number A2 seat 4 floor 101 room 022-26629111'
    },
    {
      Name: ' Account opening bank and account number of the seller ',
      Polygon: [Object],
      Value: ' Bank of China Limited Tianjin Binhai city square sub branch 280487613780'
    },
    { Name: ' payee ', Polygon: [Object], Value: ' Wang Lu ' },
    { Name: ' To review ', Polygon: [Object], Value: ' Lee thought ' },
    { Name: ' Drawer ', Polygon: [Object], Value: ' Wang Mei ' },
    { Name: ' province ', Polygon: null, Value: ' tianjin ' },
    { Name: ' Is there a company seal ', Polygon: null, Value: '1' },
    { Name: ' Invoice type ', Polygon: null, Value: ' VAT electronic invoice ' },
    { Name: ' Invoice consumption type ', Polygon: null, Value: ' service ' },
    { Name: ' Service type ', Polygon: null, Value: '' },
    { Name: ' Buyer's address 、 Telephone ', Polygon: null, Value: '' },
    { Name: ' Buyer's Bank of deposit and account number ', Polygon: null, Value: '' },
    { Name: ' Print Invoice Code ', Polygon: null, Value: '' },
    { Name: ' Print invoice number ', Polygon: null, Value: '' },
    { Name: ' Joint times ', Polygon: null, Value: '' },
    { Name: ' Whether to substitute ', Polygon: null, Value: '' },
    { Name: ' Product oil mark ', Polygon: null, Value: '' },
    { Name: ' City ', Polygon: null, Value: '' },
    { Name: ' Toll sign ', Polygon: null, Value: '' },
    { Name: ' The date of passage ends ', Polygon: null, Value: '' },
    { Name: ' From the date of passage ', Polygon: null, Value: '' },
    { Name: ' Vehicle and vessel tax ', Polygon: null, Value: '' },
    { Name: ' license plate number ', Polygon: null, Value: '' },
    { Name: ' type ', Polygon: null, Value: '' }
  ]
}

Tencent cloud gives away free resources ,

What needs to be noted here is , You need to change the payment mode to post payment :

Post payment settings ( It can only be changed once a month , The next day after the change 0 Point effective ) You have opened the post payment mode , When your resource package is exhausted, the additional calls will be paid later , Automatic monthly settlement . View the resource package stock .

The above is to experience the VAT invoice function of Tencent cloud character recognition , I hope it helped you .

原网站

版权声明
本文为[Swing a knife North]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112161355077157.html