diff --git a/TwoCaptcha.Examples/RotateExample.cs b/TwoCaptcha.Examples/RotateExample.cs index 710b8bc..716940b 100644 --- a/TwoCaptcha.Examples/RotateExample.cs +++ b/TwoCaptcha.Examples/RotateExample.cs @@ -1,26 +1,33 @@ -using System; -using System.Linq; -using TwoCaptcha.Captcha; - -namespace TwoCaptcha.Examples -{ - public class RotateExample - { - public void Main() - { - TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY"); - - Rotate captcha = new Rotate("../../resources/rotate.jpg"); - - try - { - solver.Solve(captcha).Wait(); - Console.WriteLine("Captcha solved: " + captcha.Code); - } - catch (AggregateException e) - { - Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message); - } - } - } +using System; +using System.IO; +using System.Linq; +using TwoCaptcha.Captcha; + +namespace TwoCaptcha.Examples +{ + public class RotateExample + { + public void Main() + { + TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY"); + + byte[] bytes = File.ReadAllBytes("../../resources/rotate.jpg"); + string base64EncodedImage = Convert.ToBase64String(bytes); + Console.WriteLine("base64EncodedImage: " + base64EncodedImage); + + + Rotate captcha = new Rotate(); + captcha.SetBase64(base64EncodedImage); + + 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/RotateManyExample.cs b/TwoCaptcha.Examples/RotateManyExample.cs deleted file mode 100644 index fc84abd..0000000 --- a/TwoCaptcha.Examples/RotateManyExample.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using TwoCaptcha.Captcha; - -namespace TwoCaptcha.Examples -{ - public class RotateManyExample - { - public void Main() - { - TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY"); - - var images = new List(); - images.Add(new FileInfo("../../resources/rotate.jpg")); - images.Add(new FileInfo("../../resources/rotate_2.jpg")); - images.Add(new FileInfo("../../resources/rotate_3.jpg")); - - Rotate captcha = new Rotate(); - captcha.SetFiles(images); - - 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/RotateOptionsExample.cs b/TwoCaptcha.Examples/RotateOptionsExample.cs index b6ea5ff..7ffaad5 100644 --- a/TwoCaptcha.Examples/RotateOptionsExample.cs +++ b/TwoCaptcha.Examples/RotateOptionsExample.cs @@ -1,38 +1,36 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using TwoCaptcha.Captcha; - -namespace TwoCaptcha.Examples -{ - public class RotateOptionsExample - { - public void Main() - { - TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY"); - - var images = new List(); - images.Add(new FileInfo("../../resources/rotate.jpg")); - images.Add(new FileInfo("../../resources/rotate_2.jpg")); - images.Add(new FileInfo("../../resources/rotate_3.jpg")); - - Rotate captcha = new Rotate(); - captcha.SetFiles(images); - captcha.SetAngle(40); - captcha.SetLang("en"); - captcha.SetHintImg(new FileInfo("../../resources/rotate_hint.jpg")); - captcha.SetHintText("Put the images in the correct way up"); - - try - { - solver.Solve(captcha).Wait(); - Console.WriteLine("Captcha solved: " + captcha.Code); - } - catch (AggregateException e) - { - Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message); - } - } - } +using System; +using System.IO; +using System.Linq; +using TwoCaptcha.Captcha; + +namespace TwoCaptcha.Examples +{ + public class RotateOptionsExample + { + public void Main() + { + TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY"); + + byte[] bytes = File.ReadAllBytes("../../resources/rotate.jpg"); + string base64EncodedImage = Convert.ToBase64String(bytes); + + + Rotate captcha = new Rotate(); + captcha.SetBase64(base64EncodedImage); + captcha.SetAngle(40); + captcha.SetLang("en"); + captcha.SetHintImg(new FileInfo("../../resources/rotate.jpg")); + captcha.SetHintText("Put the images in the correct way up"); + + 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/audio-en.mp3 b/TwoCaptcha.Examples/resources/audio-en.mp3 new file mode 100644 index 0000000..eee8423 Binary files /dev/null and b/TwoCaptcha.Examples/resources/audio-en.mp3 differ diff --git a/TwoCaptcha.Examples/resources/audio-ru.mp3 b/TwoCaptcha.Examples/resources/audio-ru.mp3 new file mode 100644 index 0000000..5898a67 Binary files /dev/null and b/TwoCaptcha.Examples/resources/audio-ru.mp3 differ diff --git a/TwoCaptcha.Tests/AmazonWafTest.cs b/TwoCaptcha.Tests/AmazonWafTest.cs new file mode 100644 index 0000000..e421188 --- /dev/null +++ b/TwoCaptcha.Tests/AmazonWafTest.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using NUnit.Framework; +using TwoCaptcha.Captcha; + +namespace TwoCaptcha.Tests +{ + [TestFixture] + public class AmazonWafTest : AbstractWrapperTestCase + { + [Test] + public async Task TestAllOptions() + { + AmazonWaf captcha = new AmazonWaf(); + captcha.SetSiteKey("AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AF5H1K/siwSLK7RfstKtN5bAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglg"); + captcha.SetUrl("https://non-existent-example.execute-api.us-east-1.amazonaws.com"); + captcha.SetContext("test_iv"); + captcha.SetIV("test_context"); + + var parameters = new Dictionary(); + parameters["method"] = "amazon_waf"; + parameters["sitekey"] = "AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AF5H1K/siwSLK7RfstKtN5bAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglg"; + parameters["pageurl"] = "https://non-existent-example.execute-api.us-east-1.amazonaws.com"; + parameters["context"] = "test_iv"; + parameters["iv"] = "test_context"; + + await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); + } + } +} \ No newline at end of file diff --git a/TwoCaptcha.Tests/AudioTest.cs b/TwoCaptcha.Tests/AudioTest.cs new file mode 100644 index 0000000..93aac82 --- /dev/null +++ b/TwoCaptcha.Tests/AudioTest.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using NUnit.Framework; +using TwoCaptcha.Captcha; + +namespace TwoCaptcha.Tests +{ + [TestFixture] + public class AudioTest : AbstractWrapperTestCase + { + + [Test] + public async Task TestAllParameters() + { + byte[] bytes = File.ReadAllBytes("../../../resources/audio-en.mp3"); + string base64EncodedImage = Convert.ToBase64String(bytes); + + + AudioCaptcha captcha = new AudioCaptcha(); + captcha.SetBase64(base64EncodedImage); + captcha.SetLang("en"); + + + var parameters = new Dictionary(); + parameters["method"] = "audio"; + parameters["lang"] = "en"; + parameters["body"] = base64EncodedImage; + + + await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); + } + + } +} \ No newline at end of file diff --git a/TwoCaptcha.Tests/GeeTestV4Test.cs b/TwoCaptcha.Tests/GeeTestV4Test.cs new file mode 100644 index 0000000..1984464 --- /dev/null +++ b/TwoCaptcha.Tests/GeeTestV4Test.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using NUnit.Framework; +using TwoCaptcha.Captcha; + +namespace TwoCaptcha.Tests +{ + [TestFixture] + public class GeeTestV4Test : AbstractWrapperTestCase + { + [Test] + public async Task TestAllOptions() + { + GeeTestV4 captcha = new GeeTestV4(); + captcha.SetCaptchaId("72bf15796d0b69c43867452fea615052"); + captcha.SetChallenge("12345678abc90123d45678ef90123a456b"); + captcha.SetUrl("https://mysite.com/captcha.html"); + + var parameters = new Dictionary(); + parameters["method"] = "geetest_v4"; + parameters["captcha_id"] = "72bf15796d0b69c43867452fea615052"; + parameters["challenge"] = "12345678abc90123d45678ef90123a456b"; + parameters["pageurl"] = "https://mysite.com/captcha.html"; + + await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); + } + } +} \ No newline at end of file diff --git a/TwoCaptcha.Tests/HCaptchaTest.cs b/TwoCaptcha.Tests/HCaptchaTest.cs index 2d6aed4..3e72baf 100644 --- a/TwoCaptcha.Tests/HCaptchaTest.cs +++ b/TwoCaptcha.Tests/HCaptchaTest.cs @@ -1,26 +1,26 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using NUnit.Framework; -using TwoCaptcha.Captcha; - -namespace TwoCaptcha.Tests -{ - [TestFixture] - public class HCaptchaTest : AbstractWrapperTestCase - { - [Test] - public async Task TestAllOptions() - { - HCaptcha captcha = new HCaptcha(); - captcha.SetSiteKey("f1ab2cdefa3456789012345b6c78d90e"); - captcha.SetUrl("https://www.site.com/page/"); - - var parameters = new Dictionary(); - parameters["method"] = "hcaptcha"; - parameters["sitekey"] = "f1ab2cdefa3456789012345b6c78d90e"; - parameters["pageurl"] = "https://www.site.com/page/"; - - await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); - } - } +using System.Collections.Generic; +using System.Threading.Tasks; +using NUnit.Framework; +using TwoCaptcha.Captcha; + +namespace TwoCaptcha.Tests +{ + [TestFixture] + public class HCaptchaTest : AbstractWrapperTestCase + { + [Test] + public async Task TestAllOptions() + { + HCaptcha captcha = new HCaptcha(); + captcha.SetSiteKey("f1ab2cdefa3456789012345b6c78d90e"); + captcha.SetUrl("https://www.site.com/page/"); + + var parameters = new Dictionary(); + parameters["method"] = "hcaptcha"; + parameters["sitekey"] = "f1ab2cdefa3456789012345b6c78d90e"; + parameters["pageurl"] = "https://www.site.com/page/"; + + await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); + } + } } \ No newline at end of file diff --git a/TwoCaptcha.Tests/LeminTest.cs b/TwoCaptcha.Tests/LeminTest.cs new file mode 100644 index 0000000..a635fd4 --- /dev/null +++ b/TwoCaptcha.Tests/LeminTest.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using NUnit.Framework; +using TwoCaptcha.Captcha; + +namespace TwoCaptcha.Tests +{ + [TestFixture] + public class LeminTest : AbstractWrapperTestCase + { + [Test] + public async Task TestAllOptions() + { + Lemin captcha = new Lemin(); + captcha.SetCaptchaId("CROPPED_d3d4d56_73ca4008925b4f83a8bed59c2dd0df6d"); + captcha.SetApiServer("api.leminnow.com"); + captcha.SetUrl("http://sat2.aksigorta.com.tr"); + + var parameters = new Dictionary(); + parameters["method"] = "lemin"; + parameters["captcha_id"] = "CROPPED_d3d4d56_73ca4008925b4f83a8bed59c2dd0df6d"; + parameters["api_server"] = "api.leminnow.com"; + parameters["pageurl"] = "http://sat2.aksigorta.com.tr"; + + await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); + } + } +} \ No newline at end of file diff --git a/TwoCaptcha.Tests/RotateTest.cs b/TwoCaptcha.Tests/RotateTest.cs index d9a0b6a..591c9f2 100644 --- a/TwoCaptcha.Tests/RotateTest.cs +++ b/TwoCaptcha.Tests/RotateTest.cs @@ -1,130 +1,40 @@ -using System.Collections.Generic; -using System.IO; -using System.Threading.Tasks; -using NUnit.Framework; -using TwoCaptcha.Captcha; - -namespace TwoCaptcha.Tests -{ - [TestFixture] - public class RotateTest : AbstractWrapperTestCase - { - private string[] captchaImgPaths = - { - "../../../resources/rotate.jpg", - "../../../resources/rotate_2.jpg", - "../../../resources/rotate_3.jpg", - }; - - private string hintImgPath = "../../../resources/grid_hint.jpg"; - private string hintText = "Put the images in the correct way up"; - - [Test] - public async Task TestSingleFile() - { - FileInfo image = new FileInfo(captchaImgPaths[0]); - - Rotate captcha = new Rotate(image); - - var parameters = new Dictionary(); - parameters["method"] = "rotatecaptcha"; - - var files = new Dictionary(); - files["file_1"] = image; - - await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters, files); - } - - [Test] - public async Task TestSingleFileParameter() - { - FileInfo image = new FileInfo(captchaImgPaths[0]); - - Rotate captcha = new Rotate(); - captcha.SetFile(image); - - var parameters = new Dictionary(); - parameters["method"] = "rotatecaptcha"; - - var files = new Dictionary(); - files["file_1"] = image; - - await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters, files); - } - - [Test] - public async Task TestFilesList() - { - var images = GetImages(); - - Rotate captcha = new Rotate(images); - - var parameters = new Dictionary(); - parameters["method"] = "rotatecaptcha"; - - var files = new Dictionary(); - files["file_1"] = images[0]; - files["file_2"] = images[1]; - files["file_3"] = images[2]; - - await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters, files); - } - - [Test] - public async Task TestFilesListParameter() - { - var images = GetImages(); - - Rotate captcha = new Rotate(); - captcha.SetFiles(images); - - var parameters = new Dictionary(); - parameters["method"] = "rotatecaptcha"; - - var files = new Dictionary(); - files["file_1"] = images[0]; - files["file_2"] = images[1]; - files["file_3"] = images[2]; - - await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters, files); - } - - [Test] - public async Task TestAllParameters() - { - FileInfo image = new FileInfo(captchaImgPaths[0]); - FileInfo hintImg = new FileInfo(hintImgPath); - - Rotate captcha = new Rotate(); - captcha.SetFile(image); - captcha.SetAngle(45); - captcha.SetLang("en"); - captcha.SetHintImg(hintImg); - captcha.SetHintText(hintText); - - var parameters = new Dictionary(); - parameters["method"] = "rotatecaptcha"; - parameters["angle"] = "45"; - parameters["lang"] = "en"; - parameters["textinstructions"] = hintText; - - var files = new Dictionary(); - files["file_1"] = image; - files["imginstructions"] = hintImg; - - await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters, files); - } - - private List GetImages() - { - var images = new List(); - - foreach (string image in captchaImgPaths) - { - images.Add(new FileInfo(image)); - } - - return images; - } - } +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using NUnit.Framework; +using TwoCaptcha.Captcha; + +namespace TwoCaptcha.Tests +{ + [TestFixture] + public class RotateTest : AbstractWrapperTestCase + { + + [Test] + public async Task TestAllParameters() + { + byte[] bytes = File.ReadAllBytes("../../../resources/rotate.jpg"); + string base64EncodedImage = Convert.ToBase64String(bytes); + + + Rotate captcha = new Rotate(); + captcha.SetBase64(base64EncodedImage); + captcha.SetAngle(45); + captcha.SetLang("en"); + captcha.SetHintText("Put the images in the correct way up"); + + + var parameters = new Dictionary(); + parameters["method"] = "rotatecaptcha"; + parameters["angle"] = "45"; + parameters["lang"] = "en"; + parameters["textinstructions"] = "Put the images in the correct way up"; + parameters["body"] = base64EncodedImage; + + + await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); + } + + } } \ No newline at end of file diff --git a/TwoCaptcha.Tests/TurnstileTest.cs b/TwoCaptcha.Tests/TurnstileTest.cs new file mode 100644 index 0000000..c169a18 --- /dev/null +++ b/TwoCaptcha.Tests/TurnstileTest.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using NUnit.Framework; +using TwoCaptcha.Captcha; + +namespace TwoCaptcha.Tests +{ + [TestFixture] + public class TurnstileTest : AbstractWrapperTestCase + { + [Test] + public async Task TestAllOptions() + { + Turnstile captcha = new Turnstile(); + captcha.SetSiteKey("0x4AAAAAAAChNiVJM_WtShFf"); + captcha.SetUrl("https://ace.fusionist.io"); + + var parameters = new Dictionary(); + parameters["method"] = "turnstile"; + parameters["sitekey"] = "0x4AAAAAAAChNiVJM_WtShFf"; + parameters["pageurl"] = "https://ace.fusionist.io"; + + await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); + } + } +} \ No newline at end of file diff --git a/TwoCaptcha.Tests/YandexTest.cs b/TwoCaptcha.Tests/YandexTest.cs new file mode 100644 index 0000000..7d18ab8 --- /dev/null +++ b/TwoCaptcha.Tests/YandexTest.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using NUnit.Framework; +using TwoCaptcha.Captcha; + +namespace TwoCaptcha.Tests +{ + [TestFixture] + public class YandexTest : AbstractWrapperTestCase + { + [Test] + public async Task TestAllOptions() + { + Yandex captcha = new Yandex(); + captcha.SetSiteKey("Y5Lh0tiycconMJGsFd3EbbuNKSp1yaZESUOIHfeV"); + captcha.SetUrl("https://rutube.ru"); + + var parameters = new Dictionary(); + parameters["method"] = "yandex"; + parameters["sitekey"] = "Y5Lh0tiycconMJGsFd3EbbuNKSp1yaZESUOIHfeV"; + parameters["pageurl"] = "https://rutube.ru"; + + await CheckIfCorrectParamsSendAndResultReturned(captcha, parameters); + } + } +} \ No newline at end of file diff --git a/TwoCaptcha/Captcha/Rotate.cs b/TwoCaptcha/Captcha/Rotate.cs index 2d83524..e5baef4 100644 --- a/TwoCaptcha/Captcha/Rotate.cs +++ b/TwoCaptcha/Captcha/Rotate.cs @@ -1,73 +1,45 @@ -using System; -using System.Collections.Generic; -using System.IO; - -namespace TwoCaptcha.Captcha -{ - public class Rotate : Captcha - { - public Rotate() : base() - { - parameters["method"] = "rotatecaptcha"; - } - - public Rotate(string filePath) : this(new FileInfo(filePath)) - { - } - - public Rotate(FileInfo file) : this() - { - SetFile(file); - } - - public Rotate(List files) : this() - { - SetFiles(files); - } - - public void SetFile(String filePath) - { - SetFile(new FileInfo(filePath)); - } - - public void SetFile(FileInfo file) - { - files["file_1"] = file; - } - - public void SetFiles(List files) - { - int n = 1; - - foreach (FileInfo file in files) - { - this.files["file_" + n++] = file; - } - } - - public void SetAngle(double angle) - { - parameters["angle"] = Convert.ToString(angle).Replace(',', '.'); - } - - public void SetLang(String lang) - { - parameters["lang"] = lang; - } - - public void SetHintText(String hintText) - { - parameters["textinstructions"] = hintText; - } - - public void SetHintImg(String base64) - { - parameters["imginstructions"] = base64; - } - - public void SetHintImg(FileInfo hintImg) - { - files["imginstructions"] = hintImg; - } - } +using System; +using System.Collections.Generic; +using System.IO; + +namespace TwoCaptcha.Captcha +{ + public class Rotate : Captcha + { + public Rotate() : base() + { + parameters["method"] = "rotatecaptcha"; + } + + + public void SetBase64(String base64) + { + parameters["body"] = base64; + } + + public void SetAngle(double angle) + { + parameters["angle"] = Convert.ToString(angle).Replace(',', '.'); + } + + public void SetLang(String lang) + { + parameters["lang"] = lang; + } + + public void SetHintText(String hintText) + { + parameters["textinstructions"] = hintText; + } + + public void SetHintImg(String base64) + { + parameters["imginstructions"] = base64; + } + + public void SetHintImg(FileInfo hintImg) + { + files["imginstructions"] = hintImg; + } + } } \ No newline at end of file