diff --git a/AntiCaptcha.Sandbox/Program.cs b/AntiCaptcha.Sandbox/Program.cs index 91d1562..c6bf661 100644 --- a/AntiCaptcha.Sandbox/Program.cs +++ b/AntiCaptcha.Sandbox/Program.cs @@ -1,4 +1,5 @@ ο»Ώusing System.Diagnostics; +using System.Net.Http; using System.Threading.Tasks; namespace _AntiCaptcha.Test @@ -12,26 +13,28 @@ static void Main(string[] args) static async Task Foo() { - var antiCaptcha = new AntiCaptcha(" ## YOUR API KEY ## "); + var captcha = new AntiCaptcha(" ## YOUR API KEY ## "); + // .. additionally you can pass your own httpClient class + var captchaWithHttpClient = new AntiCaptcha(" ## YOUR API KEY ## ", new HttpClient()); // Get current balance - var balance = await antiCaptcha.GetBalance(); + var balance = await captcha.GetBalance(); // Solve image captcha - var image = await antiCaptcha.SolveImage("iVBORw0KGgo..."); + var image = await captcha.SolveImage("iVBORw0KGgo..."); // Solve ReCaptchaV2 - var recaptcha = await antiCaptcha.SolveReCaptchaV2("GOOGLE_SITE_KEY", "https://example.com"); - var recaptchaInvisible = await antiCaptcha.SolveReCaptchaV2("GOOGLE_SITE_KEY", "https://example.com", true); + var recaptcha = await captcha.SolveReCaptchaV2("GOOGLE_SITE_KEY", "https://example.com"); + var recaptchaInvisible = await captcha.SolveReCaptchaV2("GOOGLE_SITE_KEY", "https://example.com", true); // Solve FunCaptcha - var fun = await antiCaptcha.SolveFunCaptcha("FUN_CAPTCHA_PUBLIC_KEY", "https://example.com"); + var fun = await captcha.SolveFunCaptcha("FUN_CAPTCHA_PUBLIC_KEY", "https://example.com"); // Solve SquareNet - var square = await antiCaptcha.SolveSquareNet("iVBORw0KGgo...", "banana", 3, 3); + var square = await captcha.SolveSquareNet("iVBORw0KGgo...", "banana", 3, 3); // Solve GeeTest - var gee = await antiCaptcha.SolveGeeTest("GEE_TEST_KEY", "https://example.com", "CHALLENGE"); + var gee = await captcha.SolveGeeTest("GEE_TEST_KEY", "https://example.com", "CHALLENGE"); Debugger.Break(); } diff --git a/AntiCaptcha/AntiCaptcha.cs b/AntiCaptcha/AntiCaptcha.cs index d745ca4..ff9d8d2 100644 --- a/AntiCaptcha/AntiCaptcha.cs +++ b/AntiCaptcha/AntiCaptcha.cs @@ -12,7 +12,7 @@ public class AntiCaptcha #if NETSTANDARD2_0 [Serializable] #endif - private struct AntiCaptchaResponse + private struct AntiCaptchaApiResponse { public int ErrorId; public string ErrorCode; @@ -27,9 +27,9 @@ private struct AntiCaptchaResponse private readonly HttpClient _httpClient; private readonly string _apiKey; - public AntiCaptcha(string apiKey) + public AntiCaptcha(string apiKey, HttpClient httpClient = null) { - _httpClient = new HttpClient(); + _httpClient = httpClient ?? new HttpClient(); _apiKey = apiKey; } @@ -44,7 +44,7 @@ public async Task GetBalance(CancellationToken cancellationTo var inResponse = await _httpClient.PostAsync(BaseUrl + "getBalance", new StringContent(contentJson), cancellationToken).ConfigureAwait(false); var inJson = await inResponse.Content.ReadAsStringAsync().ConfigureAwait(false); - var @in = JsonConvert.DeserializeObject(inJson); + var @in = JsonConvert.DeserializeObject(inJson); if (@in.ErrorId != 0) { return new AntiCaptchaResult(false, @in.ErrorCode); @@ -53,7 +53,7 @@ public async Task GetBalance(CancellationToken cancellationTo return new AntiCaptchaResult(true, @in.Balance.ToString()); } - private async Task Solve(int delaySeconds, IDictionary content, CancellationToken cancellationToken = default) + private async Task Solve(int delaySeconds, IDictionary content, CancellationToken cancellationToken = default) { content["clientKey"] = _apiKey; @@ -61,17 +61,17 @@ private async Task Solve(int delaySeconds, IDictionar var inResponse = await _httpClient.PostAsync(BaseUrl + "createTask", new StringContent(contentJson), cancellationToken).ConfigureAwait(false); var inJson = await inResponse.Content.ReadAsStringAsync().ConfigureAwait(false); - var @in = JsonConvert.DeserializeObject(inJson); + var @in = JsonConvert.DeserializeObject(inJson); if (@in.ErrorId != 0) { - return new InternalAntiCaptchaResult(false, @in.ErrorCode, null); + return new AntiCaptchaResultInternal(false, @in.ErrorCode, null); } await Task.Delay(delaySeconds * 1000, cancellationToken).ConfigureAwait(false); return await GetResponse(@in.TaskId, cancellationToken).ConfigureAwait(false); } - private async Task GetResponse(int taskId, CancellationToken cancellationToken = default) + private async Task GetResponse(int taskId, CancellationToken cancellationToken = default) { var content = new Dictionary { @@ -86,10 +86,10 @@ private async Task GetResponse(int taskId, Cancellati var response = await _httpClient.PostAsync(BaseUrl + "getTaskResult", new StringContent(contentJson), cancellationToken).ConfigureAwait(false); var responseJson = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - var res = JsonConvert.DeserializeObject(responseJson); + var res = JsonConvert.DeserializeObject(responseJson); if (res.ErrorId != 0) { - return new InternalAntiCaptchaResult(false, res.ErrorCode, null); + return new AntiCaptchaResultInternal(false, res.ErrorCode, null); } if (res.Status == "processing") @@ -98,7 +98,7 @@ private async Task GetResponse(int taskId, Cancellati continue; } - return new InternalAntiCaptchaResult(true, null, res.Solution); + return new AntiCaptchaResultInternal(true, null, res.Solution); } } diff --git a/AntiCaptcha/AntiCaptcha.csproj b/AntiCaptcha/AntiCaptcha.csproj index 86e84c2..1f25da0 100644 --- a/AntiCaptcha/AntiCaptcha.csproj +++ b/AntiCaptcha/AntiCaptcha.csproj @@ -5,21 +5,30 @@ _AntiCaptcha Zaczero (Kamil Monicz) Simple API wrapper for https://anti-captcha.com/ - Copyright (c) Zaczero (Kamil Monicz) 2019 + Copyright Β© Kamil Monicz 2020 https://github.com/Zaczero/AntiCaptcha - https://i.imgur.com/U0qKP3j.png - 1.1.0 + + 1.2 anticaptcha, captcha, solver, recaptcha, google, text, image, wrapper, api AntiCaptchaAPI true - 1.1.0.0 - 1.1.0.0 + 1.2.0.0 + 1.2.0.0 MIT + https://github.com/Zaczero/AntiCaptcha + AntiCaptcha.png + + + True + + + + diff --git a/AntiCaptcha/AntiCaptchaResult.cs b/AntiCaptcha/AntiCaptchaResult.cs index e9f0777..b948205 100644 --- a/AntiCaptcha/AntiCaptchaResult.cs +++ b/AntiCaptcha/AntiCaptchaResult.cs @@ -14,13 +14,13 @@ public AntiCaptchaResult(bool success, string response) } } - internal struct InternalAntiCaptchaResult + internal struct AntiCaptchaResultInternal { public bool Success; public string Response; public Dictionary Dictionary; - public InternalAntiCaptchaResult(bool success, string response, Dictionary dictionary) + public AntiCaptchaResultInternal(bool success, string response, Dictionary dictionary) { Success = success; Response = response; diff --git a/README.md b/README.md index 39efcb1..d1d15ba 100644 --- a/README.md +++ b/README.md @@ -1,81 +1,74 @@ -# ![2Captcha logo](https://i.imgur.com/U0qKP3j.png) +# ![Zaczero/AntiCaptcha logo](https://github.com/Zaczero/AntiCaptcha/blob/master/resources/AntiCaptcha.png) -![](https://img.shields.io/github/release/Zaczero/AntiCaptcha.svg) -![](https://img.shields.io/nuget/v/AntiCaptchaAPI.svg) -![](https://img.shields.io/github/license/Zaczero/AntiCaptcha.svg) +![github version](https://img.shields.io/github/release/Zaczero/AntiCaptcha.svg) +![nuget version](https://img.shields.io/nuget/v/AntiCaptchaAPI.svg) +![license type](https://img.shields.io/github/license/Zaczero/AntiCaptcha.svg) -Simple HTTP API wrapper for https://anti-captcha.com/ +Simple HTTP API wrapper for [anti-captcha.com](https://anti-captcha.com/) An online captcha solving and image recognition service. -## πŸ”— Download -* Latest release: https://github.com/Zaczero/AntiCaptcha/releases/latest +## 🌀️ Installation -## β˜• Support me -If you find this project useful and you are new to anti captcha please consider registering from my [referrral link](http://getcaptchasolution.com/i4lbjatsex). +### Install with NuGet (recommended) -## 🏁 Sample code +`Install-Package AntiCaptchaAPI` + +### Install manually + +[Browse latest GitHub release](https://github.com/Zaczero/AntiCaptcha/releases/latest) + +## 🏁 Getting started + +### Sample code ```cs -var antiCaptcha = new AntiCaptcha(" ## YOUR API KEY ## "); +var captcha = new AntiCaptcha(" ## YOUR API KEY ## "); +// .. additionally you can pass your own httpClient class +var captchaWithHttpClient = new AntiCaptcha(" ## YOUR API KEY ## ", new HttpClient()); // Get current balance -var balance = await antiCaptcha.GetBalance(); +var balance = await captcha.GetBalance(); // Solve image captcha -var image = await antiCaptcha.SolveImage("iVBORw0KGgo..."); +var image = await captcha.SolveImage("iVBORw0KGgo..."); // Solve ReCaptchaV2 -var recaptcha = await antiCaptcha.SolveReCaptchaV2("GOOGLE_SITE_KEY", "https://example.com"); -var recaptchaInvisible = await antiCaptcha.SolveReCaptchaV2("GOOGLE_SITE_KEY", "https://example.com", true); +var recaptcha = await captcha.SolveReCaptchaV2("GOOGLE_SITE_KEY", "https://example.com"); +var recaptchaInvisible = await captcha.SolveReCaptchaV2("GOOGLE_SITE_KEY", "https://example.com", true); // Solve FunCaptcha -var fun = await antiCaptcha.SolveFunCaptcha("FUN_CAPTCHA_PUBLIC_KEY", "https://example.com"); +var fun = await captcha.SolveFunCaptcha("FUN_CAPTCHA_PUBLIC_KEY", "https://example.com"); // Solve SquareNet -var square = await antiCaptcha.SolveSquareNet("iVBORw0KGgo...", "banana", 3, 3); +var square = await captcha.SolveSquareNet("iVBORw0KGgo...", "banana", 3, 3); // Solve GeeTest -var gee = await antiCaptcha.SolveGeeTest("GEE_TEST_KEY", "https://example.com", "CHALLENGE"); - -Debugger.Break(); +var gee = await captcha.SolveGeeTest("GEE_TEST_KEY", "https://example.com", "CHALLENGE"); ``` -### And here is the result structure *(same for all methods)*: +### And here is the result structure *(the same for all methods)* ```cs public struct AntiCaptchaResult { - public bool Success; - public string Response; - - public AntiCaptchaResult(bool success, string response) - { - Success = success; - Response = response; - } + public bool Success; + public string Response; + + public AntiCaptchaResult(bool success, string response) + { + Success = success; + Response = response; + } } ``` -## πŸ“Ž License - -MIT License +## Footer -Copyright (c) 2019 Kamil Monicz +### πŸ“§ Contact -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +* Email: [kamil@monicz.pl](mailto:kamil@monicz.pl) -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +### πŸ“ƒ License -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +* [Zaczero/AntiCaptcha](https://github.com/Zaczero/AntiCaptcha/blob/master/LICENSE) +* [JamesNK/Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json/blob/master/LICENSE.md) diff --git a/resources/AntiCaptcha.png b/resources/AntiCaptcha.png new file mode 100644 index 0000000..a44d495 Binary files /dev/null and b/resources/AntiCaptcha.png differ