Skip to content

Commit eaa7b8f

Browse files
author
2Captcha
committed
v1.0.0
0 parents  commit eaa7b8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4143
-0
lines changed

.gitignore

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#PHP and development related
2+
.idea
3+
/vendor
4+
5+
# Mac OS General
6+
.DS_Store
7+
.AppleDouble
8+
.LSOverride
9+
10+
# Icon must end with two \r
11+
Icon
12+
13+
14+
# Thumbnails
15+
._*
16+
17+
# Files that might appear in the root of a volume
18+
.DocumentRevisions-V100
19+
.fseventsd
20+
.Spotlight-V100
21+
.TemporaryItems
22+
.Trashes
23+
.VolumeIcon.icns
24+
.com.apple.timemachine.donotpresent
25+
26+
# Directories potentially created on remote AFP share
27+
.AppleDB
28+
.AppleDesktop
29+
Network Trash Folder
30+
Temporary Items
31+
.apdisk
32+
33+
34+
# Windows thumbnail cache files
35+
Thumbs.db
36+
Thumbs.db:encryptable
37+
ehthumbs.db
38+
ehthumbs_vista.db
39+
40+
# Dump file
41+
*.stackdump
42+
43+
# Folder config file
44+
[Dd]esktop.ini
45+
46+
# Recycle Bin used on file shares
47+
$RECYCLE.BIN/
48+
49+
# Windows Installer files
50+
*.cab
51+
*.msi
52+
*.msix
53+
*.msm
54+
*.msp
55+
56+
# Windows shortcuts
57+
*.lnk
58+
59+
# Linux possible garbage
60+
*~
61+
62+
# temporary files which can be created if a process still has a handle open of a deleted file
63+
.fuse_hidden*
64+
65+
# KDE directory preferences
66+
.directory
67+
68+
# Linux trash folder which might appear on any partition or disk
69+
.Trash-*
70+
71+
# .nfs files are created when an open file is removed but is still being accessed
72+
.nfs*

README.md

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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+
```

composer.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "2captcha/2captcha",
3+
"description": "Solve any captcha (image, recaptcha, click, rotate and other)",
4+
"keywords": [
5+
"2captcha",
6+
"captcha",
7+
"recaptcha"
8+
],
9+
"authors": [
10+
{
11+
"name": "2captcha",
12+
"email": "[email protected]",
13+
"homepage": "https://2captcha.com/"
14+
}
15+
],
16+
"require": {
17+
"php": ">=5.6",
18+
"ext-curl": "*",
19+
"ext-mbstring": "*",
20+
"ext-fileinfo": "*"
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "8.5.*"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"TwoCaptcha\\": "src/"
28+
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"TwoCaptcha\\Tests\\": "tests/"
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)