Type type_rucaptcha = AppDomain.CurrentDomain.GetAssemblies().First(x => x.FullName.IndexOf("Rucaptcha", StringComparison.OrdinalIgnoreCase) != -1).GetType("ZennoLab.RuCaptcha.RuCaptchaConfigurator");
string rucaptcha_key = type_rucaptcha.GetMethod("get_SecretKey").Invoke(Activator.CreateInstance(type_rucaptcha), null).ToString();
string site_key = Regex.Match(instance.ActiveTab.DomText, @"(?<=api2/anchor\?k=).*?(?=&)").Value;
if (site_key == string.Empty)
throw new Exception("google key не найден, задайте его вручную");
string domen = new Uri(instance.ActiveTab.URL).GetLeftPart(UriPartial.Authority);
System.Net.HttpWebRequest post_rucaptcha = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://rucaptcha.com/in.php?key=" + rucaptcha_key + @"&method=userrecaptcha&googlekey=" + site_key + @"&pageurl=" + domen);
post_rucaptcha.Proxy = null;
post_rucaptcha.AllowAutoRedirect = false;
post_rucaptcha.Method = "GET";
post_rucaptcha.ServicePoint.Expect100Continue = false;
post_rucaptcha.Timeout = 30000;
string url_get;
using (System.Net.WebResponse resp = post_rucaptcha.GetResponse())
using (Stream respStream = resp.GetResponseStream())
using (StreamReader sr = new StreamReader(respStream))
{
string resp_answer = sr.ReadToEnd();
if (!resp_answer.Contains("OK|"))
throw new Exception(resp_answer);
url_get = "http://rucaptcha.com/res.php?key=" + rucaptcha_key + @"&action=get&id=" + resp_answer.Split('|')[1];
}
Thread.Sleep(10000);
for (int z = 0; ;z++)
{
System.Net.HttpWebRequest get_rucaptcha_2 = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url_get);
get_rucaptcha_2.Method = "GET";
get_rucaptcha_2.Timeout = 30000;
get_rucaptcha_2.Proxy = null;
get_rucaptcha_2.AllowAutoRedirect = false;
post_rucaptcha.ServicePoint.Expect100Continue = false;
string response;
using (System.Net.WebResponse resp = get_rucaptcha_2.GetResponse())
using (Stream respStream = resp.GetResponseStream())
using (StreamReader sr = new StreamReader(respStream))
response = sr.ReadToEnd();
if (response.Contains("OK|"))
{
instance.ActiveTab.FindElementById("g-recaptcha-response").SetValue(response.Split('|')[1], "None", false);
break;
}
else if ((response != "CAPCHA_NOT_READY" && response != string.Empty) || z > 20)
throw new Exception("не удалось решить рекапчу, ответ от сервиса: " + response);
else
Thread.Sleep(10000);
}