Skip to content
API
Shopee验证码

Shopee 验证码

概述

Shopee 验证码是 Shopee 使用的验证码系统,用于保护用户和系统免受异常行为(如机器人、垃圾邮件或自动登录)的影响。

Achicaptcha 支持为多种不同平台(浏览器、模拟器、手机)自动解决 Shopee 验证码。请参阅下面的指南来集成 API。

🛍️

对于 Shopee 的文字验证码,请参考 文字验证码。如有问题,请联系 管理员 (opens in a new tab) 获取支持。

Shopee 滑块验证码 1Shopee 滑块验证码 2

1. 创建任务

请求

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

参数

参数名数据类型必需?描述
clientKeystringyesAPI 密钥
task.typestringyesShopeeCaptchaTask
task.imagestringyes掩码图像的 Base64|背景图像的 Base64
task.subTypeintyes验证码类型:
0:滑块验证码

请求示例

POST /createTask HTTP/1.1
Host: api.achicaptcha.com
Content-Type: application/json
 
{
  "clientKey": "YOUR_API_KEY",
  "task": {
    "type": "ShopeeCaptchaTask",
    "image": "/9j/4AAQSkZJRgABAQEASABIAAD...|/9j/4DSJFHKSDJDS...",
    "subType": 0
  }
}

响应

成功时,服务器将返回 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": "x1,y1,x2,y2"
}

返回结果的含义

  • errorId = 0status = ready:解决成功,在 solution 中读取结果
  • errorId = 1status = processing:正在解决验证码,等待 1-2 秒后重试
  • errorId 非 0 和 1:系统错误,返回错误代码和错误描述
  • solution:对于滑块验证码:返回需要沿图像 x 轴拖动的坐标

集成示例

import requests
import time
 
def solve_shopee_captcha(mask_image, bg_image, sub_type, api_key='YOUR_API_KEY'):
    # 步骤 1:创建任务
    create_task_url = 'https://api.achicaptcha.com/createTask'
    create_task_payload = {
        'clientKey': api_key,
        'task': {
            'type': 'ShopeeCaptchaTask',
            'image': mask_image + '|' + bg_image,
            '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 and result['status'] == 'ready':
            return result['solution']
        
        if result['errorId'] != 0 and result['errorId'] != 1:
            raise Exception(result['errorDescription'])
        
        # 如果 status == 'processing',继续循环
 
# 使用
mask_image = '/9j/4AAQSkZJRgABAQEASABIAAD...'  # 掩码图像的 Base64
bg_image = '/9j/4DSJFHKSDJDS...'  # 背景图像的 Base64
sub_type = 0  # 0:滑块验证码
solution = solve_shopee_captcha(mask_image, bg_image, sub_type, 'YOUR_API_KEY')
print('Shopee 验证码解决方案:', solution)

常见错误代码

创建任务时的错误代码

错误代码描述注释
0success创建任务成功
2missing required fields缺少必需字段,检查参数(image、subType)
3task not supported不支持的任务类型
4task creation failed创建任务失败,稍后重试
5client key does not existAPI 密钥不存在,检查 API 密钥
6insufficient account balance账户余额不足,充值积分

获取结果时的错误代码

错误代码描述注释
0success成功,在 solution 字段中读取结果
1processing正在处理,等待 1-2 秒后重新发送请求
5client key does not existAPI 密钥不存在,检查 API 密钥
7task failed, please create a new task任务失败,请创建新任务
8task ID does not exist任务 ID 不存在或已过期

最佳实践

为了在使用 Achicaptcha API 解决 Shopee 验证码时获得最佳效果,请遵循以下原则:

1. 准备 Base64 图像

  • 将掩码和背景图像转换为 Base64 格式
  • 确保图像质量清晰以提高准确性
  • 使用 |(管道)字符连接两个图像

2. 轮询间隔

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

3. 错误处理

  • 检查 errorId 以检测错误
  • errorId = 0status = ready:成功
  • errorId = 1:正在处理,继续轮询
  • errorId 非 0 和 1:系统错误,需要处理

4. 重试逻辑

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

5. API 密钥安全

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

有用的链接: