diff --git a/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs b/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs index 7efb922..cfcf589 100644 --- a/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs +++ b/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs @@ -1071,5 +1071,183 @@ public async Task Binance_ShouldSolve() sut.GetActualRequests().Should().BeEquivalentTo(expectedRequests); actual.Should().BeEquivalentTo(expectedResult); } + + [Test] + public async Task Temu_ShouldSolve() + { + var clientKey = Gen.RandomString(); + var taskId = Gen.RandomInt(); + + var captchaRequest = ObjectGen.TemuTask.CreateTask(); + var expectedResult = ObjectGen.TemuTask.CreateSolution(); + + var expectedRequests = new List<(RequestType Type, string ExpectedRequest)> + { + ( + Type: RequestType.CreateTask, + ExpectedRequest: JsonConvert.SerializeObject(new + { clientKey = clientKey, task = captchaRequest, softId = 53 }) + ), + ( + Type: RequestType.GetTaskResult, + ExpectedRequest: JsonConvert.SerializeObject(new { clientKey = clientKey, taskId = taskId }) + ), + }; + + var captchaResults = new List + { + new { taskId = taskId, errorId = 0, errorCode = (string)null! }, + new + { + status = "ready", + solution = new + { + domains = expectedResult.Solution.Domains + }, + errorId = 0, + errorCode = (string)null! + } + }; + + var sut = new Sut(clientKey); + sut.SetupHttpServer(captchaResults); + + var actual = await sut.SolveAsync(captchaRequest); + + sut.GetActualRequests().Should().BeEquivalentTo(expectedRequests); + actual.Should().BeEquivalentTo(expectedResult); + } + + [Test] + public async Task MTCaptcha_ShouldSolve() + { + var clientKey = Gen.RandomString(); + var taskId = Gen.RandomInt(); + + var captchaRequest = ObjectGen.MTCaptchaTask.CreateTask(); + var expectedResult = ObjectGen.MTCaptchaTask.CreateSolution(); + + var expectedRequests = new List<(RequestType Type, string ExpectedRequest)> + { + ( + Type: RequestType.CreateTask, + ExpectedRequest: JsonConvert.SerializeObject(new + { clientKey = clientKey, task = captchaRequest, softId = 53 }) + ), + ( + Type: RequestType.GetTaskResult, + ExpectedRequest: JsonConvert.SerializeObject(new { clientKey = clientKey, taskId = taskId }) + ), + }; + + var captchaResults = new List + { + new { taskId = taskId, errorId = 0, errorCode = (string)null! }, + new + { + status = "ready", + solution = new { token = expectedResult.Solution.Value }, + errorId = 0, + errorCode = (string)null! + } + }; + + var sut = new Sut(clientKey); + sut.SetupHttpServer(captchaResults); + + var actual = await sut.SolveAsync(captchaRequest); + + sut.GetActualRequests().Should().BeEquivalentTo(expectedRequests); + actual.Should().BeEquivalentTo(expectedResult); + } + + [Test] + public async Task Yidun_ShouldSolve() + { + var clientKey = Gen.RandomString(); + var taskId = Gen.RandomInt(); + + var captchaRequest = ObjectGen.YidunTask.CreateTask(); + var expectedResult = ObjectGen.YidunTask.CreateSolution(); + + var expectedRequests = new List<(RequestType Type, string ExpectedRequest)> + { + ( + Type: RequestType.CreateTask, + ExpectedRequest: JsonConvert.SerializeObject(new + { clientKey = clientKey, task = captchaRequest, softId = 53 }) + ), + ( + Type: RequestType.GetTaskResult, + ExpectedRequest: JsonConvert.SerializeObject(new { clientKey = clientKey, taskId = taskId }) + ), + }; + + var captchaResults = new List + { + new { taskId = taskId, errorId = 0, errorCode = (string)null! }, + new + { + status = "ready", + solution = new { token = expectedResult.Solution.Value }, + errorId = 0, + errorCode = (string)null! + } + }; + + var sut = new Sut(clientKey); + sut.SetupHttpServer(captchaResults); + + var actual = await sut.SolveAsync(captchaRequest); + + sut.GetActualRequests().Should().BeEquivalentTo(expectedRequests); + actual.Should().BeEquivalentTo(expectedResult); + } + + [Test] + public async Task Prosopo_ShouldSolve() + { + var clientKey = Gen.RandomString(); + var taskId = Gen.RandomInt(); + + var captchaRequest = ObjectGen.ProsopoTask.CreateTask(); + var expectedResult = ObjectGen.ProsopoTask.CreateSolution(); + + var expectedRequests = new List<(RequestType Type, string ExpectedRequest)> + { + ( + Type: RequestType.CreateTask, + ExpectedRequest: JsonConvert.SerializeObject(new + { clientKey = clientKey, task = captchaRequest, softId = 53 }) + ), + ( + Type: RequestType.GetTaskResult, + ExpectedRequest: JsonConvert.SerializeObject(new { clientKey = clientKey, taskId = taskId }) + ), + }; + + var captchaResults = new List + { + new { taskId = taskId, errorId = 0, errorCode = (string)null! }, + new + { + status = "ready", + solution = new + { + token = expectedResult.Solution.Value + }, + errorId = 0, + errorCode = (string)null! + } + }; + + var sut = new Sut(clientKey); + sut.SetupHttpServer(captchaResults); + + var actual = await sut.SolveAsync(captchaRequest); + + sut.GetActualRequests().Should().BeEquivalentTo(expectedRequests); + actual.Should().BeEquivalentTo(expectedResult); + } } } \ No newline at end of file diff --git a/CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs b/CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs index 652ca8c..0abcf17 100644 --- a/CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs +++ b/CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs @@ -546,5 +546,132 @@ public static CaptchaResult CreateSolution() }; } } + + public static class TemuTask + { + public static TemuCustomTaskRequest CreateTask() + { + return new TemuCustomTaskRequest(Gen.RandomString()) + { + WebsiteUrl = Gen.RandomUri().ToString(), + UserAgent = Gen.UserAgent(), + Proxy = new ProxyContainer(Gen.RandomString(), Gen.RandomInt(0, 65535), Gen.RandomEnum(), Gen.RandomString(), Gen.RandomString()) + }; + } + + public static CaptchaResult CreateSolution() + { + return new CaptchaResult + { + Error = null, + Solution = new CustomTaskResponse + { + Domains = new Dictionary + { + { + "www.temu.com", + new CustomTaskResponse.DomainInfo + { + Cookies = new Dictionary + { + { "verifyAuthToken", Gen.RandomString() }, + { "api_uid", Gen.RandomString() } + } + } + } + } + } + }; + } + } + + public static class MTCaptchaTask + { + public static MTCaptchaTaskRequest CreateTask() + { + return new MTCaptchaTaskRequest + { + WebsiteUrl = Gen.RandomUri().ToString(), + WebsiteKey = Gen.RandomString(), + Invisible = Gen.RandomBool(), + PageAction = Gen.RandomString(), + UserAgent = Gen.UserAgent(), + Proxy = new ProxyContainer( + Gen.RandomString(), Gen.RandomInt(0, 65535), + Gen.RandomEnum(), Gen.RandomString(), Gen.RandomString()) + }; + } + + public static CaptchaResult CreateSolution() + { + return new CaptchaResult + { + Error = null, + Solution = new MTCaptchaTaskResponse + { + Value = Gen.RandomString() + } + }; + } + } + + public static class YidunTask + { + public static YidunTaskRequest CreateTask() + { + return new YidunTaskRequest + { + WebsiteUrl = Gen.RandomUri().ToString(), + WebsiteKey = Gen.RandomString(), + UserAgent = Gen.UserAgent(), + // Enterprise : + YidunGetLib = Gen.RandomUri().ToString(), + YidunApiServerSubdomain = Gen.RandomString(), + Challenge = Gen.RandomString(), + Hcg = Gen.RandomString(), + Hct = Gen.RandomLong(1, long.MaxValue), + Proxy = new ProxyContainer( + Gen.RandomString(), Gen.RandomInt(0, 65535), + Gen.RandomEnum(), Gen.RandomString(), Gen.RandomString()) + }; + } + + public static CaptchaResult CreateSolution() + { + return new CaptchaResult + { + Error = null, + Solution = new YidunTaskResponse + { + Value = Gen.RandomString(), + } + }; + } + } + + public static class ProsopoTask + { + public static ProsopoTaskRequest CreateTask() + { + return new ProsopoTaskRequest + { + WebsiteUrl = Gen.RandomUri().ToString(), + WebsiteKey = Gen.RandomString(), + Proxy = new ProxyContainer(Gen.RandomString(), Gen.RandomInt(0, 65535), Gen.RandomEnum(), Gen.RandomString(), Gen.RandomString()) + }; + } + + public static CaptchaResult CreateSolution() + { + return new CaptchaResult + { + Error = null, + Solution = new ProsopoTaskResponse + { + Value = Gen.RandomString(), + } + }; + } + } } } \ No newline at end of file diff --git a/CapMonsterCloud.Client.IntegrationTests/Sut.cs b/CapMonsterCloud.Client.IntegrationTests/Sut.cs index 57cc413..8ed962a 100644 --- a/CapMonsterCloud.Client.IntegrationTests/Sut.cs +++ b/CapMonsterCloud.Client.IntegrationTests/Sut.cs @@ -97,6 +97,18 @@ public async Task> SolveAsync( public async Task> SolveAsync( RecognitionComplexImageTaskRequest request) => await _cloudClient.SolveAsync(request); + + public async Task> SolveAsync( + ProsopoTaskRequest request) => await _cloudClient.SolveAsync(request); + + public async Task> SolveAsync( + TemuCustomTaskRequest request) => await _cloudClient.SolveAsync(request); + + public async Task> SolveAsync( + MTCaptchaTaskRequest request) => await _cloudClient.SolveAsync(request); + + public async Task> SolveAsync( + YidunTaskRequest request) => await _cloudClient.SolveAsync(request); public async Task GetBalanceAsync() { diff --git a/CapMonsterCloud.Client/CapMonsterCloud.Client.csproj b/CapMonsterCloud.Client/CapMonsterCloud.Client.csproj index 4745628..dbf5e3d 100644 --- a/CapMonsterCloud.Client/CapMonsterCloud.Client.csproj +++ b/CapMonsterCloud.Client/CapMonsterCloud.Client.csproj @@ -15,8 +15,8 @@ README.md logo.png https://github.com/ZennoLab/capmonstercloud-client-dotnet - 3.0.1 - Fixed DataDome request parameters + 3.1.0 + Add Yidun, Temu, Prosopo, MTCaptcha solving support diff --git a/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs b/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs index 2cd856c..c587a40 100644 --- a/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs +++ b/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs @@ -183,6 +183,45 @@ private static GetResultTimeouts GetTimeouts(Type type) Timeout = TimeSpan.FromSeconds(15) } }, + { + typeof(TemuCustomTaskRequest), + new GetResultTimeouts + { + FirstRequestDelay = TimeSpan.FromSeconds(1), + RequestsInterval = TimeSpan.FromSeconds(3), + Timeout = TimeSpan.FromSeconds(180) + } + }, + { + typeof(MTCaptchaTaskRequest), + new GetResultTimeouts + { + FirstRequestDelay = TimeSpan.FromSeconds(1), + FirstRequestNoCacheDelay = TimeSpan.FromSeconds(10), + RequestsInterval = TimeSpan.FromSeconds(3), + Timeout = TimeSpan.FromSeconds(180) + } + }, + { + typeof(YidunTaskRequest), + new GetResultTimeouts + { + FirstRequestDelay = TimeSpan.FromSeconds(1), + FirstRequestNoCacheDelay = TimeSpan.FromSeconds(10), + RequestsInterval = TimeSpan.FromSeconds(3), + Timeout = TimeSpan.FromSeconds(180) + } + }, + { + typeof(ProsopoTaskRequest), + new GetResultTimeouts + { + FirstRequestDelay = TimeSpan.FromSeconds(1), + FirstRequestNoCacheDelay = TimeSpan.FromSeconds(10), + RequestsInterval = TimeSpan.FromSeconds(3), + Timeout = TimeSpan.FromSeconds(180) + } + }, }; } } diff --git a/CapMonsterCloud.Client/Requests/MTCaptchaTaskRequest.cs b/CapMonsterCloud.Client/Requests/MTCaptchaTaskRequest.cs new file mode 100644 index 0000000..94f59a2 --- /dev/null +++ b/CapMonsterCloud.Client/Requests/MTCaptchaTaskRequest.cs @@ -0,0 +1,57 @@ +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using Zennolab.CapMonsterCloud.Responses; + +namespace Zennolab.CapMonsterCloud.Requests +{ + /// + /// MTCaptcha recognition request. + /// + /// + /// https://docs.capmonster.cloud/docs/captchas/mtcaptcha-task/ + /// + public sealed class MTCaptchaTaskRequest : CaptchaRequestBaseWithProxy + { + /// + /// Recognition task type + /// + public const string TaskType = "MTCaptchaTask"; + + /// + [JsonProperty("type", Required = Required.Always)] + public sealed override string Type => TaskType; + + /// + /// Address of a web page with MTCaptcha. + /// + [JsonProperty("websiteURL", Required = Required.Always)] + [Url] + public string WebsiteUrl { get; set; } + + /// + /// The MTCaptcha key (sk/sitekey). + /// + [JsonProperty("websiteKey", Required = Required.Always)] + [StringLength(int.MaxValue, MinimumLength = 1)] + public string WebsiteKey { get; set; } + + /// + /// true for invisible widget (has hidden confirmation field). + /// + [JsonProperty("isInvisible")] + public bool Invisible { get; set; } + + /// + /// Action value (passed as "act" and shown during token validation). + /// Provide only if it differs from default "%24". + /// + [JsonProperty("pageAction")] + public string PageAction { get; set; } + + /// + /// Browser's User-Agent (actual Windows UA recommended). + /// + [JsonProperty("userAgent")] + public string UserAgent { get; set; } + } +} \ No newline at end of file diff --git a/CapMonsterCloud.Client/Requests/ProsopoTaskRequest.cs b/CapMonsterCloud.Client/Requests/ProsopoTaskRequest.cs new file mode 100644 index 0000000..0a2cfe7 --- /dev/null +++ b/CapMonsterCloud.Client/Requests/ProsopoTaskRequest.cs @@ -0,0 +1,38 @@ +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using Zennolab.CapMonsterCloud.Responses; + +namespace Zennolab.CapMonsterCloud.Requests +{ + /// + /// Prosopo Procaptcha recognition request. + /// + /// + /// https://docs.capmonster.cloud/docs/captchas/prosopo-task + /// + public sealed class ProsopoTaskRequest : CaptchaRequestBaseWithProxy + { + /// + /// Recognition task type + /// + public const string TaskType = "ProsopoTask"; + + /// + [JsonProperty("type", Required = Required.Always)] + public sealed override string Type => TaskType; + + /// + /// The full URL of the CAPTCHA page. + /// + [JsonProperty("websiteURL", Required = Required.Always)] + [Url] + public string WebsiteUrl { get; set; } + + /// + /// The value of the "siteKey" parameter found on the page. + /// + [JsonProperty("websiteKey", Required = Required.Always)] + [StringLength(int.MaxValue, MinimumLength = 1)] + public string WebsiteKey { get; set; } + } +} \ No newline at end of file diff --git a/CapMonsterCloud.Client/Requests/TemuCustomTaskRequest.cs b/CapMonsterCloud.Client/Requests/TemuCustomTaskRequest.cs new file mode 100644 index 0000000..915a121 --- /dev/null +++ b/CapMonsterCloud.Client/Requests/TemuCustomTaskRequest.cs @@ -0,0 +1,41 @@ +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; + +namespace Zennolab.CapMonsterCloud.Requests +{ + /// + /// Temu CustomTask recognition request. + /// + /// + /// https://docs.capmonster.cloud/docs/captchas/temu-task + /// + public sealed class TemuCustomTaskRequest : CustomTaskRequestBase + { + /// + public override string Class => "Temu"; + + /// + /// Initializes Temu task with required metadata. + /// + /// + /// Cookies string from the page with captcha (document.cookie). + /// + public TemuCustomTaskRequest(string cookie) + { + Metadata = new { cookie }; + } + + /// + /// The full URL of the page where the CAPTCHA is loaded. + /// + [JsonProperty("websiteURL", Required = Required.Always)] + [Url] + public new string WebsiteUrl + { + get => base.WebsiteUrl; + set => base.WebsiteUrl = value; + } + + // userAgent, Proxy, Domains — уже есть в базе (CustomTaskRequestBase) + } +} \ No newline at end of file diff --git a/CapMonsterCloud.Client/Requests/YidunTaskRequest.cs b/CapMonsterCloud.Client/Requests/YidunTaskRequest.cs new file mode 100644 index 0000000..7b6030c --- /dev/null +++ b/CapMonsterCloud.Client/Requests/YidunTaskRequest.cs @@ -0,0 +1,74 @@ +using Newtonsoft.Json; +using System.ComponentModel.DataAnnotations; +using Zennolab.CapMonsterCloud.Responses; + +namespace Zennolab.CapMonsterCloud.Requests +{ + /// + /// Yidun (NECaptcha) recognition request. + /// + /// + /// https://docs.capmonster.cloud/docs/captchas/yidun-task + /// + public sealed class YidunTaskRequest : CaptchaRequestBaseWithProxy + { + /// + /// Recognition task type + /// + public const string TaskType = "YidunTask"; + + /// + [JsonProperty("type", Required = Required.Always)] + public override sealed string Type => TaskType; + + /// + /// Full URL of the page with the captcha. + /// + [JsonProperty("websiteURL", Required = Required.Always)] + [Url] + public string WebsiteUrl { get; set; } + + /// + /// The siteKey value found on the page. + /// + [JsonProperty("websiteKey", Required = Required.Always)] + [StringLength(int.MaxValue, MinimumLength = 1)] + public string WebsiteKey { get; set; } + + /// + /// Browser User-Agent (actual Windows UA recommended). + /// + [JsonProperty("userAgent")] + public string UserAgent { get; set; } + + /// + /// Full URL of JS loader (Enterprise cases). + /// + [JsonProperty("yidunGetLib")] + public string YidunGetLib { get; set; } + + /// + /// Custom API server subdomain (Enterprise cases). + /// + [JsonProperty("yidunApiServerSubdomain")] + public string YidunApiServerSubdomain { get; set; } + + /// + /// Enterprise: current captcha challenge id. + /// + [JsonProperty("challenge")] + public string Challenge { get; set; } + + /// + /// Enterprise: captcha hash. + /// + [JsonProperty("hcg")] + public string Hcg { get; set; } + + /// + /// Enterprise: numeric timestamp. + /// + [JsonProperty("hct")] + public long? Hct { get; set; } + } +} diff --git a/CapMonsterCloud.Client/Responses/MTCaptchaTaskResponse.cs b/CapMonsterCloud.Client/Responses/MTCaptchaTaskResponse.cs new file mode 100644 index 0000000..298e743 --- /dev/null +++ b/CapMonsterCloud.Client/Responses/MTCaptchaTaskResponse.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Zennolab.CapMonsterCloud.Responses +{ + /// + /// MTCaptcha recognition response + /// + public sealed class MTCaptchaTaskResponse : CaptchaResponseBase + { + /// + /// MTCaptcha token to submit to the target site. + /// + [JsonProperty("token")] + public string Value { get; set; } + } +} \ No newline at end of file diff --git a/CapMonsterCloud.Client/Responses/ProsopoTaskResponse.cs b/CapMonsterCloud.Client/Responses/ProsopoTaskResponse.cs new file mode 100644 index 0000000..87069c9 --- /dev/null +++ b/CapMonsterCloud.Client/Responses/ProsopoTaskResponse.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Zennolab.CapMonsterCloud.Responses +{ + /// + /// Prosopo Procaptcha recognition response + /// + public sealed class ProsopoTaskResponse : CaptchaResponseBase + { + /// + /// Prosopo token + /// + /// + /// 0x00016c68747470733a2f2f70726f6e6f6465332e70726f736f706f2e696f... + /// + [JsonProperty("token")] + public string Value { get; set; } + } +} \ No newline at end of file diff --git a/CapMonsterCloud.Client/Responses/YidunTaskResponse.cs b/CapMonsterCloud.Client/Responses/YidunTaskResponse.cs new file mode 100644 index 0000000..456cb67 --- /dev/null +++ b/CapMonsterCloud.Client/Responses/YidunTaskResponse.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Zennolab.CapMonsterCloud.Responses +{ + /// + /// Yidun (NECaptcha) recognition response + /// + public sealed class YidunTaskResponse : CaptchaResponseBase + { + /// + /// Yidun token to submit. + /// + [JsonProperty("token")] + public string Value { get; set; } + } +} \ No newline at end of file