Added RuCaptcha support [credits to mastercho].

This commit is contained in:
ruri
2019-05-08 13:04:39 +02:00
parent 4ccb2b7c1e
commit 96de7b9671
8 changed files with 129 additions and 1 deletions
@@ -23,6 +23,10 @@
<Label DockPanel.Dock="Left" Content="2Captcha API Key" />
<TextBox DockPanel.Dock="Left" Text="{Binding TwoCapToken}" />
</DockPanel>
<DockPanel>
<Label DockPanel.Dock="Left" Content="RuCaptcha API Key" />
<TextBox DockPanel.Dock="Left" Text="{Binding RuCapToken}" />
</DockPanel>
<DockPanel>
<Label DockPanel.Dock="Left" Content="AZCaptcha API Key" />
<TextBox DockPanel.Dock="Left" Text="{Binding AZCapToken}" />
@@ -58,6 +58,10 @@ namespace OpenBullet
balance = new TwoCaptcha(Globals.rlSettings.Captchas.TwoCapToken, 0).GetBalance();
break;
case BlockCaptcha.CaptchaService.RuCaptcha:
balance = new RuCaptcha(Globals.rlSettings.Captchas.RuCapToken, 0).GetBalance();
break;
case BlockCaptcha.CaptchaService.AZCaptcha:
balance = new AZCaptcha(Globals.rlSettings.Captchas.AZCapToken, 0).GetBalance();
break;
+8 -1
View File
@@ -37,7 +37,10 @@ namespace RuriLib
SolveRecaptcha,
/// <summary>The service provided by https://2captcha.com/</summary>
TwoCaptcha
TwoCaptcha,
/// <summary>The service provided by https://rucaptcha.com/</summary>
RuCaptcha
}
/// <summary>The balance of the account of the captcha-solving service.</summary>
@@ -73,6 +76,10 @@ namespace RuriLib
Balance = new TwoCaptcha(data.GlobalSettings.Captchas.TwoCapToken, 0).GetBalance();
break;
case CaptchaService.RuCaptcha:
Balance = new RuCaptcha(data.GlobalSettings.Captchas.RuCapToken, 0).GetBalance();
break;
case CaptchaService.DeCaptcher:
Balance = new DeCaptcher(data.GlobalSettings.Captchas.DCUser, data.GlobalSettings.Captchas.DCPass, 0).GetBalance();
break;
+4
View File
@@ -142,6 +142,10 @@ namespace RuriLib
service = new TwoCaptcha(data.GlobalSettings.Captchas.TwoCapToken, data.GlobalSettings.Captchas.Timeout);
break;
case CaptchaService.RuCaptcha:
service = new RuCaptcha(data.GlobalSettings.Captchas.RuCapToken, data.GlobalSettings.Captchas.Timeout);
break;
case CaptchaService.DeCaptcher:
service = new DeCaptcher(data.GlobalSettings.Captchas.DCUser, data.GlobalSettings.Captchas.DCPass, data.GlobalSettings.Captchas.Timeout);
break;
+4
View File
@@ -104,6 +104,10 @@ namespace RuriLib
service = new TwoCaptcha(data.GlobalSettings.Captchas.TwoCapToken, data.GlobalSettings.Captchas.Timeout);
break;
case CaptchaService.RuCaptcha:
service = new RuCaptcha(data.GlobalSettings.Captchas.RuCapToken, data.GlobalSettings.Captchas.Timeout);
break;
case CaptchaService.DeCaptcher:
service = new DeCaptcher(data.GlobalSettings.Captchas.DCUser, data.GlobalSettings.Captchas.DCPass, data.GlobalSettings.Captchas.Timeout);
break;
+100
View File
@@ -0,0 +1,100 @@
using Newtonsoft.Json;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Net;
using System.Threading;
namespace RuriLib.CaptchaServices
{
/// <summary>
/// Implements the API of https://rucaptcha.com
/// </summary>
public class RuCaptcha : CaptchaService
{
/// <summary>
/// Creates a RuCaptcha client.
/// </summary>
/// <param name="apiKey">The RuCaptcha API key</param>
/// <param name="timeout">The maximum time to wait for the challenge to be solved</param>
public RuCaptcha(string apiKey, int timeout) : base(apiKey, timeout) { }
/// <inheritdoc />
public override double GetBalance()
{
using (CWebClient client = new CWebClient())
{
if (Timeout > 0) client.Timeout = Timeout;
var response = client.DownloadString($"http://rucaptcha.com/res.php?key={ApiKey}&action=getbalance");
return double.Parse(response, CultureInfo.InvariantCulture);
}
}
/// <inheritdoc />
public override string SolveRecaptcha(string siteKey, string siteUrl)
{
// Create task
using (CWebClient client = new CWebClient())
{
if (Timeout > 0) client.Timeout = Timeout;
var response = client.DownloadString($"http://rucaptcha.com/in.php?key={ApiKey}&method=userrecaptcha&googlekey={siteKey}&pageurl={siteUrl}");
if (!response.StartsWith("OK")) throw new Exception(response);
TaskId = response.Split('|')[1];
Status = CaptchaStatus.Processing;
// Check if task has been completed
DateTime start = DateTime.Now;
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
{
Thread.Sleep(5000);
response = client.DownloadString($"http://rucaptcha.com/res.php?key={ApiKey}&action=get&id={TaskId}");
if (response.Contains("NOT_READY")) continue;
if (response.Contains("ERROR")) throw new Exception(response);
Status = CaptchaStatus.Completed;
return response.Split('|')[1];
}
throw new TimeoutException();
}
}
/// <inheritdoc />
public override string SolveCaptcha(Bitmap bitmap)
{
// Create task
using (CWebClient client = new CWebClient())
{
if (Timeout > 0) client.Timeout = Timeout;
client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
var response = client.UploadString("http://rucaptcha.com/in.php",
$"key={ApiKey}&method=base64&regsense=1&body={Uri.EscapeDataString(GetBase64(bitmap, ImageFormat.Bmp))}");
if (!response.StartsWith("OK")) throw new Exception(response);
TaskId = response.Split('|')[1];
Status = CaptchaStatus.Processing;
// Check if task has been completed
DateTime start = DateTime.Now;
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
{
Thread.Sleep(5000);
response = client.DownloadString($"http://rucaptcha.com/res.php?key={ApiKey}&action=get&id={TaskId}");
if (response.Contains("NOT_READY")) continue;
if (response.Contains("ERROR")) throw new Exception(response);
Status = CaptchaStatus.Completed;
return response.Split('|')[1];
}
throw new TimeoutException();
}
}
#pragma warning disable 0414
#pragma warning disable 0649
class GenericResponse
{
public int status;
public string request;
}
#pragma warning restore 0414
#pragma warning restore 0649
}
}
+1
View File
@@ -136,6 +136,7 @@
<Compile Include="Blocks\BlockLSCode.cs" />
<Compile Include="Blocks\BlockTCP.cs" />
<Compile Include="CaptchaServices\CaptchasIO.cs" />
<Compile Include="CaptchaServices\RuCaptcha.cs" />
<Compile Include="LoliScript\Exceptions\BlockProcessingException.cs" />
<Compile Include="LoliScript\LoliScript.cs" />
<Compile Include="LoliScript\Parser\BlockParser.cs" />
@@ -32,6 +32,10 @@ namespace RuriLib.ViewModels
/// <summary>The TwoCaptcha API Token.</summary>
public string TwoCapToken { get { return twoCapToken; } set { twoCapToken = value; OnPropertyChanged(); } }
private string ruCapToken = "";
/// <summary>The RuCaptcha API Token.</summary>
public string RuCapToken { get { return ruCapToken; } set { ruCapToken = value; OnPropertyChanged(); } }
private string dcUser = "";
/// <summary>The DeCaptcher Username.</summary>
public string DCUser { get { return dcUser; } set { dcUser = value; OnPropertyChanged(); } }