diff --git a/README.md b/README.md index 4971f23..d274c80 100644 --- a/README.md +++ b/README.md @@ -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) @@ -488,6 +490,41 @@ tencent.SetAppId("190014885"); tencent.SetPageUrl("https://www.example.com/"); ``` +### VK Image + +[API method description.](https://2captcha.com/2captcha-api#vkcaptcha) + +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 + +[API method description.](https://2captcha.com/2captcha-api#vk-captcha) + +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 diff --git a/TwoCaptcha.Examples/Run.cs b/TwoCaptcha.Examples/Run.cs index c190662..a218289 100644 --- a/TwoCaptcha.Examples/Run.cs +++ b/TwoCaptcha.Examples/Run.cs @@ -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; } } } diff --git a/TwoCaptcha.Examples/TwoCaptcha.Examples.csproj b/TwoCaptcha.Examples/TwoCaptcha.Examples.csproj index 08a4b39..442d461 100644 --- a/TwoCaptcha.Examples/TwoCaptcha.Examples.csproj +++ b/TwoCaptcha.Examples/TwoCaptcha.Examples.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1;net5.0;net6.0;net7.0 @@ -81,5 +81,11 @@ PreserveNewest + + + + PreserveNewest + + \ No newline at end of file diff --git a/TwoCaptcha.Examples/VkCaptchaExample.cs b/TwoCaptcha.Examples/VkCaptchaExample.cs new file mode 100644 index 0000000..30d523e --- /dev/null +++ b/TwoCaptcha.Examples/VkCaptchaExample.cs @@ -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); + } + } + } +} \ No newline at end of file diff --git a/TwoCaptcha.Examples/VkImageExample.cs b/TwoCaptcha.Examples/VkImageExample.cs new file mode 100644 index 0000000..a29dc6b --- /dev/null +++ b/TwoCaptcha.Examples/VkImageExample.cs @@ -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); + } + } + } +} \ No newline at end of file diff --git a/TwoCaptcha.Examples/resources/vk.jpg b/TwoCaptcha.Examples/resources/vk.jpg new file mode 100644 index 0000000..91809ec Binary files /dev/null and b/TwoCaptcha.Examples/resources/vk.jpg differ diff --git a/TwoCaptcha.Tests/VkCaptchaTest.cs b/TwoCaptcha.Tests/VkCaptchaTest.cs new file mode 100644 index 0000000..a57eadc --- /dev/null +++ b/TwoCaptcha.Tests/VkCaptchaTest.cs @@ -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(); + parameters["method"] = "vkcaptcha"; + parameters["soft_id"] = "4582"; + parameters["pageurl"] = "https://ace.fusionist.io"; + parameters["sitekey"] = "0x4AAAAAAAChNiVJM_WtShFf"; + + await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); + } + } +} \ No newline at end of file diff --git a/TwoCaptcha.Tests/VkImageTest.cs b/TwoCaptcha.Tests/VkImageTest.cs new file mode 100644 index 0000000..2a91d1f --- /dev/null +++ b/TwoCaptcha.Tests/VkImageTest.cs @@ -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(); + 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); + } + } +} \ No newline at end of file diff --git a/TwoCaptcha.Tests/resources/vk.jpg b/TwoCaptcha.Tests/resources/vk.jpg new file mode 100644 index 0000000..91809ec Binary files /dev/null and b/TwoCaptcha.Tests/resources/vk.jpg differ diff --git a/TwoCaptcha/Captcha/Captcha.cs b/TwoCaptcha/Captcha/Captcha.cs index f075824..ee81ffd 100644 --- a/TwoCaptcha/Captcha/Captcha.cs +++ b/TwoCaptcha/Captcha/Captcha.cs @@ -57,5 +57,15 @@ public Dictionary GetFiles() { return new Dictionary(files); } + + public void SetSiteKey(String siteKey) + { + parameters["sitekey"] = siteKey; + } + + public void SetUrl(String url) + { + parameters["pageurl"] = url; + } } } \ No newline at end of file diff --git a/TwoCaptcha/Captcha/VkCaptcha.cs b/TwoCaptcha/Captcha/VkCaptcha.cs new file mode 100644 index 0000000..7fce9a0 --- /dev/null +++ b/TwoCaptcha/Captcha/VkCaptcha.cs @@ -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; + } + } +} + + + + + +