0qwertyy/capsolver-php

PHP package for easy integration with CapSolver API

dev-master 2024-07-27 23:00 UTC

This package is auto-updated.

Last update: 2024-10-27 23:32:28 UTC


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 0qwertyy/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

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/