6. 接口与体验
6.1 开放API
API设计
智能文档处理系统提供RESTful API,支持多种客户端接入:
API架构
基础URL:
https://api.example.com/v1/document-processing
核心接口:
1. 上传文档(Upload Document)
POST /documents
Content-Type: multipart/form-data
{
"file": <file>,
"document_type": "contract",
"metadata": {
"source": "manual",
"tags": ["important"]
}
}
Response:
{
"document_id": "doc_123",
"status": "uploaded",
"created_at": "2024-01-01T10:00:00Z"
}
2. 处理文档(Process Document)
POST /documents/{document_id}/process
Content-Type: application/json
{
"task_type": "extraction",
"extraction_fields": ["contract_no", "amount", "date"],
"options": {
"ocr": true,
"language": "zh"
}
}
Response:
{
"task_id": "task_456",
"status": "processing",
"estimated_time": 30
}
3. 获取处理结果(Get Processing Result)
GET /documents/{document_id}/result
Response:
{
"document_id": "doc_123",
"status": "completed",
"extracted_data": {
"contract_no": "HT-2024-001",
"amount": "100万元",
"date": "2024-01-01"
},
"quality_score": 0.95,
"processed_at": "2024-01-01T10:05:00Z"
}
4. 批量处理(Batch Process)
POST /documents/batch
Content-Type: application/json
{
"document_ids": ["doc_123", "doc_124", "doc_125"],
"task_type": "extraction",
"extraction_fields": ["contract_no", "amount"]
}
Response:
{
"batch_id": "batch_789",
"status": "processing",
"total": 3,
"processed": 0
}
认证授权
认证方式
API Key认证:
- 每个客户端分配唯一的API Key
- 在请求头中携带:
Authorization: Bearer {api_key} - 简单易用,适合服务端调用
OAuth 2.0认证:
- 支持标准OAuth 2.0流程
- 获取Access Token后使用
- 适合第三方应用集成
JWT Token认证:
- 用户登录后获取JWT Token
- Token包含用户信息和权限
- 适合Web和移动端应用
API文档
文档工具
Swagger/OpenAPI:
- 使用OpenAPI 3.0规范
- 自动生成交互式API文档
- 支持在线测试API
访问地址:
https://api.example.com/docs