diff --git a/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs b/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs index 4637303..cfcf589 100644 --- a/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs +++ b/CapMonsterCloud.Client.IntegrationTests/IntegrationTests.cs @@ -1203,5 +1203,51 @@ public async Task Yidun_ShouldSolve() 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 2b35809..0abcf17 100644 --- a/CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs +++ b/CapMonsterCloud.Client.IntegrationTests/ObjectGen.cs @@ -624,7 +624,7 @@ public static YidunTaskRequest CreateTask() WebsiteUrl = Gen.RandomUri().ToString(), WebsiteKey = Gen.RandomString(), UserAgent = Gen.UserAgent(), - // Enterprise поля по желанию: + // Enterprise : YidunGetLib = Gen.RandomUri().ToString(), YidunApiServerSubdomain = Gen.RandomString(), Challenge = Gen.RandomString(), @@ -648,5 +648,30 @@ public static CaptchaResult CreateSolution() }; } } + + 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 37ffe86..8ed962a 100644 --- a/CapMonsterCloud.Client.IntegrationTests/Sut.cs +++ b/CapMonsterCloud.Client.IntegrationTests/Sut.cs @@ -97,6 +97,9 @@ 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); diff --git a/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs b/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs index 8b5e47d..c587a40 100644 --- a/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs +++ b/CapMonsterCloud.Client/CapMonsterCloudClient_GetResultTimeouts.cs @@ -212,6 +212,16 @@ private static GetResultTimeouts GetTimeouts(Type type) 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/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/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