captchaocr.cnCaptchaOCR
调用示例

cURL 与 Node.js 调用示例

下面是调用 验证码识别 API 的 cURL 和 Node.js 示例。请求发到 POST /api/v1/recognize,用 X-API-Key 鉴权。密钥只放在服务端。

两种提交图片的方式

文件上传使用 multipart/form-data 的 file 字段。已经持有 Base64 时,用 JSON 字段 image 或 image_base64,也支持 data:image/...;base64,...。同一次请求只提交一种。批量接口是 POST /api/v1/recognize/batch。

cURL

curl -X POST "https://captchaocr.cn/api/v1/recognize?charset=digits&expected_length=4" \
  -H "X-API-Key: ck_live_…" \
  -F "file=@captcha.png"

Node.js

const form = new FormData();
form.append("file", new Blob([imageBytes]), "captcha.png");

const response = await fetch(
  "https://captchaocr.cn/api/v1/recognize?expected_length=4",
  {
    method: "POST",
    headers: { "X-API-Key": process.env.CAPTCHA_API_KEY },
    body: form,
  },
);
const result = await response.json();
if (result.accepted) console.log(result.text);

查询参数 charset、expected_length、min_confidence 和 strict 都可选。严格模式下验收未通过会返回 422,而不是 HTTP 200 加 accepted: false。

字段、错误码和配额见 API 参考。Python、Java、Go、Node.js 和 Rust 的完整示例见语言接入示例。Python SDK 见 Python SDK 文档。