Ich nutze den Service von
[Only registered and activated users can see links. Click Here To Register...]
Mir geht es vorallem um die Google Captchas, da kosten hier keine Rolle spielen nutze ich den obigen Service.
Hab dir mal meinen Code unten angefügt. Eventuell hilft dir der weiter.
Winform Aufbau:
[Only registered and activated users can see links. Click Here To Register...]
Winform Code:
Code:
public partial class CaptchaWindow : Form
{
string _captchaText;
Bitmap _captchaImage;
string _captchaPath;
public string CaptchaText
{
get { return _captchaText; }
private set { _captchaText = value; }
}
public CaptchaWindow(Bitmap captchaimage)
{
InitializeComponent();
_captchaImage = captchaimage;
this.pb_captcha.Image = _captchaImage;
timer_autoClose.Enabled = true; //Close Timer starten
//Image speichern
try
{
_captchaPath = System.IO.Path.GetTempPath() + Guid.NewGuid() + ".bmp"; //Captcha Pfad speichern
_captchaImage.Save(_captchaPath); //Captcha im temporären Ordner speichern
thread_captchaservice.RunWorkerAsync(); //Captcha Service starten
}
catch (Exception)
{
}
//Guthaben abfragen
try
{
lbl_credits.Text = "CS:" + _9kw.getCredits();
}
catch (Exception) { }
}
private void btn_send_Click(object sender, EventArgs e)
{
if (thread_captchaservice.IsBusy && !thread_captchaservice.CancellationPending)
{
thread_captchaservice.CancelAsync();
}
CaptchaText = tb_inputcaptcha.Text.Trim();
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
private void btn_cancel_Click(object sender, EventArgs e)
{
if (thread_captchaservice.IsBusy && !thread_captchaservice.CancellationPending)
{
thread_captchaservice.CancelAsync();
}
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
private void tb_inputcaptcha_KeyDown(object sender, KeyEventArgs e)
{
if (thread_captchaservice.IsBusy && !thread_captchaservice.CancellationPending)
{
thread_captchaservice.CancelAsync();
}
if (e.KeyCode == Keys.Enter)
{
btn_send.PerformClick();
}
}
private void timer_autoClose_Tick(object sender, EventArgs e)
{
btn_send.PerformClick();
}
private void thread_captchaservice_DoWork(object sender, DoWorkEventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
for (int i = 30; i >= 0; i--)
{
if (thread_captchaservice.CancellationPending)
{
e.Cancel = true;
return;
}
lbl_message.Text = "Auto Solver in " + i + "s";
Thread.Sleep(1000);
}
lbl_message.Text = "Auto Solver AKTIV";
string code = _9kw.getCaptchaCode(_captchaPath);
e.Result = code;
}
private void thread_captchaservice_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
try
{
File.Delete(_captchaPath); //Captcha Bild löschen
}
catch (Exception) { }
if (!e.Cancelled)
{
if (e.Result != null)
{
tb_inputcaptcha.Text = (string)e.Result; //Code in Textbox eintragen
btn_send.PerformClick(); //Captcha absenden
}
}
}
private void CaptchaWindow_FormClosed(object sender, FormClosedEventArgs e)
{
if (thread_captchaservice.IsBusy && !thread_captchaservice.CancellationPending)
{
thread_captchaservice.CancelAsync();
}
}
9kw Klasse:
Code:
class _9kw
{
private const string Globalname = "";
public static string APIKey;
public static int Debug;
public static string CaptchaID;
static _9kw()
{
APIKey = "";
Debug = 0;
}
public static void successCaptchaResponsoe(bool success)
{
if (CaptchaID != null)
{
if (success)
{
// Captcha richtig
get_9kw_api("usercaptchacorrectback&id=" + CaptchaID + "&correct=1");
}
else
{
// Captcha falsch
get_9kw_api("usercaptchacorrectback&id=" + CaptchaID + "&correct=2");
}
CaptchaID = null;
}
}
public static string getCaptchaCode(string image)
{
//Captcha einreichen
CaptchaID = get_9kw_api_upload(image);
Regex myRegexDigit = new Regex("^[0-9]+$", RegexOptions.IgnoreCase);
if ((myRegexDigit.IsMatch(CaptchaID)))
{
int wait = 5;
System.Threading.Thread.Sleep(new TimeSpan(0, 0, wait));
for (int i = 1; i < 100; i++)
{
string checkdata = get_9kw_api("usercaptchacorrectdata&id=" + CaptchaID);
if (checkdata.Length != 0)
{
return checkdata;
}
System.Threading.Thread.Sleep(new TimeSpan(0, 0, 1));
System.Threading.Thread.Sleep(new TimeSpan(0, 0, 1));
System.Threading.Thread.Sleep(new TimeSpan(0, 0, 1));
}
}
return "";
}
public static string getCredits()
{
string guthaben = get_9kw_api("usercaptchaguthaben");
return guthaben;
}
private static string get_9kw_api(string data)
{
return get_9kw_http("http://www.9kw.eu/index.cgi?source=csapi&debug=" + Debug + "&apikey=" + APIKey + "&action=" + data);
}
private static string get_9kw_api_upload(string data)
{
HttpClient client = new HttpClient();
HttpPost postMethod = new HttpPost(new Uri("http://www.9kw.eu/index.cgi"));
MultipartEntity multipartEntity = new MultipartEntity();
postMethod.Entity = multipartEntity;
StringBody stringBody = new StringBody(Encoding.UTF8, "apikey", APIKey);
multipartEntity.AddBody(stringBody);
StringBody stringBody3 = new StringBody(Encoding.UTF8, "source", "csapi");
multipartEntity.AddBody(stringBody3);
StringBody stringBody2 = new StringBody(Encoding.UTF8, "action", "usercaptchaupload");
multipartEntity.AddBody(stringBody2);
StringBody stringBody4 = new StringBody(Encoding.UTF8, "captchaperhour", "9999");
multipartEntity.AddBody(stringBody4);
FileInfo fileInfo = new FileInfo(@data);
FileBody fileBody = new FileBody("file-upload-01", data, fileInfo);
multipartEntity.AddBody(fileBody);
HttpResponse response = client.Execute(postMethod);
return EntityUtils.ToString(response.Entity);
}
private static string get_9kw_http(string url)
{
HttpClient httpClient = new HttpClient();
HttpGet httpGet = new HttpGet(new Uri(url));
HttpResponse httpResponse = httpClient.Execute(httpGet);//httpResponse.ResponseCode
return EntityUtils.ToString(httpResponse.Entity);
}