Skip to content

Commit 384d4de

Browse files
1st commit
0 parents  commit 384d4de

14 files changed

+862
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.IO;
6+
using Newtonsoft.Json;
7+
using Newtonsoft.Json.Linq;
8+
9+
namespace bestcaptchasolver
10+
{
11+
public class BestCaptchaSolverAPI
12+
{
13+
private const string BASE_URL = "https://bcsapi.xyz/api";
14+
private const string USER_AGENT = "csharpClient1.0";
15+
private const int TIMEOUT = 30000;
16+
17+
private string _access_token;
18+
private int _timeout;
19+
20+
/// <summary>
21+
/// Constructor
22+
/// </summary>
23+
/// <param name="access_token"></param>
24+
/// <param name="timeout"></param>
25+
public BestCaptchaSolverAPI(string access_token, int timeout = 30000)
26+
{
27+
this._access_token = access_token;
28+
this._timeout = timeout;
29+
}
30+
31+
/// <summary>
32+
/// Get account's balance
33+
/// </summary>
34+
/// <returns></returns>
35+
public string account_balance()
36+
{
37+
var url = string.Format("{0}/user/balance?access_token={1}", BASE_URL, this._access_token);
38+
var resp = Utils.GET(url, USER_AGENT, TIMEOUT);
39+
dynamic d = JObject.Parse(resp);
40+
return string.Format("${0}", d.balance.ToString());
41+
}
42+
43+
/// <summary>
44+
/// Submit image captcha
45+
/// </summary>
46+
/// <param name="opts"></param>
47+
/// <returns>captchaID</returns>
48+
public string submit_image_captcha(Dictionary<string, string> opts)
49+
{
50+
Dictionary<string, string> dict = new Dictionary<string, string>();
51+
var url = string.Format("{0}/captcha/image", BASE_URL);
52+
dict.Add("access_token", this._access_token);
53+
var image = "";
54+
// if no b64 string was given, but image path instead
55+
if (File.Exists(opts["image"])) image = Utils.read_captcha_image(opts["image"]);
56+
else image = opts["image"];
57+
dict.Add("b64image", image);
58+
// check case sensitive
59+
if (opts.ContainsKey("case_sensitive"))
60+
{
61+
if (opts["case_sensitive"].Equals("true")) dict.Add("case_sensitive", "1");
62+
}
63+
// affiliate ID
64+
if (opts.ContainsKey("affiliate_id")) dict.Add("affiliate_id", opts["affiliate_id"]);
65+
var data = JsonConvert.SerializeObject(dict);
66+
var resp = Utils.POST(url, data, USER_AGENT, TIMEOUT);
67+
dynamic d = JObject.Parse(resp);
68+
return d.id.ToString();
69+
}
70+
/// <summary>
71+
/// Submit image captcha
72+
/// </summary>
73+
/// <param name="opts"></param>
74+
/// <returns>captchaID</returns>
75+
public string submit_recaptcha(Dictionary<string, string> opts)
76+
{
77+
Dictionary<string, string> dict = new Dictionary<string, string>();
78+
var url = string.Format("{0}/captcha/recaptcha", BASE_URL);
79+
dict.Add("access_token", this._access_token);
80+
dict.Add("page_url", opts["page_url"]);
81+
dict.Add("site_key", opts["site_key"]);
82+
if(opts.ContainsKey("proxy"))
83+
{
84+
dict.Add("proxy", opts["proxy"]);
85+
dict.Add("proxy_type", "HTTP");
86+
}
87+
88+
// optional params
89+
if (opts.ContainsKey("type")) dict.Add("type", opts["type"]);
90+
if (opts.ContainsKey("v3_action")) dict.Add("v3_action", opts["v3_action"]);
91+
if (opts.ContainsKey("v3_min_score")) dict.Add("v3_min_score", opts["v3_min_score"]);
92+
if (opts.ContainsKey("user_agent")) dict.Add("user_agent", opts["user_agent"]);
93+
if (opts.ContainsKey("affiliate_id")) dict.Add("affiliate_id", opts["affiliate_id"]);
94+
95+
var data = JsonConvert.SerializeObject(dict);
96+
var resp = Utils.POST(url, data, USER_AGENT, TIMEOUT);
97+
dynamic d = JObject.Parse(resp);
98+
return d.id.ToString();
99+
}
100+
101+
/// <summary>
102+
/// Retrieve captcha text / gresponse using captcha ID
103+
/// </summary>
104+
/// <param name="captchaid"></param>
105+
/// <returns></returns>
106+
public Dictionary<string, string> retrieve(string captchaid)
107+
{
108+
var url = string.Format("{0}/captcha/{1}?access_token={2}", BASE_URL, captchaid, this._access_token);
109+
string resp = Utils.GET(url, USER_AGENT, TIMEOUT);
110+
JObject d = JObject.Parse(resp);
111+
// check if still in pending
112+
if (d.GetValue("status").ToString() == "pending")
113+
{
114+
var dd = new Dictionary<string, string>();
115+
dd.Add("gresponse", "");
116+
dd.Add("text", "");
117+
return dd;
118+
}
119+
// we're good, create dict and return
120+
var dict = new Dictionary<string, string>();
121+
foreach(var e in d)
122+
{
123+
dict.Add(e.Key, e.Value.ToString());
124+
}
125+
return dict;
126+
}
127+
128+
/// <summary>
129+
/// Set captcha bad
130+
/// </summary>
131+
/// <param name="captchaid"></param>
132+
/// <returns></returns>
133+
public string set_captcha_bad(string captchaid)
134+
{
135+
Dictionary<string, string> dict = new Dictionary<string, string>();
136+
var url = string.Format("{0}/captcha/bad/{1}", BASE_URL, captchaid);
137+
dict.Add("access_token", this._access_token);
138+
var data = JsonConvert.SerializeObject(dict);
139+
var resp = Utils.POST(url, data, USER_AGENT, TIMEOUT);
140+
dynamic d = JObject.Parse(resp);
141+
return d.status.ToString();
142+
}
143+
}
144+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("BestCaptchaSolverAPI")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("BestCaptchaSolverAPI")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("91e2718d-be3f-4893-a663-80b5ff34dcba")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

BestCaptchaSolverAPI/Utils.cs

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Net;
6+
using System.Net.Security;
7+
using System.Text;
8+
9+
namespace bestcaptchasolver
10+
{
11+
static class Utils
12+
{
13+
/// <summary>
14+
/// GET request
15+
/// </summary>
16+
/// <param name="url"></param>
17+
/// <returns></returns>
18+
public static string GET(string url, string user_agent, int timeout)
19+
{
20+
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
21+
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
22+
request.UserAgent = user_agent;
23+
request.Timeout = timeout;
24+
request.ReadWriteTimeout = timeout;
25+
request.Accept = "*/*";
26+
request.ContentType = "application/json";
27+
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
28+
using (Stream stream = response.GetResponseStream())
29+
using (StreamReader reader = new StreamReader(stream))
30+
{
31+
return reader.ReadToEnd();
32+
}
33+
}
34+
/// <summary>
35+
/// POST request
36+
/// </summary>
37+
/// <param name="url"></param>
38+
/// <param name="post_data"></param>
39+
/// <param name="user_agent"></param>
40+
/// <param name="timeout"></param>
41+
/// <returns></returns>
42+
public static string POST(string url, string post_data, string user_agent, int timeout)
43+
{
44+
var request = (HttpWebRequest)WebRequest.Create(url);
45+
var data = Encoding.ASCII.GetBytes(post_data);
46+
request.Method = "POST";
47+
request.ContentType = "application/json";
48+
request.ContentLength = data.Length;
49+
// set user agent and timeout
50+
request.UserAgent = user_agent;
51+
request.Timeout = timeout;
52+
request.ReadWriteTimeout = timeout;
53+
request.Accept = "*/*";
54+
55+
using (var stream = request.GetRequestStream())
56+
{
57+
stream.Write(data, 0, data.Length);
58+
}
59+
60+
HttpWebResponse response = null;
61+
response = (HttpWebResponse)request.GetResponse();
62+
string s = new StreamReader(response.GetResponseStream()).ReadToEnd();
63+
return s;
64+
}
65+
/// <summary>
66+
/// Read captcha image
67+
/// </summary>
68+
/// <param name="captcha_path"></param>
69+
/// <returns></returns>
70+
public static string read_captcha_image(string captcha_path)
71+
{
72+
Byte[] bytes = File.ReadAllBytes(captcha_path);
73+
string file_data = Convert.ToBase64String(bytes);
74+
return file_data;
75+
}
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{952613DE-192E-4DBF-988C-FD761B43E087}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>bestcaptchasolver</RootNamespace>
11+
<AssemblyName>BestCaptchaSolverAPI</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
34+
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net40\Newtonsoft.Json.dll</HintPath>
35+
</Reference>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="BestCaptchaSolverAPI.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
<Compile Include="Utils.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<None Include="packages.config" />
51+
</ItemGroup>
52+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
53+
</Project>

BestCaptchaSolverAPI/packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net40" />
4+
</packages>

bcs-automation.sln

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28010.2036
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bcs-automation", "bcs-automation\bcs-automation.csproj", "{C3DBDA00-7C3A-48EB-A67A-5E6A30809153}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BestCaptchaSolverAPI", "BestCaptchaSolverAPI\BestCaptchaSolverAPI.csproj", "{952613DE-192E-4DBF-988C-FD761B43E087}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{C3DBDA00-7C3A-48EB-A67A-5E6A30809153}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{C3DBDA00-7C3A-48EB-A67A-5E6A30809153}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{C3DBDA00-7C3A-48EB-A67A-5E6A30809153}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{C3DBDA00-7C3A-48EB-A67A-5E6A30809153}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{952613DE-192E-4DBF-988C-FD761B43E087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{952613DE-192E-4DBF-988C-FD761B43E087}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{952613DE-192E-4DBF-988C-FD761B43E087}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{952613DE-192E-4DBF-988C-FD761B43E087}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {E082989B-136C-421F-A7E0-C7A11136E968}
30+
EndGlobalSection
31+
EndGlobal

0 commit comments

Comments
 (0)