文字验证码
概述
文字验证码是一种包含扭曲但人类可读的文本的图像。要解决验证码图像,用户必须输入图像中的文本。
📝
文字验证码可以包括数字、字母或两者的组合。它们通常使用图像变形、噪声和各种字体使自动读取变得困难。

1. 创建任务
请求
POST https://api.achicaptcha.com/createTask
参数
| 参数名 | 数据类型 | 必需? | 描述 |
|---|---|---|---|
clientKey | string | yes | API 密钥 |
task.type | string | yes | ImageToTextTask |
task.image | string | yes | 图像的 base64 |
task.subType | string | yes | 是以下类型之一:common、amazon、microsoft、facebook、garena、artistshot、gmx、11166、houssam |
请求示例
POST /createTask HTTP/1.1
Host: api.achicaptcha.com
Content-Type: application/json
{
"clientKey": "您的 API_KEY",
"task": {
"type": "ImageToTextTask",
"image": "图像的 base64 编码",
"subType": "gmx"
}
}响应
成功时,服务器将返回 errorId = 0 和 taskId
{
"errorId": 0,
"taskId": "f2fc70d6-c76b-4fba-9480-205ac1fe9fb9"
}2. 获取结果
请求
POST https://api.achicaptcha.com/getTaskResult
参数
| 参数名 | 数据类型 | 必需? | 描述 |
|---|---|---|---|
clientKey | string | yes | API 密钥 |
taskId | string | yes | 从 (1) 获取的 TaskId |
请求示例
POST /getTaskResult HTTP/1.1
Host: api.achicaptcha.com
Content-Type: application/json
{
"clientKey": "您的 API_KEY",
"taskId": "f2fc70d6-c76b-4fba-9480-205ac1fe9fb9"
}响应
{
"errorId": 0,
"status": "ready",
"solution": "swamn"
}状态说明
errorId = 0且status = ready:解决成功,在solution.text中读取结果errorId = 0且status = processing:正在解决验证码,等待 2 秒后重试errorId > 0:系统错误,返回错误代码和错误描述
SubType 类型
Achicaptcha 通过 subType 参数支持多种不同类型的文字验证码:
| SubType | 描述 |
|---|---|
common | 普通文字验证码,最常见 |
amazon | Amazon 的特定验证码,具有特殊扭曲 |
microsoft | Microsoft 服务上使用的验证码 |
facebook | Facebook 的验证码,具有特征性字体 |
garena | Garena 平台上的验证码 |
artistshot | Artistshot 网站的验证码 |
gmx | GMX 电子邮件验证码 |
11166 | 代码为 11166 的特殊验证码类型 |
houssam | 名为 Houssam 的特定验证码类型 |
discord | Discord 的特定验证码类型 |
okvip | okvip 的特定验证码类型 |
shopee | shopee 的特定验证码类型 |
📝
通常 subType: common 可以处理所有类型的文字验证码。如果您网站上的文字验证码过于特殊,请联系 管理员 (opens in a new tab) 获取支持。
集成示例
import requests
import time
import base64
def solve_captcha(image_path, sub_type='common', api_key='YOUR_API_KEY'):
# 读取并编码图像
with open(image_path, 'rb') as image_file:
image_base64 = base64.b64encode(image_file.read()).decode('utf-8')
# 步骤 1:创建任务
create_task_url = 'https://api.achicaptcha.com/createTask'
create_task_payload = {
'clientKey': api_key,
'task': {
'type': 'ImageToTextTask',
'image': image_base64,
'subType': sub_type
}
}
response = requests.post(create_task_url, json=create_task_payload)
result = response.json()
if result['errorId'] != 0:
raise Exception(result['errorDescription'])
task_id = result['taskId']
# 步骤 2:获取结果
get_result_url = 'https://api.achicaptcha.com/getTaskResult'
while True:
time.sleep(2) # 等待 2 秒
get_result_payload = {
'clientKey': api_key,
'taskId': task_id
}
response = requests.post(get_result_url, json=get_result_payload)
result = response.json()
if result['errorId'] != 0:
raise Exception(result['errorDescription'])
if result['status'] == 'ready':
return result['solution']
# 如果 status == 'processing',继续循环
# 使用
solution = solve_captcha('captcha.png', 'common', 'YOUR_API_KEY')
print('验证码结果:', solution)常见错误代码
| 错误代码 | 描述 | 注释 |
|---|---|---|
| 0 | success | 成功 |
| 1 | processing | 正在处理 |
| 2 | missing required fields | 缺少必需字段,检查参数 |
| 3 | task not supported | 不支持的任务类型 |
| 4 | task creation failed | 创建任务失败 |
| 5 | client key does not exist | API 密钥不存在,检查 API 密钥 |
| 6 | insufficient account balance | 账户余额不足,充值积分 |
| 7 | task failed, please create a new task | 任务失败,请创建新任务 |
| 8 | task ID does not exist | 任务 ID 不存在 |
最佳实践
为了在使用 Achicaptcha API 时获得最佳效果,请遵循以下原则:
1. 图像质量
- 使用具有良好分辨率的图像
- 确保图像不会过度模糊或有噪声
- 选择适合验证码类型的正确
subType
2. 轮询间隔
- 在结果检查之间至少等待 2 秒
- 不要用太多连续请求轰炸 API
- 设置超时以避免无限循环
3. 重试逻辑
- 为临时错误(如
ERROR_NO_SLOT_AVAILABLE)实施重试 - 重试时使用指数退避
- 限制最大重试次数
4. API 密钥安全
- 不要在代码中硬编码 API 密钥
- 使用环境变量
- 不要在客户端暴露 API 密钥
有用的链接: