Skip to content

Commit 6fd0a86

Browse files
victorkowalskivictorkowalski
andauthored
VkImage captcha (#39)
* VkImage captcha * SetSteps * readme updated * vk example * readme updated * setFile() * vk test * readme upd --------- Co-authored-by: victorkowalski <victorkowalski@yandex.ru>
1 parent 3e25741 commit 6fd0a86

11 files changed

Lines changed: 250 additions & 1 deletion

File tree

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Examples of API requests for different captcha types are available on the [C# ca
4343
- [DataDome](#datadome)
4444
- [atbCAPTCHA](#atbcaptcha)
4545
- [Tencent](#tencent)
46+
- [VK Image](#vk-image)
47+
- [VK Captcha](#vk-captcha)
4648
- [Other methods](#other-methods)
4749
- [send / getResult](#send--getresult)
4850
- [balance](#balance)
@@ -488,6 +490,41 @@ tencent.SetAppId("190014885");
488490
tencent.SetPageUrl("https://www.example.com/");
489491
```
490492

493+
### VK Image
494+
495+
<sup>[API method description.](https://2captcha.com/2captcha-api#vkcaptcha)</sup>
496+
497+
We offer two methods to solve this type of captcha - token-based and image-based.
498+
499+
We use the body (image in base64 format) or file (image as file) and steps parameters.
500+
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.
501+
502+
```csharp
503+
TwoCaptcha solver = new TwoCaptcha(apiKey);
504+
505+
byte[] bytes = File.ReadAllBytes("resources/vk.jpg");
506+
string base64EncodedImage = Convert.ToBase64String(bytes);
507+
508+
VkCaptcha captcha = new VkCaptcha("vkimage");
509+
captcha.SetBase64(base64EncodedImage);
510+
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]");
511+
512+
```
513+
514+
### VK Captcha
515+
516+
<sup>[API method description.](https://2captcha.com/2captcha-api#vk-captcha)</sup>
517+
518+
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.
519+
520+
```csharp
521+
VkCaptcha captcha = new VkCaptcha("vkcaptcha");
522+
523+
captcha.SetRedirectUri("https://id.vk.com/not_robot_captcha?domain=vk.com&session_token=eyJ....HGsc5B4LyvjA&variant=popup&blank=1");
524+
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");
525+
captcha.SetProxy("http", "1.2.3.4");
526+
```
527+
491528

492529
## Other methods
493530

TwoCaptcha.Examples/Run.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ public static void Main(string[] args)
198198
case "YandexOptionsExample":
199199
YandexOptionsExample YandexOptionsExample = new YandexOptionsExample(apiKey);
200200
break;
201+
202+
case "VkImageExample":
203+
VkImageExample VkImageExample = new VkImageExample(apiKey);
204+
break;
205+
206+
case "VkCaptchaExample":
207+
VkCaptchaExample VkCaptchaExample = new VkCaptchaExample(apiKey);
208+
break;
201209
}
202210
}
203211
}

TwoCaptcha.Examples/TwoCaptcha.Examples.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22

33
<PropertyGroup>
44
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
@@ -81,5 +81,11 @@
8181
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8282
</None>
8383
</ItemGroup>
84+
85+
<ItemGroup>
86+
<None Update="resources\vk.jpg">
87+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
88+
</None>
89+
</ItemGroup>
8490

8591
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using TwoCaptcha.Captcha;
5+
using static System.Net.Mime.MediaTypeNames;
6+
7+
namespace TwoCaptcha.Examples
8+
{
9+
public class VkCaptchaExample
10+
{
11+
public VkCaptchaExample(string apiKey)
12+
{
13+
TokenBased(apiKey);
14+
}
15+
16+
private void TokenBased(string apiKey)
17+
{
18+
TwoCaptcha solver = new TwoCaptcha(apiKey);
19+
20+
VkCaptcha captcha = new VkCaptcha("vkcaptcha");
21+
22+
captcha.SetRedirectUri("https://id.vk.com/not_robot_captcha?domain=vk.com&session_token=eyJ....HGsc5B4LyvjA&variant=popup&blank=1");
23+
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");
24+
captcha.SetProxy("http", "1.2.3.4");
25+
try
26+
{
27+
solver.Solve(captcha).Wait();
28+
Console.WriteLine("Captcha solved: " + captcha.Code);
29+
}
30+
catch (AggregateException e)
31+
{
32+
Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message);
33+
}
34+
}
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using TwoCaptcha.Captcha;
5+
using static System.Net.Mime.MediaTypeNames;
6+
7+
namespace TwoCaptcha.Examples
8+
{
9+
public class VkImageExample
10+
{
11+
public VkImageExample(string apiKey)
12+
{
13+
ImageBased(apiKey);
14+
}
15+
16+
private void ImageBased(string apiKey)
17+
{
18+
TwoCaptcha solver = new TwoCaptcha(apiKey);
19+
20+
byte[] bytes = File.ReadAllBytes("resources/vk.jpg");
21+
string base64EncodedImage = Convert.ToBase64String(bytes);
22+
23+
VkCaptcha captcha = new VkCaptcha("vkimage");
24+
captcha.SetBase64(base64EncodedImage);
25+
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]");
26+
27+
try
28+
{
29+
solver.Solve(captcha).Wait();
30+
Console.WriteLine("Captcha solved: " + captcha.Code);
31+
}
32+
catch (AggregateException e)
33+
{
34+
Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message);
35+
}
36+
}
37+
}
38+
}
31.5 KB
Loading

TwoCaptcha.Tests/VkCaptchaTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
using TwoCaptcha.Captcha;
7+
using static System.Net.Mime.MediaTypeNames;
8+
9+
namespace TwoCaptcha.Tests
10+
{
11+
[TestFixture]
12+
public class VkCaptchaTest : AbstractWrapperTestCase
13+
{
14+
[Test]
15+
public async Task TestAllParameters()
16+
{
17+
VkCaptcha captcha = new VkCaptcha("vkcaptcha");
18+
captcha.SetSiteKey("0x4AAAAAAAChNiVJM_WtShFf");
19+
captcha.SetUrl("https://ace.fusionist.io");
20+
21+
var parameters = new Dictionary<string, string>();
22+
parameters["method"] = "vkcaptcha";
23+
parameters["soft_id"] = "4582";
24+
parameters["pageurl"] = "https://ace.fusionist.io";
25+
parameters["sitekey"] = "0x4AAAAAAAChNiVJM_WtShFf";
26+
27+
await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
28+
}
29+
}
30+
}

TwoCaptcha.Tests/VkImageTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
using TwoCaptcha.Captcha;
7+
using static System.Net.Mime.MediaTypeNames;
8+
9+
namespace TwoCaptcha.Tests
10+
{
11+
[TestFixture]
12+
public class VkImageTest : AbstractWrapperTestCase
13+
{
14+
[Test]
15+
public async Task TestAllParameters()
16+
{
17+
byte[] bytes = File.ReadAllBytes("../../../resources/vk.jpg");
18+
string base64EncodedImage = Convert.ToBase64String(bytes);
19+
20+
VkCaptcha captcha = new VkCaptcha("vkimage");
21+
captcha.SetBase64(base64EncodedImage);
22+
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]");
23+
24+
var parameters = new Dictionary<string, string>();
25+
parameters["method"] = "vkimage";
26+
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]";
27+
parameters["body"] = base64EncodedImage;
28+
parameters["soft_id"] = "4582";
29+
30+
await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters);
31+
}
32+
}
33+
}

TwoCaptcha.Tests/resources/vk.jpg

31.5 KB
Loading

TwoCaptcha/Captcha/Captcha.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,15 @@ public Dictionary<string, FileInfo> GetFiles()
5757
{
5858
return new Dictionary<string, FileInfo>(files);
5959
}
60+
61+
public void SetSiteKey(String siteKey)
62+
{
63+
parameters["sitekey"] = siteKey;
64+
}
65+
66+
public void SetUrl(String url)
67+
{
68+
parameters["pageurl"] = url;
69+
}
6070
}
6171
}

0 commit comments

Comments
 (0)