1. Go to this page and download the library: Download gladyshev/rucaptcha-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gladyshev / rucaptcha-client example snippets
" ...
"gladyshev/rucaptcha-client": "*"
...
}
/* Simple */
$rucaptcha = new Rucaptcha\Client(
Rucaptcha\Config::fromApiKey(getenv('__RUCAPTCHA_KEY__')),
new GuzzleHttp\Client() // Any PSR-18 HTTP-client
);
$captchaText = $rucaptcha->recognizeFile('captcha.png');
print_r($captchaText); // h54g6
/* Advanced example */
$rucaptcha = new \Rucaptcha\Client(
\Rucaptcha\Config::fromApiKey('YOUR_API_KEY'),
new \GuzzleHttp\Client(['base_uri' => 'https://2captcha.com']),
new \Monolog\Logger('2Captcha', [new \Monolog\Handler\StreamHandler('php://stdout')])
);
$taskIds = [];
$taskIds[] = $rucaptcha->sendCaptcha(file_get_contents('captcha1.png'));
$taskIds[] = $rucaptcha->sendCaptcha(file_get_contents('captcha2.jpg'));
$taskIds[] = $rucaptcha->sendCaptcha(file_get_contents('captcha3.gif'), [
Rucaptcha\Extra::NUMERIC => 1
]);
$results = [];
while (count($taskIds) > 0)
{
// Try get results
foreach ($taskIds as $i=>$taskId)
{
// Wait 5 sec
sleep(5);
$results[$taskId] = $rucaptcha->getCaptchaResult($taskId);
// false === is not ready, on error we've got an exception
if ($results[$taskId] === false) {
continue;
} else {
unset($taskIds[$i]);
}
}
}
print_r($results);