API 文档

OCR证件识别服务API接口文档,帮助您快速接入

接口域名 Base URL
https://ocr.5811.cn

1 快速开始

注册账号后,在控制台创建API密钥,即可开始调用OCR识别接口。

// 1. 注册账号并登录控制台
// 2. 创建 API 密钥
// 3. 使用密钥调用识别接口

// 接口地址
POST /api/v1/ocr

// 认证方式
Authorization: Bearer your_api_key

2 OCR识别接口

接口信息

请求方式POST
接口地址/api/v1/ocr
Content-Typemultipart/form-dataapplication/json

Header 参数

参数名类型必填说明
AuthorizationstringBearer token,格式:Bearer your_api_key

请求方式一:上传图片文件

使用 multipart/form-data 上传图片文件

参数名类型必填说明
imagefile图片文件,支持 JPG/PNG/BMP

请求方式二:图片URL

使用 JSON 格式传递图片URL

{
  "image_url": "https://example.com/id-card.jpg"
}

3 代码示例

cURL

# 上传图片文件
curl -X POST https://ocr.5811.cn/api/v1/ocr \
  -H "Authorization: Bearer your_api_key" \
  -F "image=@/path/to/image.jpg"

# 使用图片URL
curl -X POST https://ocr.5811.cn/api/v1/ocr \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"image_url": "https://example.com/image.jpg"}'

JavaScript / Node.js

// 使用 fetch API
const formData = new FormData();
formData.append('image', fileInput.files[0]);

const response = await fetch('/api/v1/ocr', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your_api_key'
  },
  body: formData
});

const result = await response.json();
console.log(result);

// 使用图片URL
const response2 = await fetch('/api/v1/ocr', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your_api_key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    image_url: 'https://example.com/image.jpg'
  })
});

Python

import requests

# 上传图片文件
url = "https://ocr.5811.cn/api/v1/ocr"
headers = {"Authorization": "Bearer your_api_key"}

with open("image.jpg", "rb") as f:
    files = {"image": f}
    response = requests.post(url, headers=headers, files=files)

result = response.json()
print(result)

# 使用图片URL
import json
response = requests.post(url,
    headers={
        "Authorization": "Bearer your_api_key",
        "Content-Type": "application/json"
    },
    data=json.dumps({"image_url": "https://example.com/image.jpg"})
)

4 响应说明

成功响应

{
  "status": "success",
  "data": {
    // OCR识别结果,包含证件信息
  }
}

错误响应

{
  "statusCode": 401,
  "message": "缺少API密钥"
}

错误码说明

错误码说明
401API密钥缺失或无效
403API密钥已被禁用
400请求参数错误
500服务器内部错误