private void button1_Click(object sender, EventArgs e) { new Thread(delegate(object o) { Thread.Sleep(1000); IntPtr intPtr = this.webBrowser1.Handle; StringBuilder stringBuilder = new StringBuilder(100); while (stringBuilder.ToString() != "Internet Explorer_Server") { intPtr = J_AliLoginForm.GetWindow(intPtr, 5); J_AliLoginForm.GetClassName(intPtr, stringBuilder, stringBuilder.Capacity); } J_AliLoginForm.SendMessage(intPtr, 513, 1, this.MakeLParam(65, 135)); J_AliLoginForm.SendMessage(intPtr, 512, 1, this.MakeLParam(65, 135)); Thread.Sleep(10); J_AliLoginForm.SendMessage(intPtr, 512, 1, this.MakeLParam(285, 135)); J_AliLoginForm.SendMessage(intPtr, 514, 1, this.MakeLParam(275, 135)); }) { IsBackground = true }.Start(); }
/// <summary> /// 定时期执行逻辑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick(object sender, EventArgs e) { if (DateTime.Now.AddSeconds(-120.0) >= this.starttime) { this.timer1.Stop(); //MainForm.AliIsLogin = false; base.Close(); } else if (!this.webBrowser1.IsBusy) //浏览器是否加载新文档 { if (!(this.webBrowser1.Document == null)) // 获取一个 HtmlDocument,它表示当前显示在 WebBrowser 控件中的网页 { if (this.webBrowser1.Url != null && this.webBrowser1.Url.ToString().Contains("www.alimama.com/index.htm")) { this.timer1.Stop(); XJHTTP xJHTTP = new XJHTTP(); DT.Cookie = xJHTTP.GetCookieByWininet("http://pub.alimama.com/myunion.htm"); bool flag = DT.Cookie != null && GetToken(DT.Cookie).Count > 0; if (flag) { DT.Token = this.GetToken(DT.Cookie)[0]; string accountInfo = this.test_mm(); //登路成功后,解析账号信息 parseAccountInfo(accountInfo); base.Close(); } } else if (this.webBrowser1.Document.GetElementById("ra-0") != null && this.webBrowser1.Document.GetElementById("ra-0").GetAttribute("value") != null && this.webBrowser1.Document.GetElementById("ra-0").GetAttribute("value").StartsWith("cntaobao") && DT.AliLoginType == "快捷")//&& MainForm.AliLoginType == 1 { if (this.webBrowser1.Document.GetElementById("J_SubmitQuick") != null) { try { this.webBrowser1.Document.GetElementById("J_SubmitQuick").Focus(); } catch { } HtmlElement elementById = this.webBrowser1.Document.GetElementById("J_SubmitQuick"); System.Drawing.Point offset = this.GetOffset(elementById); if (offset.X > 0 && offset.Y > 0) { IntPtr intPtr = this.webBrowser1.Handle; StringBuilder stringBuilder = new StringBuilder(100); while (stringBuilder.ToString() != "Internet Explorer_Server") { intPtr = J_AliLoginForm.GetWindow(intPtr, 5); J_AliLoginForm.GetClassName(intPtr, stringBuilder, stringBuilder.Capacity); } int loWord = offset.X + new Random().Next(20, 100); int hiWord = offset.Y + new Random().Next(10, 30); J_AliLoginForm.SendMessage(intPtr, 513, 1, this.MakeLParam(loWord, hiWord)); J_AliLoginForm.SendMessage(intPtr, 514, 1, this.MakeLParam(loWord, hiWord)); // ShowLog.Show("检测到已登录千牛[" + this.webBrowser1.Document.GetElementById("ra-0").GetAttribute("value").Replace("cntaobao", string.Empty) + "]优先选择该帐号登录!", System.Drawing.Color.Green, string.Empty, string.Empty); } } } else { if (this.webBrowser1.Document.GetElementById("J_LoginBox") != null && this.webBrowser1.Document.GetElementById("J_LoginBox").GetAttribute("classname") != null && this.webBrowser1.Document.GetElementById("J_LoginBox").GetAttribute("classname").ToString().Contains("module-quick")) { if (this.webBrowser1.Document.GetElementById("J_Quick2Static") != null) { this.webBrowser1.Document.GetElementById("J_Quick2Static").InvokeMember("click"); //ShowLog.Show("切换到帐号输入状态...", System.Drawing.Color.Green, string.Empty, string.Empty); return; } } if ((this.webBrowser1.Document.GetElementById("nc_1_clickCaptcha") != null && this.webBrowser1.Document.GetElementById("nc_1_clickCaptcha").Style != null && !this.webBrowser1.Document.GetElementById("nc_1_clickCaptcha").Style.Contains("-")) || (this.webBrowser1.Document.GetElementById("nc_1_imgCaptcha") != null && this.webBrowser1.Document.GetElementById("nc_1_imgCaptcha").Style != null && !this.webBrowser1.Document.GetElementById("nc_1_imgCaptcha").Style.Contains("-")) || (this.webBrowser1.Document.GetElementById("nc_1__voicebtn") != null && this.webBrowser1.Document.GetElementById("nc_1__voicebtn").Style != null && !this.webBrowser1.Document.GetElementById("nc_1__voicebtn").Style.ToLower().Contains("display: none"))) { string style = this.webBrowser1.Document.GetElementById("nc_1_clickCaptcha").Style; string style2 = this.webBrowser1.Document.GetElementById("nc_1_imgCaptcha").Style; string style3 = this.webBrowser1.Document.GetElementById("nc_1__voicebtn").Style; this.Text = "请手动验证并点击登录!"; } else { if (this.webBrowser1.Document.GetElementById("nocaptcha") != null && this.webBrowser1.Document.GetElementById("nocaptcha").Style != null) { if (!(this.webBrowser1.Document.GetElementById("nc_1_n1z") != null) || !(this.webBrowser1.Document.GetElementById("nc_1_n1z").GetAttribute("classname") == "nc_iconfont btn_ok")) { if (this.webBrowser1.Document.GetElementById("nc_1__scale_text") != null && this.webBrowser1.Document.GetElementById("nc_1__scale_text").OuterText == "请按住滑块,拖动到最右边") { HtmlElement elementById = this.webBrowser1.Document.GetElementById("nocaptcha"); System.Drawing.Point offset = this.GetOffset(elementById); IntPtr intPtr = this.webBrowser1.Handle; StringBuilder stringBuilder = new StringBuilder(100); while (stringBuilder.ToString() != "Internet Explorer_Server") { intPtr = J_AliLoginForm.GetWindow(intPtr, 5); J_AliLoginForm.GetClassName(intPtr, stringBuilder, stringBuilder.Capacity); } int num = 65; int num2 = 285; int num3 = 20; J_AliLoginForm.SendMessage(intPtr, 513, 1, this.MakeLParam(num, offset.Y + 20)); int num4 = num + (num2 - num) / num3; for (int i = 0; i < num3; i++) { J_AliLoginForm.SendMessage(intPtr, 512, 1, this.MakeLParam(num + i * ((num2 - num) / num3), offset.Y + 20)); Thread.Sleep(20); } J_AliLoginForm.SendMessage(intPtr, 514, 1, this.MakeLParam(275, offset.Y + 20)); } return; } } if (this.webBrowser1.Document.GetElementById("TPL_username_1") != null) { // this.webBrowser1.Document.GetElementById("TPL_username_1").SetAttribute("value", DT.TBName); } if (this.webBrowser1.Document.GetElementById("TPL_password_1") != null) { // this.webBrowser1.Document.GetElementById("TPL_password_1").SetAttribute("value", DT.TBPsw); } if (this.webBrowser1.Document.GetElementById("J_SubmitStatic") != null) { try { this.webBrowser1.Document.GetElementById("J_SubmitStatic").Focus(); } catch { } HtmlElement elementById = this.webBrowser1.Document.GetElementById("J_SubmitStatic"); System.Drawing.Point offset = this.GetOffset(elementById); if (offset.X > 0 && offset.Y > 0) { IntPtr intPtr = this.webBrowser1.Handle; StringBuilder stringBuilder = new StringBuilder(100); while (stringBuilder.ToString() != "Internet Explorer_Server") { intPtr = J_AliLoginForm.GetWindow(intPtr, 5); J_AliLoginForm.GetClassName(intPtr, stringBuilder, stringBuilder.Capacity); } int loWord = offset.X + new Random().Next(20, 100); int hiWord = offset.Y + new Random().Next(10, 30); J_AliLoginForm.SendMessage(intPtr, 513, 1, this.MakeLParam(loWord, hiWord)); J_AliLoginForm.SendMessage(intPtr, 514, 1, this.MakeLParam(loWord, hiWord)); } } } } } } }