PHP code example of zaman-ua / 2captcha
1. Go to this page and download the library: Download zaman-ua/2captcha 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/ */
zaman-ua / 2captcha example snippets
$solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY');
$solver = new \TwoCaptcha\TwoCaptcha([
'server' => 'http://rucaptcha.com',
'apiKey' => 'YOUR_API_KEY',
'softId' => 123,
'callback' => 'https://your.site/result-receiver',
'defaultTimeout' => 120,
'recaptchaTimeout' => 600,
'pollingInterval' => 10,
]);
$result = $solver->normal('path/to/captcha.jpg');
$result = $solver->text('If tomorrow is Saturday, what day is today?');
$result = $solver->recaptcha([
'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
'url' => 'https://mysite.com/page/with/recaptcha',
]);
$result = $solver->recaptcha([
'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
'url' => 'https://mysite.com/page/with/recaptcha',
'version' => 'v3',
]);
$result = $solver->funcaptcha([
'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
'url' => 'https://mysite.com/page/with/funcaptcha',
]);
$result = $solver->geetest([
'gt' => 'f1ab2cdefa3456789012345b6c78d90e',
'challenge' => '12345678abc90123d45678ef90123a456b',
'url' => 'https://www.site.com/page/',
]);
$result = $solver->hcaptcha([
'sitekey' => '10000000-ffff-ffff-ffff-000000000001',
'url' => 'https://www.site.com/page/',
]);
$result = $solver->keycaptcha([
's_s_c_user_id' => 10,
's_s_c_session_id' => '493e52c37c10c2bcdf4a00cbc9ccd1e8',
's_s_c_web_server_sign' => '9006dc725760858e4c0715b835472f22-pz-',
's_s_c_web_server_sign2' => '2ca3abe86d90c6142d5571db98af6714',
'url' => 'https://www.keycaptcha.ru/demo-magnetic/',
]);
$result = $solver->capy([
'sitekey' => 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',
'url' => 'http://mysite.com/',
'api_server' => 'https://jp.api.capy.me/',
]);
$result = $solver->grid('path/to/captcha.jpg');
$result = $solver->canvas('path/to/captcha.jpg');
$result = $solver->coordinates('path/to/captcha.jpg');
$result = $solver->rotate('path/to/captcha.jpg');
$id = $solver->send(['file' => 'path/to/captcha.jpg', ...]);
sleep(20);
$code = $solver->getResult($id);
$balance = $solver->balance();
$solver->report($id, true); // captcha solved correctly
$solver->report($id, false); // captcha solved incorrectly
try {
$result = $solver->text('If tomorrow is Saturday, what day is today?');
} catch (\TwoCaptcha\Exception\ValidationException $e) {
// invalid parameters passed
} catch (\TwoCaptcha\Exception\NetworkException $e) {
// network error occurred
} catch (\TwoCaptcha\Exception\ApiException $e) {
// api respond with error
} catch (\TwoCaptcha\Exception\TimeoutException $e) {
// captcha is not solved so far
}