> ## Documentation Index
> Fetch the complete documentation index at: https://docs.acedata.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# 数字英文验证码识别 API 对接说明

> Recognition of English numerical verification codes 集成指南 - Ace Data Cloud

本文将介绍一种 数字英文验证码识别 API 对接说明，它是基于深度学习技术，可用于识别变长英文数字验证码。输入验证码图像的内容，输出验证码结果。

## 申请流程

要使用 数字英文验证码识别 API，首先到 [Ace Data Cloud 控制台](https://platform.acedata.cloud/console/applications) 获取您的 API Token，留作备用。

![](https://cdn.acedata.cloud/5hmkdg.jpg)

如果你尚未登录或注册，会自动跳转到登录页面邀请你注册和登录，完成后会自动返回当前页面。

**一个 API Token 即可调用平台所有服务，无需为每个服务单独申请。** 首次申请会赠送免费额度，可免费体验；额度不足时可在 [控制台](https://platform.acedata.cloud/console/coin) 充值通用余额。

> 📘 完整文档：[数字英文验证码识别 API →](https://platform.acedata.cloud/documents/captcha-recognition-image2text)

## 基本使用

首先先了解下基本的使用方式，就是输入需要处理 变长英文数字验证码图像，便可获得处理后的结果，首先需要简单地传递一个 `image` 字段，这个就是具体英文数字验证码图像，如图所示：

<p>
  <img src="https://cdn.acedata.cloud/c50hi9.png" width="500" className="m-auto" />
</p>

然后我们需要将验证码图片转换为Base64编码的验证码图像，转换Base64编码推荐使用谷歌浏览器插件FeHelper进行转换，具体使用方法可参考下图：

<p>
  <img src="https://cdn.acedata.cloud/zy2jwh.png" width="500" className="m-auto" />
</p>

<p>
  <img src="https://cdn.acedata.cloud/pr73gn.png" width="500" className="m-auto" />
</p>

<p>
  <img src="https://cdn.acedata.cloud/ic4dbw.png" width="500" className="m-auto" />
</p>

之后就可以将谷歌浏览器插件FeHelp获取到的Base64编码复制过来，记住是不包含data:image/png;base64的前缀，具体的内容如下：

<p>
  <img src="https://cdn.acedata.cloud/5h4x4w.png" width="500" className="m-auto" />
</p>

可以看到这里我们设置了 Request Headers，包括：

* `accept`：想要接收怎样格式的响应结果，这里填写为 `application/json`，即 JSON 格式。
* `authorization`：调用 API 的密钥，申请之后可以直接下拉选择。

另外设置了 Request Body，包括：

* `image`：Base64编码的验证码图像（不包含data:image/png;base64的前缀）。

选择之后，可以发现右侧也生成了对应代码，如图所示：

<p>
  <img src="https://cdn.acedata.cloud/202y3d.png" width="500" className="m-auto" />
</p>

点击「Try」按钮即可进行测试，如上图所示，这里我们就得到了如下结果：

```json theme={null}
{
  "text": "7364"
}
```

返回结果一共有多个字段，介绍如下：

* `text`，此次 变长英文数字验证码图像 任务处理后文字内容。

可以看到我们得到了处理 变长英文数字验证码图像 的验证结果，我们只需要根据结果中 `text` 的文字内容即可通过验证。

另外如果想生成对应的对接代码，可以直接复制生成，例如 CURL 的代码如下：

```shell theme={null}
curl -X POST 'https://api.acedata.cloud/captcha/recognition/image2text' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "image": "iVBORw0KGgoAAAANSUhEUgAAAgUAAAE3CAYAAAA6xjI2AAAAAX..."
}'
```

Python 的对接代码如下：

```python theme={null}
import requests

url = "https://api.acedata.cloud/captcha/recognition/image2text"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "image": "iVBORw0KGgoAAAANSUhEUgAAAgUAAAE3CAYAAAA6xjI2AAAAAX..."
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)
```

## 错误处理

在调用 API 时，如果遇到错误，API 会返回相应的错误代码和信息。例如：

* `400 token_mismatched`：Bad request, possibly due to missing or invalid parameters.
* `400 api_not_implemented`：Bad request, possibly due to missing or invalid parameters.
* `401 invalid_token`：Unauthorized, invalid or missing authorization token.
* `429 too_many_requests`：Too many requests, you have exceeded the rate limit.
* `500 api_error`：Internal server error, something went wrong on the server.

### 错误响应示例

```json theme={null}
{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}
```

## 结论

通过本文档，您已经了解了如何使用 数字英文验证码识别 API 可用于识别变长英文数字验证码。输入验证码图像的内容，输出验证码结果。希望本文档能帮助您更好地对接和使用该 API。如有任何问题，请随时联系我们的技术支持团队。
