diff --git a/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs b/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs index 2d07a25..d3d88fd 100644 --- a/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs +++ b/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs @@ -1117,6 +1117,48 @@ public async Task Temu_ShouldSolve() 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); + } } } \ No newline at end of file diff --git a/CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs b/CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs index 793baf5..df8e73b 100644 --- a/CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs +++ b/CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs @@ -583,7 +583,36 @@ public static CaptchaResult CreateSolution() } }; } + } + + 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() + } + }; + } } } } \ No newline at end of file diff --git a/CapMonsterCloud.Client.IntegrationTests/Sut.cs b/CapMonsterCloud.Client.IntegrationTests/Sut.cs index 9a12bde..57de39b 100644 --- a/CapMonsterCloud.Client.IntegrationTests/Sut.cs +++ b/CapMonsterCloud.Client.IntegrationTests/Sut.cs @@ -101,6 +101,8 @@ public async Task> SolveAsync( public async Task> SolveAsync( TemuCustomTaskRequest request) => await _cloudClient.SolveAsync(request); + public async Task> SolveAsync( + MTCaptchaTaskRequest request) => await _cloudClient.SolveAsync(request); public async Task GetBalanceAsync() { diff --git a/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs b/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs index df4508c..eae38fb 100644 --- a/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs +++ b/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs @@ -192,6 +192,15 @@ private static GetResultTimeouts GetTimeouts(Type type) Timeout = TimeSpan.FromSeconds(180) } }, - }; + { + typeof(MTCaptchaTaskRequest), + 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/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