-
Notifications
You must be signed in to change notification settings - Fork 8
/
Captcha.cs
55 lines (53 loc) · 2.17 KB
/
Captcha.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Http;
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Reflection;
namespace Strawpoll_Bot
{
class Captcha
{
private static readonly HttpClient client = new HttpClient();
private static Random random = new Random();
private static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
public async Task<string> GetSolvedCaptcha(string captchakey, string id)
{
var newrequesturl = "http://2captcha.com/res.php?key=" + captchakey + "&action=get&id=" + id;
var newresponse = await client.GetAsync(newrequesturl);
string newresponseString = await newresponse.Content.ReadAsStringAsync();
//Console.WriteLine("Response String: " + newresponseString);
if (newresponseString == "CAPCHA_NOT_READY")
{
await Task.Delay(5000);
return await GetSolvedCaptcha(captchakey, id);
}
else
{
string responsestring = newresponseString.Split('|')[1];
return responsestring;
}
}
public async Task<string> SolveCaptcha(string captchakey, string sitekey, string currenturl)
{
var requesturl = "http://2captcha.com/in.php?key=" + captchakey + "&method=userrecaptcha&googlekey=" + sitekey + "&invisible=1&pageurl=" + currenturl;
var response = await client.GetAsync(requesturl);
string responseString = await response.Content.ReadAsStringAsync();
Thread.Sleep(15000);
string solvedcaptchaid = responseString.Split('|')[1];
string solvedresponse = await GetSolvedCaptcha(captchakey, solvedcaptchaid);
return solvedresponse;
}
}
}