|
| 1 | +- [Installation](#installation) |
| 2 | + - [Composer](#composer) |
| 3 | + - [Manual](#manual) |
| 4 | +- [Configuration](#configuration) |
| 5 | +- [Solve captcha](#solve-captcha) |
| 6 | + - [Normal Captcha](#normal-captcha) |
| 7 | + - [Text](#text-captcha) |
| 8 | + - [ReCaptcha v2](#recaptcha-v2) |
| 9 | + - [ReCaptcha v3](#recaptcha-v3) |
| 10 | + - [FunCaptcha](#funcaptcha) |
| 11 | + - [GeeTest](#geetest) |
| 12 | + - [hCaptcha](#hcaptcha) |
| 13 | + - [KeyCaptcha](#keycaptcha) |
| 14 | + - [Capy](#capy) |
| 15 | + - [Grid (ReCaptcha V2 Old Method)](#grid) |
| 16 | + - [Canvas](#canvas) |
| 17 | + - [ClickCaptcha](#clickcaptcha) |
| 18 | + - [Rotate](#rotate) |
| 19 | +- [Other methods](#other-methods) |
| 20 | + - [send / getResult](#send--getresult) |
| 21 | + - [balance](#balance) |
| 22 | + - [report](#report) |
| 23 | +- [Error handling](#error-handling) |
| 24 | + |
| 25 | + |
| 26 | +## Installation |
| 27 | +This package can be installed via composer or manually |
| 28 | + |
| 29 | +### Composer |
| 30 | +``` |
| 31 | +composer require 2captcha/2captcha-php |
| 32 | +``` |
| 33 | + |
| 34 | +### Manual |
| 35 | +Copy `src` directory to your project and then `require` autoloader (`src/autoloader.php`) where needed: |
| 36 | +```php |
| 37 | +require 'path/to/autoloader.php'; |
| 38 | +``` |
| 39 | + |
| 40 | +## Configuration |
| 41 | +`TwoCaptcha` instance can be created like this: |
| 42 | +```php |
| 43 | +$solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY'); |
| 44 | +``` |
| 45 | +Also there are few options that can be configured: |
| 46 | +```php |
| 47 | +$solver = new \TwoCaptcha\TwoCaptcha([ |
| 48 | + 'apiKey' => 'YOUR_API_KEY', |
| 49 | + 'softId' => 123, |
| 50 | + 'callback' => 'https://your.site/result-receiver', |
| 51 | + 'defaultTimeout' => 120, |
| 52 | + 'recaptchaTimeout' => 600, |
| 53 | + 'pollingInterval' => 10, |
| 54 | +]); |
| 55 | +``` |
| 56 | + |
| 57 | +## Solve captcha |
| 58 | +Below shown only base examples for every captcha type. Check out `examples` directory to find more examples with all available options. |
| 59 | + |
| 60 | +### Normal Captcha |
| 61 | +```php |
| 62 | +$result = $solver->normal('path/to/captcha.jpg'); |
| 63 | +``` |
| 64 | +### Text Captcha |
| 65 | +```php |
| 66 | +$result = $solver->text('If tomorrow is Saturday, what day is today?'); |
| 67 | +``` |
| 68 | +### ReCaptcha v2 |
| 69 | +```php |
| 70 | +$result = $solver->recaptcha([ |
| 71 | + 'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', |
| 72 | + 'url' => 'https://mysite.com/page/with/recaptcha', |
| 73 | +]); |
| 74 | +``` |
| 75 | +### ReCaptcha v3 |
| 76 | +```php |
| 77 | +$result = $solver->recaptcha([ |
| 78 | + 'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', |
| 79 | + 'url' => 'https://mysite.com/page/with/recaptcha', |
| 80 | + 'version' => 'v3', |
| 81 | +]); |
| 82 | +``` |
| 83 | +### FunCaptcha |
| 84 | +```php |
| 85 | +$result = $solver->funcaptcha([ |
| 86 | + 'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-', |
| 87 | + 'url' => 'https://mysite.com/page/with/funcaptcha', |
| 88 | +]); |
| 89 | +``` |
| 90 | +### GeeTest |
| 91 | +```php |
| 92 | +$result = $solver->geetest([ |
| 93 | + 'gt' => 'f1ab2cdefa3456789012345b6c78d90e', |
| 94 | + 'challenge' => '12345678abc90123d45678ef90123a456b', |
| 95 | + 'url' => 'https://www.site.com/page/', |
| 96 | +]); |
| 97 | +``` |
| 98 | +### hCaptcha |
| 99 | +```php |
| 100 | +$result = $solver->funcaptcha([ |
| 101 | + 'sitekey' => 'f1ab2cdefa3456789012345b6c78d90e', |
| 102 | + 'challenge' => '12345678abc90123d45678ef90123a456b', |
| 103 | + 'url' => 'https://www.site.com/page/', |
| 104 | +]); |
| 105 | +``` |
| 106 | +### KeyCaptcha |
| 107 | +```php |
| 108 | +$result = $solver->keycaptcha([ |
| 109 | + 's_s_c_user_id' => 10, |
| 110 | + 's_s_c_session_id' => '493e52c37c10c2bcdf4a00cbc9ccd1e8', |
| 111 | + 's_s_c_web_server_sign' => '9006dc725760858e4c0715b835472f22-pz-', |
| 112 | + 's_s_c_web_server_sign2' => '2ca3abe86d90c6142d5571db98af6714', |
| 113 | + 'url' => 'https://www.keycaptcha.ru/demo-magnetic/', |
| 114 | +]); |
| 115 | +``` |
| 116 | +### Capy |
| 117 | +```php |
| 118 | +$result = $solver->capy([ |
| 119 | + 'sitekey' => 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v', |
| 120 | + 'url' => 'http://mysite.com/', |
| 121 | +]); |
| 122 | +``` |
| 123 | +### Grid |
| 124 | +```php |
| 125 | +$result = $solver->grid('path/to/captcha.jpg'); |
| 126 | +``` |
| 127 | +### Canvas |
| 128 | +```php |
| 129 | +$result = $solver->canvas('path/to/captcha.jpg'); |
| 130 | +``` |
| 131 | +### ClickCaptcha |
| 132 | +```php |
| 133 | +$result = $solver->coordinates('path/to/captcha.jpg'); |
| 134 | +``` |
| 135 | +### Rotate |
| 136 | +```php |
| 137 | +$result = $solver->rotate('path/to/captcha.jpg'); |
| 138 | +``` |
| 139 | + |
| 140 | +## Other methods |
| 141 | + |
| 142 | +### send / getResult |
| 143 | +```php |
| 144 | +$id = $solver->send(['file' => 'path/to/captcha.jpg', ...]); |
| 145 | + |
| 146 | +sleep(20); |
| 147 | + |
| 148 | +$code = $solver->getResult($id); |
| 149 | +``` |
| 150 | +### balance |
| 151 | +```php |
| 152 | +$balance = $solver->balance(); |
| 153 | +``` |
| 154 | +### report |
| 155 | +```php |
| 156 | +$solver->report($id, true); // captcha solved correctly |
| 157 | +$solver->report($id, false); // captcha solved incorrectly |
| 158 | +``` |
| 159 | + |
| 160 | +## Error handling |
| 161 | +```php |
| 162 | +try { |
| 163 | + $result = $solver->text('If tomorrow is Saturday, what day is today?'); |
| 164 | +} catch (\TwoCaptcha\Exception\ValidationException $e) { |
| 165 | + // invalid parameters passed |
| 166 | +} catch (\TwoCaptcha\Exception\NetworkException $e) { |
| 167 | + // network error occurred |
| 168 | +} catch (\TwoCaptcha\Exception\ApiException $e) { |
| 169 | + // api respond with error |
| 170 | +} catch (\TwoCaptcha\Exception\TimeoutException $e) { |
| 171 | + // captcha is not solved so far |
| 172 | +} |
| 173 | +``` |
0 commit comments