brenoleite8/capsolver-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

brenoleite8/capsolver-php

Composer 安装命令:

composer require brenoleite8/capsolver-php

包简介

PHP package for easy integration with CapSolver API

README 文档

README

The easiest way to quickly integrate [CapSolver] captcha solving service into your code to automate solving of any types of captcha.

Installation

This package can be installed via composer or manually

Composer

composer require brenoleite8/capsolver-php:dev-master

Manual

Copy src directory to your project and then require autoloader (src/autoloader.php) where needed:

require 'path/to/autoloader.php';

Configuration

CapSolver instance can be created like this:

$solver = new \CapSolver\CapSolver('CAI-XXX...');

Also there are few options that can be configured:

$solver = new \CapSolver\CapSolver([
    'apiKey'           => 'CAI-XXX...',
    'defaultTimeout'   => 120,
    'recaptchaTimeout' => 600,
    'pollingInterval'  => 10,
]);

CapSolver instance options

Option Default value Description
defaultTimeout 120 Polling timeout in seconds for all captcha types except ReCaptcha. Defines how long the module tries to get the answer from getTaskResult API endpoint
recaptchaTimeout 600 Polling timeout for ReCaptcha in seconds. Defines how long the module tries to get the answer from getTaskResult API endpoint
pollingInterval 10 Interval in seconds between requests to getTaskResult API endpoint, setting values less than 5 seconds is not recommended

To get the answer manually use getResult method

Solve a captcha

Call example

Use this method to solve ReCaptcha V2 and obtain a token to bypass the protection.

$result = $solver->recaptchav2([
        'websiteKey'    => 'XxX-XXXXXXxXXXXXXXXXXxXXXXX',                   // grab it from target site
        'websiteURL'    => 'https://www.mysite.com/recaptcha/api2/demo',    // grab it from target site
        'proxy'         => 'proxy.provider.io:23331:user1:password1',       // proxy string format
]);

Manual polling

send / getResult

These methods can be used for manual captcha submission and answer polling.

$id = $solver->send(['type' => 'HCaptchaTask', ...]);
sleep(20);

$code = $solver->getResult($id);

balance

Use this method to get your account's balance

$balance = $solver->balance();

Error handling

If case of an error captcha solver throws an exception. It's important to properly handle these cases. We recommend to use try catch to handle exceptions.

try {
    $result = $solver->recaptchav2([
            'websiteKey'    => 'XxX-XXXXXXxXXXXXXXXXXxXXXXX',                   // grab it from target site
            'websiteURL'    => 'https://www.mysite.com/recaptcha/api2/demo',    // grab it from target site
            'proxy'         => 'proxy.provider.io:23331:user1:password1',       // proxy string format
    ]);
} catch (\CapSolver\Exception\ValidationException $e) {
    // invalid parameters passed
} catch (\CapSolver\Exception\NetworkException $e) {
    // network error occurred
} catch (\CapSolver\Exception\ApiException $e) {
    // api respond with error
} catch (\CapSolver\Exception\TimeoutException $e) {
    // captcha is not solved so far
}

📁 Examples directory

Figure out all the working examples here. [CapSolver]: https://capsolver.com/

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-27