/// <summary> /// PIN码登陆 /// </summary> private void Submit() { try { /* * 1.获取到验证码图片。 * 2.破解 * 3.赋值 * 4.提价 * 5.重试 */ #region 解析验证码并填入 MoveLeftTopSide(); string imgCode = ""; Bitmap bitmap = GetImage(); int tryCount = 0; while (!"1".Equals(Config.UnNeedQrCode) && tryCount < 2 && imgCode.Length < 4) { try { tryCount++; if (tryCount > 1) { WindowFormAPI.SendMessage(this.changeImgCodeBtnHandler, WindowFormAPI.BM_CLICK, IntPtr.Zero, null); Thread.Sleep(1000); bitmap = GetImage(); } if (bitmap == null) { break; } BreakCodeServer unCheckobj = new BreakCodeServer(bitmap); Thread.Sleep(1000); imgCode = unCheckobj.getPicnum(); } catch (Exception ex) { SetText(string.Format("解析验证码异常:{0}", "未成功解析验证码")); } } if ((!string.IsNullOrEmpty(imgCode) && imgCode.Length == 4)) { WindowFormAPI.SendMessage(this.imgCodeTextHandler, WindowFormAPI.WM_SETTEXT, IntPtr.Zero, imgCode); } #endregion #region 点击登录 Thread.Sleep(2000); WindowFormAPI.SendMessage(this.SubmitBtnHandler, WindowFormAPI.BM_CLICK, IntPtr.Zero, null); #endregion } catch (Exception ex) { SetText(String.Format("Submit提交异常:{0}", ex.Message)); } }
/// <summary> /// 获取页面验证码图片转换为字符串 /// </summary> /// <param name="webbrowser"></param> /// <returns></returns> public string ConImageCodeToString(System.Windows.Forms.WebBrowser webbrowser, out HtmlElement imagecodeelement) { string imagecode = default(string); try { #region 解析验证码 HtmlElementCollection imageresult = webbrowser.Document.Images; imagecodeelement = null; foreach (var item in imageresult) { HtmlElement curimg = item as HtmlElement; if (curimg.OuterHtml.Contains("rand_code.csp")) { /*获取页面图片*/ imagecodeelement = curimg; HTMLDocument hdoc = (HTMLDocument)webbrowser.Document.DomDocument; HTMLBody hbody = (HTMLBody)hdoc.body; IHTMLControlRange hcr = (IHTMLControlRange)hbody.createControlRange(); IHTMLControlElement hImg = (IHTMLControlElement)curimg.DomElement; hcr.add(hImg); hcr.execCommand("Copy", false, null); Image CodeImage = Clipboard.GetImage(); Bitmap bitmap = new Bitmap(CodeImage); /*******解析验证码********/ BreakCodeServer unCheckobj = new BreakCodeServer(bitmap); Thread.Sleep(2000); imagecode = unCheckobj.getPicnum(); break; } } #endregion } catch (Exception ex) { SetText(System.DateTime.Now.ToString() + "\r\n解析验证码失败\r\n"); imagecodeelement = null; imagecode = ""; } return(imagecode); }