接口描述
支持对各类定额发票的发票代码、发票号码、金额、发票所在地、发票金额小写、省、市7个关键字段进行结构化识别。
在线调试
您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/ocr/v1/quota_invoice
URL参数:
参数 | 值 |
---|---|
access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
参数 | 值 |
---|---|
Content-Type | application/x-www-form-urlencoded |
Body中放置请求参数,参数详情如下:
请求参数
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
---|---|---|---|---|
image | 和 url/pdf_file 三选一 | string | - |
图像数据,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式 优先级:image > url > pdf_file,当image字段存在时,url、pdf_file字段失效 |
url | 和 image/pdf_file 三选一 | string | - |
图片完整url,url长度不超过1024字节,url对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式 优先级:image > url > pdf_file,当image字段存在时,url字段失效 请注意关闭URL防盗链 |
pdf_file | 和 image/url 三选一 | string | - |
PDF文件,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过4M,最短边至少15px,最长边最大4096px 优先级:image > url > pdf_file,当image、url字段存在时,pdf_file字段失效 |
pdf_file_num | 否 | string | - | 需要识别的PDF文件的对应页码,当 pdf_file 参数有效时,识别传入页码的对应页面内容,若不传入,则默认识别第 1 页 |
请求代码示例
提示一:使用示例代码前,请记得替换其中的示例Token、图片地址或Base64信息。
提示二:部分语言依赖的类或库,请在代码注释中查看下载地址。
curl -i -k 'https://aip.baidubce.com/rest/2.0/ocr/v1/quota_invoice?
access_token=【调用鉴权接口获取的token】' --data 'image=【图片Base64编码,
需UrlEncode】' -H 'Content-Type:application/x-www-form-urlencoded'
返回说明
返回参数
字段 | 是否必选 | 类型 | 说明 |
---|---|---|---|
log_id | 是 | uint64 | 唯一的log id,用于问题定位 |
words_result_num | 是 | uint32 | 识别结果数,表示words_result的元素个数 |
words_result | 是 | object{} | 识别结果数组 |
+ invoice_code | 否 | string | 发票代码 |
+ invoice_number | 否 | string | 发票号码 |
+ invoice_rate | 否 | string | 金额 |
+ location | 否 | string | 发票所在地 |
+ invoice_rate_lowercase | 否 | string | 发票金额小写 |
+ province | 否 | string | 省 |
+ city | 否 | string | 市 |
pdf_file_size | 否 | string | 传入PDF文件的总页数,当 pdf_file 参数有效时返回该字段 |
返回示例
{ "log_id": 2480896295, "words_result_num": 3, "words_result": { "invoice_code":
"132081490320", "invoice_number": "01275486", "invoice_rate": "伍拾元整"
"invoice_rate_lowercase": "100.00", "invoice_code": "161034127200", "province": "陕西", } }