二维码识别

ocr-qrcodePOST
POSThttps://v1.apizero.cn/api/ocr-qrcode

概述

上传含二维码或条形码的图片(URL 或 base64),自动识别并返回解码文本、码类型和四角位置。支持一图多码。 适用于扫码核销、仓储入库、海报解析、条码录入等场景。需要登录后使用,匿名不可调用。

调用约定

  • 网关 · https://v1.apizero.cn
  • 鉴权 · Authorization: Bearer <API Key>
  • 回包 · JSON {code, msg, data}。成功看 code === 0,不要只看 HTTP 200。
/aidocs/ocr-qrcode/raw.md
打开 Markdown

鉴权

未携带 API Key:无;已登录(未开通会员):每天 10 次 · QPS 2;试用:一次性 5 次;黄金会员:每天 100 次 · QPS 10;钻石会员:每天 5,000 次 · QPS 30;企业会员:每天不限次 · QPS 60;点数:本接口不支持扣点;免费。需要 API Key(Authorization: Bearer <key>)。也可直接传 url 或 image(base64),与 input_type + input_data 等价。

获取 API Key

请求头

Authorizationstring选填

推荐:Bearer <API Key>。兼容请求头 X-API-Key,以及 Query api_key / apikey / key(key 仅当值为 sk_live_/sk_test_/sk_stag_ 形态时生效)。匿名可不传,受每日免费额度限制。

Content-Typestring必填

请求体格式

请求参数

POST · APPLICATION/JSON

input_typestring必填

图片传入方式:url 或 base64。也可省略本字段,改传 url / image

例url

input_datastring必填

图片 URL 或 base64(jpg/png,可带 data:image 前缀,最大 10 MB)。兼容别名 url、image

例https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https%3A%2F%2Fwww.apizero.cn

{
  "input_type": "url",
  "input_data": "https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https%3A%2F%2Fwww.apizero.cn"
}

返回结果

顶层固定为 code / msg / data。下表一般是 data 内字段。 code · msg · data · tips · request_id

countnumber

识别到的码数量(一图可多码)

itemsarray

识别结果列表

textstring

解码文本

typestring

码类型,常见 qrcode、barcode

positionobject

四角像素坐标

left_top.xnumber

左上角 x

left_top.ynumber

左上角 y

right_top.xnumber

右上角 x

right_top.ynumber

右上角 y

right_bottom.xnumber

右下角 x

right_bottom.ynumber

右下角 y

left_bottom.xnumber

左下角 x

left_bottom.ynumber

左下角 y

tipsstring

品牌提示(所有接口统一返回):极数本源 · https://apizero.cn

返回示例

{
  "code": 0,
  "msg": "成功",
  "data": {
    "count": 1,
    "items": [
      {
        "text": "https://www.apizero.cn/",
        "type": "qrcode",
        "position": {
          "left_top": {
            "x": 40.5,
            "y": 40.5
          },
          "right_top": {
            "x": 410.5,
            "y": 40.5
          },
          "right_bottom": {
            "x": 410.5,
            "y": 410.5
          },
          "left_bottom": {
            "x": 40.5,
            "y": 410.5
          }
        }
      }
    ]
  },
  "request_id": "req_abc123",
  "tips": "极数本源 · https://apizero.cn"
}

请求示例

示例都是服务端写法。Python / JavaScript 各有常规写法和官方库。

curl -sS -X POST "https://v1.apizero.cn/api/ocr-qrcode" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "input_type": "url",
  "input_data": "https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https%3A%2F%2Fwww.apizero.cn"
}'

错误码

先看业务 code。HTTP 也可能不是 200。

0200

成功

4000400

参数错误

4011401

API Key 无效

4013403

API Key 已暂停

4014403

当前 IP 不在 Key 白名单

4015401

此接口需要 API Key

4022402

余额不足

4029429

调用过快(QPS)

4030429

今日免费额度已用完

4040503

接口已下线

4041404

接口不存在

5000500

服务器内部错误

5020502

上游暂时不可用

5021502

上游返回格式异常

5030502

暂无可用节点

调用限制

计费模式
完全免费
QPS 限制
QPS 2
登录免费额度
10 次(已认证)
匿名每日额度
无
黄金会员
每天 100 次 · QPS 10
钻石会员
每天 5,000 次 · QPS 30
企业会员
每天不限次 · QPS 60

购买套餐、看评价请走商城详情。 购买 / 调试

更新日志

  • 1.0.02026-09-08

    上架二维码 / 条形码识别,支持一图多码 登录每天 10 次;黄金每天 100 次;企业走共享额度

免责声明

识别结果以图片清晰度为准;模糊、残缺、反光过强可能导致漏识。请勿用于违法用途。