Skip to content

Commit

Permalink
UPDATE: updated for latest version compability
Browse files Browse the repository at this point in the history
  • Loading branch information
alperensert committed Feb 21, 2023
1 parent 33377a4 commit 13b6949
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 99 deletions.
3 changes: 1 addition & 2 deletions CapSolver.Tests/BaseMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ public async void TestBalance()
{
var client = new CapSolverClient(Environment.GetEnvironmentVariable("APIKEY")!, false);
float balance = await client.GetBalance();
Assert.NotNull(balance);
Assert.IsType<float>(balance);
Assert.True(default (float) != balance);
Assert.True(default != balance);
}

[Fact]
Expand Down
19 changes: 0 additions & 19 deletions CapSolver.Tests/FunCaptchaTaskTest.cs

This file was deleted.

2 changes: 1 addition & 1 deletion CapSolver/CapSolverClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<string> CreateTask(ITask task)
{
JObject vt = JObject.FromObject(t);
JObject t_ = JObject.FromObject(task);
t_["type"] += "Proxyless";
t_["type"] += "ProxyLess";
vt["task"] = t_;
data = vt.ToString();
}
Expand Down
7 changes: 5 additions & 2 deletions CapSolver/Models/Responses/DatadomeSliderResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ namespace CapSolver.Models.Responses;

public class DatadomeSliderResponse : ITaskResponse
{
[JsonRequired]
[JsonProperty("cookie")]
public string Cookie { get; set; } = null!;
public string Cookie { get; set; }

[JsonRequired]
[JsonProperty("userAgent")]
public string UserAgent { get; set; } = null!;
}
4 changes: 0 additions & 4 deletions CapSolver/Models/Responses/GeeTestResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ public class GeeTestResponse : ITaskResponse
[JsonRequired]
[JsonProperty("validate")]
public string Validate { get; set; } = null!;

[JsonRequired]
[JsonProperty("seccode")]
public string SecCode { get; set; } = null!;
}
25 changes: 25 additions & 0 deletions CapSolver/Models/Responses/GeeTestV4Response.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;

namespace CapSolver.Models.Responses;

public class GeeTestV4Response
{
[JsonProperty("captcha_id")]
public string CaptchaId { get; set; }

[JsonProperty("captcha_output")]
public string CaptchaOutput { get; set; }

[JsonProperty("gen_time")]
public string GenTime { get; set; }

[JsonProperty("lot_number")]
public string LotNumber { get; set; }

[JsonProperty("pass_token")]
public string Token { get; set; }

[JsonProperty("risk_type")]
public string RiskType { get; set; }

}
6 changes: 6 additions & 0 deletions CapSolver/Models/Responses/HCaptchaClassificationResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ public class HCaptchaClassificationResponse : ITaskResponse
[JsonRequired]
[JsonProperty("objects")]
public IList<bool> Objects { get; set; } = null!;

[JsonProperty("box")]
public IList<float>? Box { get; set; }

[JsonProperty("imageSize")]
public Tuple<int, int> ImageSize { get; set; }
}
12 changes: 11 additions & 1 deletion CapSolver/Models/Responses/HCaptchaTaskResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
using CapSolver.Utilities;
using Newtonsoft.Json;

namespace CapSolver.Models.Responses;

public class HCaptchaTaskResponse : ReCaptchaV2Response, ITaskResponse { }
public class HCaptchaTaskResponse : ReCaptchaV2Response, ITaskResponse
{
[JsonRequired]
[JsonProperty("timestamp")]
public long Timestamp { get; set; }

[JsonRequired]
[JsonProperty("captchaKey")]
public string CaptchaKey { get; set; } = null!;
}
6 changes: 4 additions & 2 deletions CapSolver/Models/Responses/MtCaptchaResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace CapSolver.Models.Responses;

public class MtCaptchaResponse : ITaskResponse
{
[JsonRequired]
[JsonProperty("token")]
public string Token { get; set; } = null!;
public string Token { get; set; }

[JsonProperty("userAgent")]
public string UserAgent { get; set; }
}
6 changes: 6 additions & 0 deletions CapSolver/Models/Responses/ReCaptchaV2Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ public class ReCaptchaV2Response : ITaskResponse
[JsonRequired]
[JsonProperty("gRecaptchaResponse")]
public string GReCaptchaResponse { get; set; } = null!;

[JsonProperty("userAgent")]
public string UserAgent { get; set; } = null!;

[JsonProperty("expireTime")]
public long ExpireTime { get; set; }
}
5 changes: 4 additions & 1 deletion CapSolver/Models/Responses/ReCaptchaV3Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

namespace CapSolver.Models.Responses;

public class ReCaptchaV3Response : ReCaptchaV2Response, ITaskResponse { }
public class ReCaptchaV3Response : ReCaptchaV2Response, ITaskResponse
{

}
4 changes: 4 additions & 0 deletions CapSolver/Tasks/AwsWafClassificationTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ public class AwsWafClassificationTask : ITask

/// <summary>
/// For full names of questions, please refer to the following list of questions.
/// <br />
/// See question allow list: <seealso href="https://docs.capsolver.com/guide/recognition/AwsWafClassification.html#create-task">click here</seealso>
/// </summary>
[JsonProperty("question", NullValueHandling = NullValueHandling.Include)]
public string Question { get; set; }

/// <summary>
/// Prepare a AwsWafClassification task.
/// <br/>
/// See supported types: <seealso href="https://docs.capsolver.com/guide/recognition/AwsWafClassification.html#support-types">click here</seealso>
/// </summary>
/// <param name="images">Base64-encoded images, do not include "data:image/***;base64,"Base64-encoded images, do not include "data:image/***;base64,"</param>
/// <param name="question">For full names of questions, please refer to the following list of questions.</param>
Expand Down
6 changes: 5 additions & 1 deletion CapSolver/Tasks/FunCaptchaClassification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ public class FunCaptchaClassification : ITask
/// Only support English requires accurate case, other languages please convert to English yourself
/// The server will automatically determine different image types according to the question, so please make sure the question is correct.
/// Please see the list at the end of the document for the full list of image types and corresponding English questions
/// <br/>
/// See the supported question list: <seealso href="https://docs.capsolver.com/guide/recognition/FunCaptchaClassification.html#create-task">click here</seealso>
/// </summary>
[JsonRequired]
[JsonProperty("question")]
public string Question { get; set; }

/// <summary>
/// Prepare a FunCaptchaClassification task.
/// <br/>
/// See supported types of FunCaptcha: <seealso href="https://docs.capsolver.com/guide/recognition/FunCaptchaClassification.html#supported-types">click here</seealso>
/// </summary>
/// <param name="image">Base64 encoded image, can be a screenshot (pass only the hexagonal image, do not pass the rest of the content)</param>
/// <param name="question">Question name. Pass the full name, such as: Pick the lion. Only support English requires accurate case, other languages please convert to English yourself</param>
/// <param name="question">Question name. Pass the full name, such as: Pick the lion. Only support English requires accurate case, other languages please convert to English yourself.<br/>See the supported question list: <seealso href="https://docs.capsolver.com/guide/recognition/FunCaptchaClassification.html#create-task">click here</seealso></param>
public FunCaptchaClassification(string image, string question)
{
Image = image;
Expand Down
4 changes: 2 additions & 2 deletions CapSolver/Tasks/FunCaptchaTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FunCaptchaTask : ITask, IProxyTask, IUserAgentTask
/// A special subdomain of funcaptcha.com, from which the JS captcha widget should be loaded. Most FunCaptcha installations work from shared domains.
/// </summary>
[JsonProperty("funcaptchaApiJSSubdomain")]
public string ApiJsSubdomain { get; set; }
public string? ApiJsSubdomain { get; set; }

/// <summary>
/// Additional parameter that may be required by FunCaptcha implementation. Use this property to send "blob" value as a stringified array. See example how it may look like.
Expand All @@ -51,7 +51,7 @@ public class FunCaptchaTask : ITask, IProxyTask, IUserAgentTask
/// <param name="data">Additional parameter that may be required by FunCaptcha implementation. Use this property to send "blob" value as a stringified array. See example how it may look like. </param>
public FunCaptchaTask(string websiteUrl,
string websitePublicKey,
string apiJsSubdomain,
string? apiJsSubdomain = null,
string? data = null,
string? userAgent = null)
{
Expand Down
63 changes: 17 additions & 46 deletions CapSolver/Tasks/GeeTestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace CapSolver.Tasks;
public class GeeTestTask : ITask, IProxyTask, IUserAgentTask, ICookieTask
{
[JsonProperty("type")]
private readonly string Type = "GeetestTask";
private readonly string Type = "GeeTestTask";

/// <summary>
/// Address of a webpage with Geetest
Expand All @@ -19,83 +19,54 @@ public class GeeTestTask : ITask, IProxyTask, IUserAgentTask, ICookieTask
/// <summary>
/// The domain public key, rarely updated.
/// </summary>
[JsonRequired]
[JsonProperty("gt")]
public string Gt { get; set; }
[JsonProperty("gt", NullValueHandling = NullValueHandling.Ignore)]
public string? Gt { get; set; }

/// <summary>
/// Changing token key. Make sure you grab a fresh one for each captcha; otherwise, you'll be charged for an error task.
/// </summary>
[JsonRequired]
[JsonProperty("challenge")]
public string Challenge { get; set; }
[JsonProperty("challenge", NullValueHandling = NullValueHandling.Ignore)]
public string? Challenge { get; set; }

[JsonProperty("captchaId")]
public string? CaptchaId { get; set; }

/// <summary>
/// Optional API subdomain. May be required for some implementations.
/// </summary>
[JsonProperty("geetestApiServerSubdomain", NullValueHandling = NullValueHandling.Ignore)]
public string? ApiServerSubdomain { get; set; }

/// <summary>
/// Required for some implementations. Send the JSON encoded into a string. The value can be traced in browser developer tools. Put a breakpoint before calling the "initGeetest" function.
/// </summary>
[JsonProperty("geetestGetLib", NullValueHandling = NullValueHandling.Ignore)]
public string? GeeTestGetLib { get; set; }

/// <summary>
/// Version number. Default version is 3.
/// </summary>
[JsonProperty("version", NullValueHandling = NullValueHandling.Ignore)]
public string? Version { get; set; }

/// <summary>
/// Additional initialization parameters for version 4
/// </summary>
[JsonProperty("initParameters", NullValueHandling = NullValueHandling.Ignore)]
public string? InitParameters { get; set; }

/// <summary>
/// Browser's User-Agent which is used in emulation. It is required that you use a signature of a modern browser, otherwise Google will ask you to "update your browser".
/// </summary>
[JsonProperty("userAgent", NullValueHandling = NullValueHandling.Ignore)]
public string? UserAgent { get; set; }

/// <summary>
/// Additional cookies which we must use during interaction with target page or Google.
/// </summary>
[JsonProperty("cookies", NullValueHandling = NullValueHandling.Ignore)]
public string? Cookies { get; set; }

/// <summary>
/// Preapre a GeeTest task
/// </summary>
/// <param name="websiteUrl">Address of a webpage with Geetest</param>
/// <param name="gt">The domain public key, rarely updated.</param>
/// <param name="challenge">Changing token key. Make sure you grab a fresh one for each captcha; otherwise, you'll be charged for an error task.</param>
/// <param name="apiServerSubdomain">Optional API subdomain. May be required for some implementations.</param>
/// <param name="getLib">Required for some implementations. Send the JSON encoded into a string. The value can be traced in browser developer tools. Put a breakpoint before calling the "initGeetest" function.</param>
/// <param name="version">Version number. Default version is 3.</param>
/// <param name="initParameters">Additional initialization parameters for version 4</param>
/// <param name="cookies">Additional cookies which we must use during interaction with target page or Google.</param>
/// <param name="userAgent">Browser's User-Agent which is used in emulation.</param>
public GeeTestTask(string websiteUrl,
string gt,
string challenge,
string? gt = null,
string? challenge = null,
string? apiServerSubdomain = null,
string? getLib = null,
string? version = null,
string? initParameters = null,
string? cookies = null,
string? userAgent = null)
string? userAgent = null,
string? captchaId = null)
{
WebsiteURL = websiteUrl;
Gt = gt;
Challenge = challenge;
ApiServerSubdomain = apiServerSubdomain;
GeeTestGetLib = getLib;
Version = version;
InitParameters = initParameters;
UserAgent = userAgent;
Cookies = cookies;
CaptchaId = captchaId;
if (gt != null && challenge != null)
{
CaptchaId = null;
}
}
}
12 changes: 5 additions & 7 deletions CapSolver/Tasks/HCaptchaTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public class HCaptchaTask : ITask, IProxyTask, IUserAgentTask
[JsonProperty("enterprisePayload", NullValueHandling = NullValueHandling.Ignore)]
public object? EnterprisePayload { get; set; }

/// <summary>
/// Use true for enterprise version of hcaptcha
/// </summary>
[JsonProperty("isEnterprise", NullValueHandling = NullValueHandling.Ignore)]
public bool? IsEnterprise { get; set; }

/// <summary>
/// Use true for invisible version of hcaptcha
/// </summary>
Expand All @@ -57,6 +51,7 @@ public class HCaptchaTask : ITask, IProxyTask, IUserAgentTask
/// <param name="enterprisePayload">Custom data that is used in some implementations of hCaptcha Enterprise. So you need to put true in the isEnterprise parameter. In most cases you see it as rqdata inside network requests. IMPORTANT: you MUST provide userAgent if you submit captcha with data parameter. The value should match the User-Agent you use when interacting with the target website.</param>
/// <param name="isEnterprise">Use true for enterprise version of hcaptcha</param>
/// <param name="isInvisible">Use true for invisible version of hcaptcha</param>
/// <param name="userAgent">Browser's User-Agent which is used in emulation.</param>
public HCaptchaTask(string websiteUrl,
string websiteKey,
object? enterprisePayload = null,
Expand All @@ -67,8 +62,11 @@ public class HCaptchaTask : ITask, IProxyTask, IUserAgentTask
WebsiteURL = websiteUrl;
WebsiteKey = websiteKey;
EnterprisePayload = enterprisePayload;
IsEnterprise = isEnterprise;
IsInvisible = isInvisible;
UserAgent = userAgent;
if (isEnterprise == true)
{
Type = "HCaptchaEnterpriseTask";
}
}
}
24 changes: 23 additions & 1 deletion CapSolver/Tasks/ImageToTextTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,34 @@ public class ImageToTextTask : ITask
[JsonProperty("body")]
public string Body { get; set; }

/// <summary>
/// Specifies the module. Currently, the supported modules are common and queueit.
/// </summary>
[JsonProperty("module")]
public string? Module { get; set; }

/// <summary>
/// Identify the matching degree. If the recognition rate is not within the range, no deduction
/// </summary>
/// <value>0.8 ~ 1</value>
[JsonProperty("score")]
public float? Score { get; set; }

/// <summary>
/// Case sensitive or not
/// </summary>
[JsonProperty("case")]
public bool? Case { get; set; }

/// <summary>
/// Prepare an image to text task.
/// </summary>
/// <param name="body">Base64 encoded content of the image (without line breaks)</param>
public ImageToTextTask(string body)
public ImageToTextTask(string body, string? module = null, float? score = null, bool? caseSensitive = null)
{
Body = body;
Module = module;
Score = score;
Case = caseSensitive;
}
}
Loading

0 comments on commit 13b6949

Please sign in to comment.