Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Examples of API requests for different captcha types are available on the [PHP c
- [atbCAPTCHA](#atbcaptcha)
- [DataDome](#datadome)
- [CyberSiARA](#cybersiara)
- [VK Captcha](#vk-captcha)
- [VK Image](#vk-image)
- [Other methods](#other-methods)
- [send / getResult](#send--getresult)
- [balance](#balance)
Expand Down Expand Up @@ -444,6 +446,38 @@ $result = $solver->cybersiara([
]);
```

### VK Image

<sup>[API method description.](https://2captcha.com/2captcha-api#vkcaptcha)</sup>

We offer two methods to solve this type of captcha - token-based and image-based.

We use the body (image in base64 format) or file (image as file) and steps parameters.
You can get both values from the response to the request https://api.vk.com/method/captchaNotRobot.getContent?v={API_VER} when loading the captcha widget on the page.

```php
$result = $solver->vkImage([
'body' => base64_encode(file_get_contents(__DIR__ . '/images/vk.jpg')),
'steps' => '[5,12,22,24,21,23,10,7,2,8,19,18,8,24,21,22,11,14,16,5,18,20,4,21,12,6,0,0,11,12,8,20,19,3,14,8,9,13,16,24,18,3,2,23,8,12,6,1,11,0,20,15,19,22,17,24,8,0,12,5,19,14,11,6,7,14,23,24,23,20,4,20,6,12,4,17,4,18,6,20,17,5,23,7,10,2,8,9,5,4,17,24,11,14,4,10,12,22,21,2]',
]);
```
### VK Captcha

<sup>[API method description.](https://2captcha.com/2captcha-api#vk-captcha)</sup>

Token-based method requires redirect_uri parameter, as well as proxy and userAgent. The value of the redirect_uri parameter can be found in the response to requests to the VK API that return captchas.

```php
$tokenBasedResult = $solver->vkCaptcha([
'redirect_uri' => 'https://id.vk.com/not_robot_captcha?domain=vk.com&session_token=eyJ....HGsc5B4LyvjA&variant=popup&blank=1',
'userAgent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36',
'proxy' => [
'type' => 'HTTPS',
'uri' => 'login:password@IP_address:PORT',
],
]);
```


## Other methods

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"Cutcaptcha",
"Friendly Captcha",
"atbCAPTCHA",
"DataDome"
"DataDome",
"vkCaptcha",
"vkImage"
],
"license": "MIT",
"authors": [
Expand Down
Binary file added examples/images/vk.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/rotate_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require(__DIR__ . '/../src/autoloader.php');

$solver = new \TwoCaptcha\TwoCaptcha([
'apiKey' => 'YOUR_API_KEY',
'apiKey' => $argv[1],
'server' => 'http://2captcha.com'
]);

Expand Down
3 changes: 2 additions & 1 deletion examples/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

require(__DIR__ . '/../src/autoloader.php');

$solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY');
//$argv[1] = YOUR_API_KEY
$solver = new \TwoCaptcha\TwoCaptcha($argv[1]);

try {
$result = $solver->text('If tomorrow is Saturday, what day is today?');
Expand Down
29 changes: 29 additions & 0 deletions examples/vk_captcha.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use TwoCaptcha\TwoCaptcha;

set_time_limit(610);

require(__DIR__ . '/../src/autoloader.php');

//$argv[1] = YOUR_API_KEY
$solver = new TwoCaptcha($argv[1]);

try {

$tokenBasedResult = $solver->vkCaptcha([
'redirect_uri' => 'https://id.vk.com/not_robot_captcha?domain=vk.com&session_token=eyJ....HGsc5B4LyvjA&variant=popup&blank=1',
'userAgent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36',
'proxy' => [
'type' => 'HTTPS',
'uri' => 'login:password@IP_address:PORT',
],
]);

echo 'TokenBasedResult Captcha solved: ' . $tokenBasedResult->code;

} catch (\Exception $e) {
die($e->getMessage());
}

die('Captcha solved: ' . $result->code);
22 changes: 22 additions & 0 deletions examples/vk_image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use TwoCaptcha\TwoCaptcha;

set_time_limit(610);

require(__DIR__ . '/../src/autoloader.php');

//$argv[1] = YOUR_API_KEY
$solver = new TwoCaptcha($argv[1]);

try {
$result = $solver->vkImage([
'body' => base64_encode(file_get_contents(__DIR__ . '/images/vk.jpg')),
'steps' => '[5,12,22,24,21,23,10,7,2,8,19,18,8,24,21,22,11,14,16,5,18,20,4,21,12,6,0,0,11,12,8,20,19,3,14,8,9,13,16,24,18,3,2,23,8,12,6,1,11,0,20,15,19,22,17,24,8,0,12,5,19,14,11,6,7,14,23,24,23,20,4,20,6,12,4,17,4,18,6,20,17,5,23,7,10,2,8,9,5,4,17,24,11,14,4,10,12,22,21,2]',
]);

} catch (\Exception $e) {
die($e->getMessage());
}

die('Captcha solved: ' . $result->code);
34 changes: 34 additions & 0 deletions src/TwoCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,40 @@ public function cybersiara($captcha)
return $this->solve($captcha);
}

/**
* Wrapper for solving vk captcha (image)
*
* @param $captcha
* @return \stdClass
* @throws ApiException
* @throws NetworkException
* @throws TimeoutException
* @throws ValidationException
*/
public function vkimage($captcha)
{
if (is_string($captcha)) {
if (!file_exists($captcha)) {
throw new ValidationException('File not found (' . $captcha . ')');
}
$body = file_get_contents($captcha);
$body = base64_encode($body);
$captcha = [
'body' => $body,
];
}

$captcha['method'] = 'vkimage';
return $this->solve($captcha);
}

public function vkcaptcha($captcha)
{
$captcha['method'] = 'vkcaptcha';

return $this->solve($captcha);
}

/**
* Sends captcha to `/in.php` and waits for it's result.
* This helper can be used insted of manual using of `send` and `getResult` functions.
Expand Down
34 changes: 34 additions & 0 deletions tests/VkCaptchaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace TwoCaptcha\Tests;

class VkCaptchaTest extends AbstractWrapperTestCase
{
protected $method = 'vkcaptcha';

public function testAllOptions()
{
$params = [
'url' => 'https://www.site.com/page/',
'proxy' => [
'type' => 'HTTPS',
'uri' => 'username:str0ngP@$$W0rd@1.2.3.4:4321',

]
];

$sendParams = [
'method' => 'vkcaptcha',
'pageurl' => 'https://www.site.com/page/',
'proxy' => 'username:str0ngP@$$W0rd@1.2.3.4:4321',
'proxytype' => 'HTTPS',
'soft_id' => '4585'
];

$this->checkIfCorrectParamsSendAndResultReturned([
'params' => $params,
'sendParams' => $sendParams,
'sendFiles' => [],
]);
}
}
35 changes: 35 additions & 0 deletions tests/VkImageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace TwoCaptcha\Tests;

class VkImageTest extends AbstractWrapperTestCase
{
protected $method = 'vkimage';


public function testAllParameters()
{
$captchaImg = __DIR__ . '/../examples/images/vk.jpg';

$params = [
'base64' => '...',
'file' => $captchaImg,
];

$sendParams = [
'method' => 'vkimage',
'body' => '...',
'soft_id' => '4585',
];

$sendFiles = [
'file' => $captchaImg,
];

$this->checkIfCorrectParamsSendAndResultReturned([
'params' => $params,
'sendParams' => $sendParams,
'sendFiles' => $sendFiles,
]);
}
}