Skip to content
API
文本验证码

文字验证码

概述

文字验证码是一种包含扭曲但人类可读的文本的图像。要解决验证码图像,用户必须输入图像中的文本。

📝

文字验证码可以包括数字、字母或两者的组合。它们通常使用图像变形、噪声和各种字体使自动读取变得困难。

常见文字验证码

1. 创建任务

请求

POST https://api.achicaptcha.com/createTask

参数

参数名数据类型必需?描述
clientKeystringyesAPI 密钥
task.typestringyesImageToTextTask
task.imagestringyes图像的 base64
task.subTypestringyes是以下类型之一:commonamazonmicrosoftfacebookgarenaartistshotgmx11166houssam

请求示例

POST /createTask HTTP/1.1
Host: api.achicaptcha.com
Content-Type: application/json
 
{
  "clientKey": "您的 API_KEY",
  "task": {
    "type": "ImageToTextTask",
    "image": "图像的 base64 编码",
    "subType": "gmx"
  }
}

响应

成功时,服务器将返回 errorId = 0taskId

{
  "errorId": 0,
  "taskId": "f2fc70d6-c76b-4fba-9480-205ac1fe9fb9"
}

2. 获取结果

请求

POST https://api.achicaptcha.com/getTaskResult

参数

参数名数据类型必需?描述
clientKeystringyesAPI 密钥
taskIdstringyes从 (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 = 0status = ready:解决成功,在 solution.text 中读取结果
  • errorId = 0status = processing:正在解决验证码,等待 2 秒后重试
  • errorId > 0:系统错误,返回错误代码和错误描述

SubType 类型

Achicaptcha 通过 subType 参数支持多种不同类型的文字验证码:

SubType描述
common普通文字验证码,最常见
amazonAmazon 的特定验证码,具有特殊扭曲
microsoftMicrosoft 服务上使用的验证码
facebookFacebook 的验证码,具有特征性字体
garenaGarena 平台上的验证码
artistshotArtistshot 网站的验证码
gmxGMX 电子邮件验证码
11166代码为 11166 的特殊验证码类型
houssam名为 Houssam 的特定验证码类型
discordDiscord 的特定验证码类型
okvipokvip 的特定验证码类型
shopeeshopee 的特定验证码类型
📝

通常 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)

常见错误代码

错误代码描述注释
0success成功
1processing正在处理
2missing required fields缺少必需字段,检查参数
3task not supported不支持的任务类型
4task creation failed创建任务失败
5client key does not existAPI 密钥不存在,检查 API 密钥
6insufficient account balance账户余额不足,充值积分
7task failed, please create a new task任务失败,请创建新任务
8task ID does not exist任务 ID 不存在

最佳实践

为了在使用 Achicaptcha API 时获得最佳效果,请遵循以下原则:

1. 图像质量

  • 使用具有良好分辨率的图像
  • 确保图像不会过度模糊或有噪声
  • 选择适合验证码类型的正确 subType

2. 轮询间隔

  • 在结果检查之间至少等待 2 秒
  • 不要用太多连续请求轰炸 API
  • 设置超时以避免无限循环

3. 重试逻辑

  • 为临时错误(如 ERROR_NO_SLOT_AVAILABLE)实施重试
  • 重试时使用指数退避
  • 限制最大重试次数

4. API 密钥安全

  • 不要在代码中硬编码 API 密钥
  • 使用环境变量
  • 不要在客户端暴露 API 密钥

有用的链接: