更新时间:2024-01-11 gmt 08:00

增值税发票识别-凯发k8国际娱乐官网入口

功能介绍

识别增值税发票的类别,并以json格式返回识别的结构化结果,支持识别图片、pdf、ofd文件。该接口的使用限制请参见约束与限制,详细使用指导请参见ocr服务使用简介章节。

发票验真api请参见。

图1 增值税发票示例图
图2 区块链发票示例图
图3 全电发票示例图

对于区块链发票与增值税电子普票的区别参考如下:

  • 一般电子普通发票除了地名,均标明“增值税电子普通发票”,区块链发票除了地名外只标明“电子普通发票”。
  • 增值税电子普通发票一般有机器编码。
  • 校验码数位不一样,增值税电子普通发票校验码是由20位阿拉伯数字组成 ;区块链发票校验码5位数字或英文字母与阿拉伯数字组合。
  • 增值税发票仅限于中华人民共和国境内使用的增值税发票
  • 支持的增值税发票包括:增值税专用发票、增值税普通发票、增值税电子专用发票、增值税电子普通发票(含通行费发票、区块链发票)、增值税普通发票(卷票)、全电发票。

约束与限制

  • 支持jpeg、jpg、png、bmp、tiff、pdf、ofd格式,多页pdf默认识别第一页,或者您可以指定要识别的页码。
  • 图像各边的像素大小在100px到8192px之间。
  • 图像中发票区域有效占比超过80%。
  • 支持图像中增值税发票任意角度的水平旋转。
  • 图片中发票宽高比例与真实发票比例一致。
  • 支持增值税专用发票、全电发票和增值税普通发票(含电子普通发票),包括增值税普通发票中的卷式发票、通行费发票。
  • 文字识别服务属于公有云服务,线上用户资源共享,如果需要多并发请求,请提前。

调用方法

请参见。

前提条件

在使用之前,需要您完成服务申请和认证鉴权,具体操作流程请参见开通服务和章节。

用户首次使用需要先。服务只需要开通一次即可,后面使用时无需再次申请。如未开通服务,调用服务时会提示modelarts.4204报错,请在调用服务前先进入控制台开通服务,并注意开通服务区域与调用服务的区域保持一致。

uri

post /v2/{project_id}/ocr/vat-invoice

表1 路径参数

参数

是否必选

说明

endpoint

终端节点,即调用api的请求地址。

不同服务不同区域的endpoint不同,您可以从中获取。

例如,ocr服务在“华北-北京四”区域的“endpoint”“ocr.cn-north-4.myhuaweicloud.com”

project_id

项目id,您可以从中获取。

请求参数

表2 请求header参数

参数

是否必选

参数类型

描述

x-auth-token

string

用户token。

用于获取操作api的权限。响应消息头中x-subject-token的值即为token。

content-type

string

发送的实体的mime类型,参数值为“application/json”。

enterprise-project-id

string

企业项目id。ocr支持通过企业项目管理(eps)对不同用户组和用户的资源使用,进行分账。

获取方法:进入“”页面,单击企业项目名称,在企业项目详情页获取enterprise-project-id(企业项目id)。

企业项目创建步骤请参见用户指南。

说明:

创建企业项目后,在传参时,有以下三类场景。

  • 携带正确的id,正常使用ocr服务,账单归到企业id对应的企业项目中。
  • 携带错误的id,正常使用ocr服务,账单的企业项目会被分类为“未归集”。
  • 不携带id,正常使用ocr服务,账单的企业项目会被分类为“未归集”。
表3 请求body参数

参数

是否必选

参数类型

说明

image

string

该参数与url二选一。

图片的base64编码,要求base64编码后大小不超过10mb。

图片最短边不小于100px,最长边不超过8192px,支持jpeg、jpg、png、bmp、tiff、pdf、ofd格式,多页pdf仅识别第一页。

图片base64编码示例如/9j/4aaqskzjrgabag...,带有多余前缀会产生the image format is not supported报错。

url

string

该参数与image二选一。图片的url路径,目前支持:

  • 公网http/https url
  • obs提供的url,使用obs数据需要进行授权。包括对服务授权、临时授权、匿名公开授权,详情参见。
说明:
  • 接口响应时间依赖于图片的下载时间,如果图片下载时间过长,会返回接口调用失败。
  • 请保证被检测图片所在的存储服务稳定可靠,推荐使用obs服务存储图片数据。
  • url中不能存在中文字符,若存在,中文需要进行utf8编码。

advanced_mode

boolean

默认为false,如果传参为true,则返回更多字段,具体请参见表5

return_text_location

boolean

默认为false,如果传参为true,则返回text_location字段表示文本框在原图位置。

page_num

integer

页码,默认为1,返回第一页结果。如果传参不大于pdf页数,则返回对应pdf页的结果。

响应参数

根据识别的结果,可能有不同的http响应状态码(status code)。例如,200表示api调用成功,400表示调用失败,详细的状态码和响应参数说明如下。

状态码: 200

表4 响应body参数

参数

参数类型

描述

result

vatinvoiceresult object

识别结果。

调用失败时不返回此字段。

表5 vatinvoiceresult

参数

参数类型

描述

title

string

增值税发票标题。

type

string

增值税发票类型,可选值如下所示。

  • special:增值税专用发票
  • normal:增值税普通发票
  • electronic:增值税电子普通发票(含区块链发票)
  • special_electronic:增值税电子专用发票
  • toll:增值税电子普通发票(通行费)
  • roll:增值税普通发票(卷票)
  • fully_digitalized_special_electronic:全电专用发票
  • fully_digitalized_normal_electronic:全电普通发票

invoice_tag

string

增值税发票左上角标志。当“advanced_mode”设置为“true”时才返回。包含:通行费、代开。

sum_amount

string

小计金额,当传入多页pdf时返回此字段。

sum_tax

string

小计税额,当传入多页pdf时返回此字段。

serial_number

string

发票联次。

“advanced_mode”设置为“true”时才返回。

attribution

string

发票归属地。

“advanced_mode”设置为“true”时才返回。

supervision_seal

array of strings

发票监制章。

“advanced_mode”设置为“true”时才返回。

code

string

发票代码。

print_code

string

机打代码。当“advanced_mode”设置为“true”时才返回。

machine_number

string

机器编号。

“advanced_mode”设置为“true”时才返回。

print_number

string

卷票是机打号码,普通发票和专用发票在右上角,电子发票、通行费发票无此字段。

“advanced_mode”设置为“true”时才返回。

check_code

string

发票校验码,特定类型增值税发票内不存在该信息时返回空字符串。

number

string

发票号码。

issue_date

string

开票日期。

encryption_block

string

密码区。

buyer_name

string

购买方名称。

buyer_id

string

购买方纳税人识别号。

buyer_address

string

购买方地址、电话。

buyer_bank

string

购买方开户行及帐号。

seller_name

string

销售方名称。

seller_id

string

销售方纳税人识别号。

seller_address

string

销售方地址、电话。

seller_bank

string

销售方开户行及帐号。

subtotal_amount

string

合计金额。

subtotal_tax

string

合计税额。

total

string

价税合计。

total_in_words

string

价税合计(大写)。

“advanced_mode”设置为“true”时才返回。

remarks

string

备注。

“advanced_mode”设置为“true”时才返回。

receiver

string

收款人。

“advanced_mode”设置为“true”时才返回。

reviewer

string

复核。

“advanced_mode”设置为“true”时才返回。

issuer

string

开票人。

“advanced_mode”设置为“true”时才返回。

seller_seal

array of strings

销售方发票专用章。

“advanced_mode”设置为“true”时才返回。

item_list

array of itemlist objects

货物或应税劳务列表。

confidence

object

各个字段的置信度。

“advanced_mode”设置为“true”时才返回。

text_location

object

文本框在原图位置。输出左上、右上、右下、左下四个点坐标。

当“return_text_location”设置为“true”时才返回。

表6 itemlist

参数

参数类型

描述

name

string

货物或应税劳务、服务名称。

specification

string

规格型号。

unit

string

单位。

quantity

string

数量。

unit_price

string

单价。

license_plate_number

string

车牌号码。

当“type”被识别为“toll”且“advanced_mode”设置为“true”时才返回。

amount

string

金额。

tax_rate

string

税率。

tax

string

税额。

end_date

string

通行日期止。

当“type”被识别为“toll”且“advanced_mode”设置为“true”时才返回。

start_date

string

通行日期起。

当“type”被识别为“toll”且“advanced_mode”设置为“true”时才返回。

vehicle_type

string

车辆类型。

当“type”被识别为“toll”且“advanced_mode”设置为“true”时才返回。

状态码: 400

表7 响应body参数

参数

参数类型

说明

error_code

string

调用失败时的错误码,具体请参见。

当出现错误码“modelarts.4204”时,请参考为什么调用api时提示“modelarts.4204”?章节。

调用成功时不返回此字段。

error_msg

string

调用失败时返回的错误信息。

调用成功时不返回此字段。

请求示例

  • “endpoint”即调用api的请求地址,不同服务不同区域的“endpoint”不同,具体请参见。

    例如,增值税发票识别服务部署在“华北-北京四”区域的“endpoint”“ocr.cn-north-4.myhuaweicloud.com”“ocr.cn-north-4.myhuaweicloud.cn”,请求url为“https://ocr.cn-north-4.myhuaweicloud.com/v2/{project_id}/ocr/vat-invoice”“project_id”为项目id,获取方法请参见

  • 如何获取token请参见。
  • 传入增值税发票的base64编码进行文字识别,并通过设置“advanced_mode”返回发票类型、联次、金额等信息。
    post https://{endpoint}/v2/{project_id}/ocr/vat-invoice 
     request header:   
     content-type: application/json   
     x-auth-token: miinrwyjkozihvcnaqccoiinodccdtqcaqexdtalbglghkgbzqmeagewgguvbgkqhkig...      
     request body:
     {   
        "image":"/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaaj...",
        "advanced_mode": true
      }
  • 传入增值税发票的url进行文字识别,并通过设置“advanced_mode”返回发票类型、联次、金额等信息。
    post https://{endpoint}/v2/{project_id}/ocr/vat-invoice 
     request header:   
     content-type: application/json   
     x-auth-token: miinrwyjkozihvcnaqccoiinodccdtqcaqexdtalbglghkgbzqmeagewgguvbgkqhkig...     
     request body:
     {
         "url":"https://bucketname.obs.xxxx.com/objectname",
         "advanced_mode": true
      }

响应示例

状态码:200

成功响应示例

{
  "result" : {
    "type" : "special",
    "title" : "深圳增值税电子专用发票",
    "serial_number" : "第二联:发票联",
    "attribution" : "深圳",
    "supervision_seal" : [ "全国统一发票监制章", "深圳", "国家税务总局监制" ],
    "code" : "310316xxxx",
    "check_code" : "",
    "machine_number" : "310316xxxx",
    "print_number" : "",
    "number" : "60543xxx",
    "issue_date" : "2017年08月30日",
    "encryption_block" : "6/ 1 733<672085 063>82>30<1872/1<>*312671<9<1-11208-746599*6/> 7>2163 141-8737*4932 7970*11892126>0*- 7 78>1",
    "buyer_name" : "xx有限公司",
    "buyer_id" : "917107277650880665",
    "buyer_address" : "xxxx",
    "buyer_bank" : "xx银行20384543252xxxx",
    "seller_name" : "餐饮有限公司",
    "seller_id" : "9351099411892126",
    "seller_address" : "xxxx",
    "seller_bank" : "xx银行991101526087xxxx",
    "subtotal_amount" : "¥8850.00",
    "subtotal_tax" : "¥1504.50",
    "total" : "¥10354.50",
    "total_in_words" : "肆仟肆佰玖拾圆整",
    "remarks" : "校验码11xxxxxxxxxxx",
    "receiver" : "xx",
    "reviewer" : "xx",
    "issuer" : "xx",
    "seller_seal" : [ "深圳市xxx有限公司", "91440300736259277e", "发票专用章" ],
    "item_list" : [ {
      "name" : "食品a",
      "specification" : "200g/盒",
      "unit" : "盒",
      "quantity" : "300",
      "unit_price" : "28.00",
      "license_plate_number" : "",
      "vehicle_type" : "",
      "start_date" : "",
      "end_date" : "",
      "amount" : "8400.00",
      "tax_rate" : "17%",
      "tax" : "1428.00"
    } ],
    "confidence" : {
      "type" : 0.996,
      "title" : 0.9962,
      "serial_number" : 0.9652,
      "attribution" : 0.996,
      "supervision_seal" : [ 0.997, 0.9945, 0.996 ],
      "code" : 0.99999,
      "check_code" : 0.843,
      "machine_number" : 0.907,
      "print_number" : 0.0,
      "number" : 1.9856,
      "issue_date" : 0.9848,
      "encryption_block" : 0.9922,
      "buyer_name" : 0.9854,
      "buyer_id" : 0.9869,
      "buyer_address" : 0.0,
      "buyer_bank" : 0.0,
      "seller_name" : 0.9883,
      "seller_id" : 0.9914,
      "seller_address" : 0.9952,
      "seller_bank" : 0.9829,
      "subtotal_amount" : 0.9533,
      "subtotal_tax" : 0.9167,
      "total" : 0.9444,
      "total_in_words" : 0.9854,
      "remarks" : 0.8762,
      "receiver" : 0.985,
      "reviewer" : 0.9759,
      "issuer" : 0.9872,
      "seller_seal" : [ 0.9883, 0.9914, 0.9999 ],
      "item_list" : [ {
        "name" : 0.9779,
        "specification" : 0.0,
        "unit" : 0.0,
        "quantity" : 0.0,
        "unit_price" : 0.0,
        "license_plate_number" : 0.0,
        "vehicle_type" : 0.0,
        "start_date" : 0.0,
        "end_date" : 0.0,
        "amount" : 0.8227,
        "tax_rate" : 0.5183,
        "tax" : 0.8394
      } ]
    }
  }
}

状态码:400

失败响应示例

{
    "error_code": "ais.0103",
    "error_msg": "the image size does not meet the requirements."
}

sdk代码示例

sdk代码示例如下。

  • 传入增值税发票的base64编码进行文字识别,并通过设置“advanced_mode”返回发票类型、联次、金额等信息。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    package com.huaweicloud.sdk.test;
    import com.huaweicloud.sdk.core.auth.icredential;
    import com.huaweicloud.sdk.core.auth.basiccredentials;
    import com.huaweicloud.sdk.core.exception.connectionexception;
    import com.huaweicloud.sdk.core.exception.requesttimeoutexception;
    import com.huaweicloud.sdk.core.exception.serviceresponseexception;
    import com.huaweicloud.sdk.ocr.v1.region.ocrregion;
    import com.huaweicloud.sdk.ocr.v1.*;
    import com.huaweicloud.sdk.ocr.v1.model.*;
    public class recognizevatinvoicesolution {
        public static void main(string[] args) {
            // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
            string ak = system.getenv("cloud_sdk_ak");
            string sk = system.getenv("cloud_sdk_sk");
            icredential auth = new basiccredentials()
                    .withak(ak)
                    .withsk(sk);
            ocrclient client = ocrclient.newbuilder()
                    .withcredential(auth)
                    .withregion(ocrregion.valueof(""))
                    .build();
            recognizevatinvoicerequest request = new recognizevatinvoicerequest();
            vatinvoicerequestbody body = new vatinvoicerequestbody();
            body.withadvancedmode(true);
            body.withimage("/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa...");
            request.withbody(body);
            try {
                recognizevatinvoiceresponse response = client.recognizevatinvoice(request);
                system.out.println(response.tostring());
            } catch (connectionexception e) {
                e.printstacktrace();
            } catch (requesttimeoutexception e) {
                e.printstacktrace();
            } catch (serviceresponseexception e) {
                e.printstacktrace();
                system.out.println(e.gethttpstatuscode());
                system.out.println(e.getrequestid());
                system.out.println(e.geterrorcode());
                system.out.println(e.geterrormsg());
            }
        }
    }
    
  • 传入增值税发票的url进行文字识别,并通过设置“advanced_mode”返回发票类型、联次、金额等信息。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    package com.huaweicloud.sdk.test;
    import com.huaweicloud.sdk.core.auth.icredential;
    import com.huaweicloud.sdk.core.auth.basiccredentials;
    import com.huaweicloud.sdk.core.exception.connectionexception;
    import com.huaweicloud.sdk.core.exception.requesttimeoutexception;
    import com.huaweicloud.sdk.core.exception.serviceresponseexception;
    import com.huaweicloud.sdk.ocr.v1.region.ocrregion;
    import com.huaweicloud.sdk.ocr.v1.*;
    import com.huaweicloud.sdk.ocr.v1.model.*;
    public class recognizevatinvoicesolution {
        public static void main(string[] args) {
            // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
            string ak = system.getenv("cloud_sdk_ak");
            string sk = system.getenv("cloud_sdk_sk");
            icredential auth = new basiccredentials()
                    .withak(ak)
                    .withsk(sk);
            ocrclient client = ocrclient.newbuilder()
                    .withcredential(auth)
                    .withregion(ocrregion.valueof(""))
                    .build();
            recognizevatinvoicerequest request = new recognizevatinvoicerequest();
            vatinvoicerequestbody body = new vatinvoicerequestbody();
            body.withadvancedmode(true);
            body.withurl("https://bucketname.obs.myhuaweicloud.com/objectname");
            request.withbody(body);
            try {
                recognizevatinvoiceresponse response = client.recognizevatinvoice(request);
                system.out.println(response.tostring());
            } catch (connectionexception e) {
                e.printstacktrace();
            } catch (requesttimeoutexception e) {
                e.printstacktrace();
            } catch (serviceresponseexception e) {
                e.printstacktrace();
                system.out.println(e.gethttpstatuscode());
                system.out.println(e.getrequestid());
                system.out.println(e.geterrorcode());
                system.out.println(e.geterrormsg());
            }
        }
    }
    
  • 传入增值税发票的base64编码进行文字识别,并通过设置“advanced_mode”返回发票类型、联次、金额等信息。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    # coding: utf-8
    from huaweicloudsdkcore.auth.credentials import basiccredentials
    from huaweicloudsdkocr.v1.region.ocr_region import ocrregion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkocr.v1 import *
    if __name__ == "__main__":
        # the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
        ak = os.getenv("cloud_sdk_ak")
        sk = os.getenv("cloud_sdk_sk")
        credentials = basiccredentials(ak, sk) \
        client = ocrclient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ocrregion.value_of("")) \
            .build()
        try:
            request = recognizevatinvoicerequest()
            request.body = vatinvoicerequestbody(
                advanced_mode=true,
                image="/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa..."
            )
            response = client.recognize_vat_invoice(request)
            print(response)
        except exceptions.clientrequestexception as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 传入增值税发票的url进行文字识别,并通过设置“advanced_mode”返回发票类型、联次、金额等信息。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    # coding: utf-8
    from huaweicloudsdkcore.auth.credentials import basiccredentials
    from huaweicloudsdkocr.v1.region.ocr_region import ocrregion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkocr.v1 import *
    if __name__ == "__main__":
        # the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
        ak = os.getenv("cloud_sdk_ak")
        sk = os.getenv("cloud_sdk_sk")
        credentials = basiccredentials(ak, sk) \
        client = ocrclient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ocrregion.value_of("")) \
            .build()
        try:
            request = recognizevatinvoicerequest()
            request.body = vatinvoicerequestbody(
                advanced_mode=true,
                url="https://bucketname.obs.myhuaweicloud.com/objectname"
            )
            response = client.recognize_vat_invoice(request)
            print(response)
        except exceptions.clientrequestexception as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 传入增值税发票的base64编码进行文字识别,并通过设置“advanced_mode”返回发票类型、联次、金额等信息。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    package main
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        ocr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/region"
    )
    func main() {
        // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
        ak := os.getenv("cloud_sdk_ak")
        sk := os.getenv("cloud_sdk_sk")
        auth := basic.newcredentialsbuilder().
            withak(ak).
            withsk(sk).
            build()
        client := ocr.newocrclient(
            ocr.ocrclientbuilder().
                withregion(region.valueof("")).
                withcredential(auth).
                build())
        request := &model.recognizevatinvoicerequest{}
    	advancedmodevatinvoicerequestbody:= true
    	imagevatinvoicerequestbody:= "/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa..."
    	request.body = &model.vatinvoicerequestbody{
    		advancedmode: &advancedmodevatinvoicerequestbody,
    		image: &imagevatinvoicerequestbody,
    	}
    	response, err := client.recognizevatinvoice(request)
    	if err == nil {
            fmt.printf("% v\n", response)
        } else {
            fmt.println(err)
        }
    }
    
  • 传入增值税发票的url进行文字识别,并通过设置“advanced_mode”返回发票类型、联次、金额等信息。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    package main
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        ocr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/region"
    )
    func main() {
        // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
        ak := os.getenv("cloud_sdk_ak")
        sk := os.getenv("cloud_sdk_sk")
        auth := basic.newcredentialsbuilder().
            withak(ak).
            withsk(sk).
            build()
        client := ocr.newocrclient(
            ocr.ocrclientbuilder().
                withregion(region.valueof("")).
                withcredential(auth).
                build())
        request := &model.recognizevatinvoicerequest{}
    	advancedmodevatinvoicerequestbody:= true
    	urlvatinvoicerequestbody:= "https://bucketname.obs.myhuaweicloud.com/objectname"
    	request.body = &model.vatinvoicerequestbody{
    		advancedmode: &advancedmodevatinvoicerequestbody,
    		url: &urlvatinvoicerequestbody,
    	}
    	response, err := client.recognizevatinvoice(request)
    	if err == nil {
            fmt.printf("% v\n", response)
        } else {
            fmt.println(err)
        }
    }
    

更多编程语言的sdk代码示例,请参见的代码示例页签,可生成自动对应的sdk代码示例。

状态码

状态码

描述

200

成功响应示例

400

失败响应样例

状态码请参见。

错误码

错误码请参见。

分享:
网站地图