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
37 changes: 37 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 [C# ca
- [DataDome](#datadome)
- [atbCAPTCHA](#atbcaptcha)
- [Tencent](#tencent)
- [VK Image](#vk-image)
- [VK Captcha](#vk-captcha)
- [Other methods](#other-methods)
- [send / getResult](#send--getresult)
- [balance](#balance)
Expand Down Expand Up @@ -488,6 +490,41 @@ tencent.SetAppId("190014885");
tencent.SetPageUrl("https://www.example.com/");
```

### 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.

```csharp
TwoCaptcha solver = new TwoCaptcha(apiKey);

byte[] bytes = File.ReadAllBytes("resources/vk.jpg");
string base64EncodedImage = Convert.ToBase64String(bytes);

VkCaptcha captcha = new VkCaptcha("vkimage");
captcha.SetBase64(base64EncodedImage);
captcha.SetSteps("[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.

```csharp
VkCaptcha captcha = new VkCaptcha("vkcaptcha");

captcha.SetRedirectUri("https://id.vk.com/not_robot_captcha?domain=vk.com&session_token=eyJ....HGsc5B4LyvjA&variant=popup&blank=1");
captcha.SetuserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36");
captcha.SetProxy("http", "1.2.3.4");
```


## Other methods

Expand Down
8 changes: 8 additions & 0 deletions TwoCaptcha.Examples/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ public static void Main(string[] args)
case "YandexOptionsExample":
YandexOptionsExample YandexOptionsExample = new YandexOptionsExample(apiKey);
break;

case "VkImageExample":
VkImageExample VkImageExample = new VkImageExample(apiKey);
break;

case "VkCaptchaExample":
VkCaptchaExample VkCaptchaExample = new VkCaptchaExample(apiKey);
break;
}
}
}
8 changes: 7 additions & 1 deletion TwoCaptcha.Examples/TwoCaptcha.Examples.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
Expand Down Expand Up @@ -81,5 +81,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Update="resources\vk.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
36 changes: 36 additions & 0 deletions TwoCaptcha.Examples/VkCaptchaExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.IO;
using System.Linq;
using TwoCaptcha.Captcha;
using static System.Net.Mime.MediaTypeNames;

namespace TwoCaptcha.Examples
{
public class VkCaptchaExample
{
public VkCaptchaExample(string apiKey)
{
TokenBased(apiKey);
}

private void TokenBased(string apiKey)
{
TwoCaptcha solver = new TwoCaptcha(apiKey);

VkCaptcha captcha = new VkCaptcha("vkcaptcha");

captcha.SetRedirectUri("https://id.vk.com/not_robot_captcha?domain=vk.com&session_token=eyJ....HGsc5B4LyvjA&variant=popup&blank=1");
captcha.SetuserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36");
captcha.SetProxy("http", "1.2.3.4");
try
{
solver.Solve(captcha).Wait();
Console.WriteLine("Captcha solved: " + captcha.Code);
}
catch (AggregateException e)
{
Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message);
}
}
}
}
38 changes: 38 additions & 0 deletions TwoCaptcha.Examples/VkImageExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.IO;
using System.Linq;
using TwoCaptcha.Captcha;
using static System.Net.Mime.MediaTypeNames;

namespace TwoCaptcha.Examples
{
public class VkImageExample
{
public VkImageExample(string apiKey)
{
ImageBased(apiKey);
}

private void ImageBased(string apiKey)
{
TwoCaptcha solver = new TwoCaptcha(apiKey);

byte[] bytes = File.ReadAllBytes("resources/vk.jpg");
string base64EncodedImage = Convert.ToBase64String(bytes);

VkCaptcha captcha = new VkCaptcha("vkimage");
captcha.SetBase64(base64EncodedImage);
captcha.SetSteps("[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]");

try
{
solver.Solve(captcha).Wait();
Console.WriteLine("Captcha solved: " + captcha.Code);
}
catch (AggregateException e)
{
Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message);
}
}
}
}
Binary file added TwoCaptcha.Examples/resources/vk.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions TwoCaptcha.Tests/VkCaptchaTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using TwoCaptcha.Captcha;
using static System.Net.Mime.MediaTypeNames;

namespace TwoCaptcha.Tests
{
[TestFixture]
public class VkCaptchaTest : AbstractWrapperTestCase
{
[Test]
public async Task TestAllParameters()
{
VkCaptcha captcha = new VkCaptcha("vkcaptcha");
captcha.SetSiteKey("0x4AAAAAAAChNiVJM_WtShFf");
captcha.SetUrl("https://ace.fusionist.io");

var parameters = new Dictionary<string, string>();
parameters["method"] = "vkcaptcha";
parameters["soft_id"] = "4582";
parameters["pageurl"] = "https://ace.fusionist.io";
parameters["sitekey"] = "0x4AAAAAAAChNiVJM_WtShFf";

await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
}
}
}
33 changes: 33 additions & 0 deletions TwoCaptcha.Tests/VkImageTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using TwoCaptcha.Captcha;
using static System.Net.Mime.MediaTypeNames;

namespace TwoCaptcha.Tests
{
[TestFixture]
public class VkImageTest : AbstractWrapperTestCase
{
[Test]
public async Task TestAllParameters()
{
byte[] bytes = File.ReadAllBytes("../../../resources/vk.jpg");
string base64EncodedImage = Convert.ToBase64String(bytes);

VkCaptcha captcha = new VkCaptcha("vkimage");
captcha.SetBase64(base64EncodedImage);
captcha.SetSteps("[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]");

var parameters = new Dictionary<string, string>();
parameters["method"] = "vkimage";
parameters["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]";
parameters["body"] = base64EncodedImage;
parameters["soft_id"] = "4582";

await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
}
}
}
Binary file added TwoCaptcha.Tests/resources/vk.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions TwoCaptcha/Captcha/Captcha.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,15 @@ public Dictionary<string, FileInfo> GetFiles()
{
return new Dictionary<string, FileInfo>(files);
}

public void SetSiteKey(String siteKey)
{
parameters["sitekey"] = siteKey;
}

public void SetUrl(String url)
{
parameters["pageurl"] = url;
}
}
}
51 changes: 51 additions & 0 deletions TwoCaptcha/Captcha/VkCaptcha.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Buffers.Text;
using System.Collections.Generic;
using System.IO;

namespace TwoCaptcha.Captcha
{
public class VkCaptcha : Captcha
{
public VkCaptcha(String method) : base()
{
parameters["method"] = method;
}

public void SetSteps(String steps)
{
parameters["steps"] = steps;
}

public void SetBase64(String base64)
{
parameters["body"] = base64;
}

public void SetRedirectUri(String redirect_uri)
{
parameters["redirect_uri"] = redirect_uri;
}

public void SetuserAgent(String userAgent)
{
parameters["userAgent"] = userAgent;
}

public void SetFile(string filePath)
{
SetFile(new FileInfo(filePath));
}

public void SetFile(FileInfo file)
{
files["file"] = file;
}
}
}