Skip to content

Commit 011636b

Browse files
added geetest captcha
1 parent e7ac2cd commit 011636b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+282
-56
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*Debug*
2+
source/.vs
3+
source/packages

binary/imagetyperzapi.dll

3 KB
Binary file not shown.

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
14.03.2019
2+
----------
3+
- added geetest captcha

LICENSE.md renamed to license.md

File renamed without changes.

README.md renamed to readme.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ string balance = i.account_balance();
3636
Console.WriteLine(string.format("Balance: {0}", balance));
3737
```
3838

39-
**Submit image captcha**
39+
## Image captcha
40+
41+
### Submit image captcha
4042

4143
``` csharp
4244
string captcha_text = i.solve_captcha("captcha.jpg");
@@ -52,7 +54,9 @@ string captcha_text = i.solve_captcha("http://abc.com/captcha.jpg", false);
5254
For those that are still using username & password, retrieve your access_key from
5355
imagetyperz.com
5456

55-
**Submit recaptcha details**
57+
## reCAPTCHA
58+
59+
### Submit recaptcha details
5660

5761
For recaptcha submission there are two things that are required, and some optional parameters
5862
- page_url
@@ -77,7 +81,7 @@ string captcha_id = i.submit_recaptcha(d);
7781
This method returns a captchaID. This ID will be used next, to retrieve the g-response, once workers have
7882
completed the captcha. This takes somewhere between 10-80 seconds.
7983

80-
**Retrieve captcha response**
84+
### Retrieve captcha response
8185

8286
Once you have the captchaID, you check for it's progress, and later on retrieve the gresponse.
8387

@@ -93,6 +97,49 @@ while(i.in_progress(captcha_id))
9397
string recaptcha_response = i.retrieve_captcha(captcha_id);
9498
```
9599

100+
## GeeTest
101+
102+
GeeTest is a captcha that requires 3 parameters to be solved:
103+
- domain
104+
- challenge
105+
- gt
106+
107+
The response of this captcha after completion are 3 codes:
108+
- challenge
109+
- validate
110+
- seccode
111+
112+
### Submit GeeTest
113+
```csharp
114+
Dictionary<string, string> dg = new Dictionary<string, string>();
115+
dg.Add("domain", "geetest captcha domain");
116+
dg.Add("challenge", "geetest captcha challenge");
117+
dg.Add("gt", "geetest captcha gt");
118+
//d.Add("proxy", "126.45.34.53:123"); // or with auth 126.45.34.53:123:user:pass - optional
119+
//d.Add("user_agent", "Your user agent"); // optional
120+
```
121+
122+
Just like reCAPTCHA, you'll receive a captchaID.
123+
Using the ID, you'll be able to retrieve 3 codes after completion.
124+
125+
Optionally, you can send proxy and user_agent along.
126+
127+
### Retrieve GeeTest codes
128+
```csharp
129+
Console.WriteLine(string.Format("Geetest captcha id: {0}", geetest_id));
130+
Console.WriteLine("Waiting for geetest captcha to be solved ...");
131+
132+
// check for completion
133+
while (i.in_progress(geetest_id)) System.Threading.Thread.Sleep(10000); // sleep for 10 seconds and retry
134+
135+
// we got a response at this point
136+
Dictionary<string, string> geetest_response = i.retrieve_geetest(geetest_id); // get the response
137+
Console.WriteLine(string.Format("Geetest response: {0} - {1} - {2}", geetest_response["challenge"],
138+
geetest_response["validate"], geetest_response["seccode"]));
139+
```
140+
141+
Response will be a string dictionary, which looks like this: `{'challenge': '...', 'validate': '...', 'seccode': '...'}`
142+
96143
## Other methods/variables
97144

98145
**Affiliate id**

source/.vs/imagetyperzapi/v15/.suo

-71 KB
Binary file not shown.

source/.vs/imagetyperzapi/v15/Server/sqlite3/db.lock

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.

source/cli/bin/Debug/cli.exe

-8 KB
Binary file not shown.

source/cli/bin/Debug/cli.pdb

-17.5 KB
Binary file not shown.
-16.5 KB
Binary file not shown.
-41.5 KB
Binary file not shown.
Binary file not shown.

source/cli/obj/Debug/cli.csproj.CopyComplete

Whitespace-only changes.

source/cli/obj/Debug/cli.csproj.CoreCompileInputs.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

source/cli/obj/Debug/cli.csproj.FileListAbsolute.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.
Binary file not shown.

source/cli/obj/Debug/cli.exe

-8 KB
Binary file not shown.

source/cli/obj/Debug/cli.pdb

-17.5 KB
Binary file not shown.

source/example/Program.cs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ static void test_api()
1717
// -----------------------------------------
1818
string access_key = "access_token_here";
1919

20-
2120
// init imagetypersAPI obj with username and password
2221
ImageTypersAPI i = new ImageTypersAPI(access_key);
2322

2423
// old school / legacy way
25-
//i.set_user_and_password("your_username", "your_password");
24+
// i.set_user_and_password("your_username", "your_password");
2625

2726
// balance
2827
// ------------
@@ -31,9 +30,9 @@ static void test_api()
3130

3231
// captcha image
3332
// ==========================================================================================
34-
//Console.WriteLine("Solving image captcha ...");
35-
//string captcha_image_text = i.solve_captcha("captcha.jpg");
36-
//Console.WriteLine(string.Format("Captcha text: {0}", captcha_image_text));
33+
Console.WriteLine("Solving image captcha ...");
34+
string captcha_image_text = i.solve_captcha("captcha.jpg");
35+
Console.WriteLine(string.Format("Captcha text: {0}", captcha_image_text));
3736

3837
// ==========================================================================================
3938
// recaptcha
@@ -59,11 +58,32 @@ static void test_api()
5958
// retrieve
6059
// ---------
6160
while (i.in_progress(captcha_id)) System.Threading.Thread.Sleep(10000); // sleep for 10 seconds and retry
61+
string gresponse = i.retrieve_captcha(captcha_id);
62+
Console.WriteLine(string.Format("Recaptcha response: {0}", gresponse));
6263

63-
// we got a response at this point
64-
// ---------------------------------
65-
string recaptcha_response = i.retrieve_captcha(captcha_id); // get the response
66-
Console.WriteLine(string.Format("Recaptcha response: {0}", recaptcha_response));
64+
// Geetest
65+
// ----------
66+
// create params dict
67+
//Dictionary<string, string> dg = new Dictionary<string, string>();
68+
//dg.Add("domain", "geetest captcha domain");
69+
//dg.Add("challenge", "geetest captcha challenge");
70+
//dg.Add("gt", "geetest captcha gt");
71+
////d.Add("proxy", "126.45.34.53:123"); // or with auth 126.45.34.53:123:user:pass - optional
72+
////d.Add("user_agent", "Your user agent"); // optional
73+
74+
//string geetest_id = i.submit_geetest(dg);
75+
//Console.WriteLine(string.Format("Geetest captcha id: {0}", geetest_id));
76+
//Console.WriteLine("Waiting for geetest captcha to be solved ...");
77+
78+
//// retrieve
79+
//// ---------
80+
//while (i.in_progress(geetest_id)) System.Threading.Thread.Sleep(10000); // sleep for 10 seconds and retry
81+
82+
//// we got a response at this point
83+
//// ---------------------------------
84+
//Dictionary<string, string> geetest_response = i.retrieve_geetest(geetest_id); // get the response
85+
//Console.WriteLine(string.Format("Geetest response: {0} - {1} - {2}", geetest_response["challenge"],
86+
// geetest_response["validate"], geetest_response["seccode"]));
6787

6888
// Other examples
6989
// ----------------

source/example/bin/Debug/example.exe

-5.5 KB
Binary file not shown.

source/example/bin/Debug/example.pdb

-13.5 KB
Binary file not shown.
-16.5 KB
Binary file not shown.
-41.5 KB
Binary file not shown.
Binary file not shown.

source/example/obj/Debug/example.csproj.CopyComplete

Whitespace-only changes.

source/example/obj/Debug/example.csproj.CoreCompileInputs.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

source/example/obj/Debug/example.csproj.FileListAbsolute.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.
Binary file not shown.

source/example/obj/Debug/example.exe

-5.5 KB
Binary file not shown.

source/example/obj/Debug/example.pdb

-13.5 KB
Binary file not shown.

source/imagetyperzapi/Geetest.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace ImageTypers
7+
{
8+
class Geetest
9+
{
10+
private string _captcha_id = "";
11+
private string _response = "";
12+
13+
public Geetest(string captcha_id)
14+
{
15+
this._captcha_id = captcha_id;
16+
}
17+
/// <summary>
18+
/// Save captcha response to obj
19+
/// </summary>
20+
/// <param name="response"></param>
21+
public void set_response(string response)
22+
{
23+
this._response = response;
24+
}
25+
/// <summary>
26+
/// Getter for ID
27+
/// </summary>
28+
/// <returns></returns>
29+
public string captcha_id()
30+
{
31+
return this._captcha_id;
32+
}
33+
/// <summary>
34+
/// Getter for response
35+
/// </summary>
36+
/// <returns></returns>
37+
public Dictionary<string, string> response()
38+
{
39+
var s = this._response.Split(new string[] { ";;;" }, StringSplitOptions.None);
40+
if(s.Length == 3)
41+
{
42+
var d = new Dictionary<string, string>();
43+
d.Add("challenge", s[0]);
44+
d.Add("validate", s[1]);
45+
d.Add("seccode", s[2]);
46+
return d;
47+
}
48+
throw new Exception("invalid geetest response");
49+
}
50+
}
51+
}

source/imagetyperzapi/ImageTypersAPI.cs

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class ImageTypersAPI
1717
private static string BALANCE_ENDPOINT = "http://captchatypers.com/Forms/RequestBalance.ashx";
1818
private static string BAD_IMAGE_ENDPOINT = "http://captchatypers.com/Forms/SetBadImage.ashx";
1919
private static string PROXY_CHECK_ENDPOINT = "http://captchatypers.com/captchaAPI/GetReCaptchaTextJSON.ashx";
20+
private static string GEETEST_SUBMIT_ENDPOINT = "http://captchatypers.com/captchaapi/UploadGeeTest.ashx";
21+
private static string GEETEST_RETRIEVE_ENDPOINT = "http://captchatypers.com/captchaapi/getrecaptchatext.ashx";
2022

2123
private static string CAPTCHA_ENDPOINT_CONTENT_TOKEN = "http://captchatypers.com/Forms/UploadFileAndGetTextNEWToken.ashx";
2224
private static string CAPTCHA_ENDPOINT_URL_TOKEN = "http://captchatypers.com/Forms/FileUploadAndGetTextCaptchaURLToken.ashx";
@@ -25,6 +27,7 @@ public class ImageTypersAPI
2527
private static string BALANCE_ENDPOINT_TOKEN = "http://captchatypers.com/Forms/RequestBalanceToken.ashx";
2628
private static string BAD_IMAGE_ENDPOINT_TOKEN = "http://captchatypers.com/Forms/SetBadImageToken.ashx";
2729
private static string PROXY_CHECK_ENDPOINT_TOKEN = "http://captchatypers.com/captchaAPI/GetReCaptchaTextTokenJSON.ashx";
30+
private static string GEETEST_SUBMIT_ENDPOINT_TOKEN = "http://captchatypers.com/captchaapi/UploadGeeTestToken.ashx";
2831

2932
private static string USER_AGENT = "csharpAPI1.0"; // user agent used in requests
3033

@@ -36,6 +39,7 @@ public class ImageTypersAPI
3639

3740
private Captcha _captcha;
3841
private Recaptcha _recaptcha = null;
42+
private Geetest _geetest = null;
3943

4044
private string _error = "";
4145

@@ -52,8 +56,8 @@ public ImageTypersAPI(string access_token, string affiliate_id = "0", int timeou
5256
this._timeout = timeout * 1000;
5357
}
5458

55-
#region captcha & recaptcha
56-
/// <summary>
59+
#region captcha / recaptcha / geetest
60+
/// <summary>
5761
/// Solve normal captcha
5862
/// </summary>
5963
/// <param name="captcha">captcha image file (local) or remote file (URL) [remote works only if tokens are used]</param>
@@ -273,7 +277,8 @@ public bool in_progress(string captcha_id)
273277
{
274278
try
275279
{
276-
this.retrieve_captcha(captcha_id); // try to retrieve captcha
280+
if (this._geetest != null) this.retrieve_geetest(captcha_id);
281+
else this.retrieve_captcha(captcha_id); // try to retrieve captcha
277282
return false; // no error, we're good
278283
}
279284
catch (Exception ex)
@@ -288,6 +293,103 @@ public bool in_progress(string captcha_id)
288293
}
289294
}
290295
#endregion
296+
297+
#region geetest
298+
/// <summary>
299+
/// Submit geetest captcha
300+
/// </summary>
301+
/// <param name="d"></param>
302+
/// <returns></returns>
303+
public string submit_geetest(Dictionary<string, string> d)
304+
{
305+
string url = "";
306+
307+
if(!d.ContainsKey("domain")) throw new Exception("domain is missing");
308+
if (!d.ContainsKey("challenge")) throw new Exception("challenge is missing");
309+
if (!d.ContainsKey("gt")) throw new Exception("gt is missing");
310+
311+
d.Add("action", "UPLOADCAPTCHA");
312+
// create URL
313+
if (!string.IsNullOrWhiteSpace(this._username))
314+
{
315+
d.Add("username", this._username);
316+
d.Add("password", this._password);
317+
url = GEETEST_SUBMIT_ENDPOINT;
318+
}
319+
else
320+
{
321+
d.Add("token", this._access_token);
322+
url = GEETEST_SUBMIT_ENDPOINT_TOKEN;
323+
}
324+
325+
// affiliate id
326+
if (!string.IsNullOrWhiteSpace(this._affiliateid) && this._affiliateid.ToString() != "0")
327+
{
328+
d.Add("affiliateid", this._affiliateid);
329+
}
330+
331+
var post_data = Utils.list_to_params(d); // transform dict to params
332+
var full_url = string.Format("{0}?{1}", url, post_data);
333+
string response = Utils.GET(full_url, USER_AGENT, this._timeout); // make request
334+
if (response.Contains("ERROR:"))
335+
{
336+
var response_err = response.Split(new string[] { "ERROR:" }, StringSplitOptions.None)[1].Trim();
337+
this._error = response_err;
338+
throw new Exception(response_err);
339+
}
340+
341+
// set as recaptcha [id] response and return
342+
var r = new Geetest(response);
343+
this._geetest = r;
344+
return this._geetest.captcha_id(); // return captcha id
345+
}
346+
347+
/// <summary>
348+
/// Get geetest response
349+
/// </summary>
350+
/// <param name="captcha_id"></param>
351+
/// <returns></returns>
352+
public Dictionary<string, string> retrieve_geetest(string captcha_id)
353+
{
354+
// check if ID is OK
355+
if (string.IsNullOrWhiteSpace(captcha_id))
356+
{
357+
throw new Exception("captcha ID is null or empty");
358+
}
359+
360+
string url = "";
361+
// init params object
362+
Dictionary<string, string> d = new Dictionary<string, string>();
363+
d.Add("action", "GETTEXT");
364+
d.Add("captchaid", captcha_id);
365+
366+
if (!string.IsNullOrWhiteSpace(this._username))
367+
{
368+
d.Add("username", this._username);
369+
d.Add("password", this._password);
370+
url = GEETEST_RETRIEVE_ENDPOINT;
371+
}
372+
else
373+
{
374+
d.Add("token", this._access_token);
375+
url = GEETEST_RETRIEVE_ENDPOINT;
376+
}
377+
378+
var post_data = Utils.list_to_params(d); // transform dict to params
379+
var full_url = string.Format("{0}?{1}", url, post_data);
380+
string response = Utils.GET(full_url, USER_AGENT, this._timeout); // make request
381+
if (response.Contains("ERROR:"))
382+
{
383+
var response_err = response.Split(new string[] { "ERROR:" }, StringSplitOptions.None)[1].Trim();
384+
this._error = response_err;
385+
throw new Exception(response_err);
386+
}
387+
388+
// set as recaptcha [id] response and return
389+
this._geetest.set_response(response);
390+
return this._geetest.response(); // return captcha id
391+
}
392+
#endregion
291393
#endregion
292394

293395
#region others

0 commit comments

Comments
 (0)