The easiest way to quickly integrate CapSolver captcha solving service into your code to automate solving of any types of captcha.
This package can be installed via composer or manually
composer require 0qwertyy/capsolver-php:dev-master
Copy src
directory to your project and then require
autoloader (src/autoloader.php
) where needed:
require 'path/to/autoloader.php';
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,
]);
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
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
]);
These methods can be used for manual captcha submission and answer polling.
$id = $solver->send(['type' => 'HCaptchaTask', ...]);
sleep(20);
$code = $solver->getResult($id);
Use this method to get your account's balance
$balance = $solver->balance();
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
}
Figure out all the working examples here.