众森企服票据识别API 开发文档
基于阿里云百炼平台,支持 JPG/PNG/PDF/OFD/XML,返回结构化发票数据。
基础信息
| 基础URL | http://localhost:3000/api |
|---|---|
| 认证方式 | API Key(表单字段 api_key) |
| 支持格式 | JPG、PNG、PDF、OFD、XML |
| 最大文件大小 | 10MB |
| 每日配额 | 默认 1000 次/Key/日(超限返回 429) |
一键导入集合
直接导入到 Postman 或 Insomnia,即可调试所有接口。
下载 Postman Collection 下载 Insomnia Collection
接口与示例
1) 票据识别 POST /api/v1/recognize
curl -X POST "http://localhost:3000/api/v1/recognize" \
-F "file=@invoice.pdf" \
-F "api_key=zs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
-F "file=@invoice.pdf" \
-F "api_key=zs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
2) 查询状态 GET /api/v1/status/{requestId}
curl -X GET "http://localhost:3000/api/v1/status/uuid-string?api_key=zs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
3) 支持格式 GET /api/v1/formats
curl -X GET "http://localhost:3000/api/v1/formats"
JavaScript 示例
const fd=new FormData();
fd.append('file',file);
fd.append('api_key','zs_xxx');
fetch('/api/v1/recognize',{method:'POST',body:fd}).then(r=>r.json()).then(console.log);
fd.append('file',file);
fd.append('api_key','zs_xxx');
fetch('/api/v1/recognize',{method:'POST',body:fd}).then(r=>r.json()).then(console.log);
Python 示例
import requests
r=requests.post('http://localhost:3000/api/v1/recognize',files={'file':open('invoice.pdf','rb')},data={'api_key':'zs_xxx'})
print(r.json())
r=requests.post('http://localhost:3000/api/v1/recognize',files={'file':open('invoice.pdf','rb')},data={'api_key':'zs_xxx'})
print(r.json())
错误码与限流说明
| 错误码 | 含义 | 说明 |
|---|---|---|
| 400 | 请求参数错误 | 缺少 file 或 api_key |
| 401 | API Key无效 | 格式错误或不存在 |
| 413 | 文件过大 | 超过 10MB |
| 415 | 文件格式不支持 | 仅支持 JPG/PNG/PDF/OFD/XML |
| 429 | 请求过于频繁 | 超过每日配额(默认1000) |
| 500 | 服务器内部错误 | 后端异常 |
| 502 | 百炼服务异常 | 上游识别失败 |
PDF/OFD 处理策略
系统先尝试直传到百炼;若直传失败,自动以 Puppeteer 渲染第一页转为 PNG 再识别,避免系统级依赖。
最佳实践
- 不要在前端硬编码 API Key,使用后端代理或仅在服务端调用
- 控制文件大小与清晰度,提高识别准确率与响应速度
- 记录返回的 request_id,便于问题追踪与状态查询