private void subimt(String URL, SubmitPrice points, CaptchaInput inputType) { logger.WarnFormat("BEGIN 验证码({0})", inputType); ScreenUtil.SetCursorPos(points.inputBox.x, points.inputBox.y); ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero); logger.Info("\tBEGIN make INPUTBOX blank"); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0x2, 0); logger.Info("\tEND make INPUTBOX blank"); byte[] content = new ScreenUtil().screenCaptureAsByte(points.captcha[0].x, points.captcha[0].y, 128, 28); byte[] binaryTips = new ScreenUtil().screenCaptureAsByte(points.captcha[1].x, points.captcha[1].y, 112, 16); Bitmap bitmap = new Bitmap(new MemoryStream(content)); this.pictureBox1.Image = bitmap; String strLoading = this.m_orcCaptchaLoading.IdentifyStringFromPic(bitmap); logger.InfoFormat("LOADING : {0}", strLoading); //if ("正在获取校验码".Equals(strLoading)) { // logger.InfoFormat("正在获取校验码,关闭&打开窗口重新获取"); // ScreenUtil.SetCursorPos(points.buttons[0].x + 188, points.buttons[0].y);//取消按钮 // ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero); // return; //} logger.Info("\tBEGIN identify Captcha"); String txtCaptcha = this.m_orcCaptcha.IdentifyStringFromPic(bitmap); logger.InfoFormat("\tEND identify Captcha : [{0}]", txtCaptcha); logger.Info("\tBEGIN input ACTIVE CAPTCHA"); String strActive = ""; if (CaptchaInput.LEFT == inputType) strActive = txtCaptcha.Substring(0, 4); else if (CaptchaInput.MIDDLE == inputType) strActive = txtCaptcha.Substring(1, 4); else if (CaptchaInput.RIGHT == inputType) strActive = txtCaptcha.Substring(2, 4); else if (CaptchaInput.AUTO == inputType) strActive = this.m_orcCaptchaTipsUtil.getActive(txtCaptcha, new Bitmap(new MemoryStream(binaryTips))); for (int i = 0; i < strActive.Length; i++) { ScreenUtil.keybd_event(ScreenUtil.keycode[strActive[i].ToString()], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode[strActive[i].ToString()], 0, 0x2, 0); System.Threading.Thread.Sleep(25); } logger.InfoFormat("\tEND input ACTIVE CAPTCHA [{0}]", strActive); { MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("确定要提交出价吗?", "提交出价", messButton, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); if (dr == DialogResult.OK) { logger.Info("用户选择确定出价"); ScreenUtil.SetCursorPos(points.buttons[0].x, points.buttons[0].y);//确定按钮 ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero); System.Threading.Thread.Sleep(1000); ScreenUtil.SetCursorPos(points.buttons[0].x + 188 / 2, points.buttons[0].y - 10);//确定按钮 //ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero); } else { logger.Warn("用户选择取消出价"); ScreenUtil.SetCursorPos(points.buttons[0].x + 188, points.buttons[0].y);//取消按钮 ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero); } } logger.Info("END 验证码"); }
/// <summary> /// 出校验码,【for CTRL+左、上、右】 /// </summary> /// <param name="URL"></param> /// <param name="bid"></param> /// <param name="input"></param> /// <returns></returns> private Boolean submit(String URL, tobid.rest.position.BidStep2 bid, CaptchaInput input) { logger.WarnFormat("BEGIN submitCAPTCHA({0})", input); logger.Info("\tBEGIN make INPUT blank"); logger.DebugFormat("\tINPUT BOX({0}, {1})", bid.submit.inputBox.x, bid.submit.inputBox.y); ScreenUtil.SetCursorPos(bid.submit.inputBox.x, bid.submit.inputBox.y); ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0x2, 0); //System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0x2, 0); //System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0x2, 0); System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0x2, 0); //System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0x2, 0); //System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0x2, 0); logger.Info("\tEND make INPUT blank"); logger.Info("\tBEGIN identify CAPTCHA..."); logger.DebugFormat("\tCAPTURE CAPTCHA({0}, {1})", bid.submit.captcha[0].x, bid.submit.captcha[0].y); byte[] binaryCaptcha = new ScreenUtil().screenCaptureAsByte(bid.submit.captcha[0].x, bid.submit.captcha[0].y, 128, 28); File.WriteAllBytes("CAPTCHA.BMP", binaryCaptcha); String txtCaptcha = this.m_orcCaptcha.IdentifyStringFromPic(new Bitmap(new MemoryStream(binaryCaptcha))); logger.DebugFormat("\tCAPTURE TIPS({0}, {1})", bid.submit.captcha[1].x, bid.submit.captcha[1].y); byte[] binaryTips = new ScreenUtil().screenCaptureAsByte(bid.submit.captcha[1].x, bid.submit.captcha[1].y, 112, 16); File.WriteAllBytes("TIPS.BMP", binaryTips); String txtActive = this.m_orcCaptchaTipsUtil.getActive(txtCaptcha, new Bitmap(new MemoryStream(binaryTips))); logger.InfoFormat("\tEND identify CAPTCHA = {0}, ACTIVE = {1}", txtCaptcha, txtActive); logger.Info("\tBEGIN input CAPTCHA"); { if (CaptchaInput.LEFT == input) { for (int i = 0; i <= 3; i++) { System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode[txtCaptcha[i].ToString()], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode[txtCaptcha[i].ToString()], 0, 0x2, 0); } } if (CaptchaInput.MIDDLE == input) { for (int i = 1; i <= 4; i++) { System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode[txtCaptcha[i].ToString()], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode[txtCaptcha[i].ToString()], 0, 0x2, 0); } } if (CaptchaInput.RIGHT == input) { for (int i = 2; i <= 5; i++) { System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode[txtCaptcha[i].ToString()], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode[txtCaptcha[i].ToString()], 0, 0x2, 0); } } if (CaptchaInput.AUTO == input) { for (int i = 0; i < txtActive.Length; i++) { System.Threading.Thread.Sleep(25); ScreenUtil.keybd_event(ScreenUtil.keycode[txtActive[i].ToString()], 0, 0, 0); ScreenUtil.keybd_event(ScreenUtil.keycode[txtActive[i].ToString()], 0, 0x2, 0); } } } logger.Info("\tEND input CAPTCHA"); MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("确定要提交出价吗?", "提交出价", messButton, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); if (dr == DialogResult.OK) { logger.InfoFormat("用户选择确定出价"); logger.DebugFormat("\tBUTTON[确定]({0}, {1})", bid.submit.buttons[0].x, bid.submit.buttons[0].y); ScreenUtil.SetCursorPos(bid.submit.buttons[0].x, bid.submit.buttons[0].y);//确定按钮 ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero); //System.Threading.Thread.Sleep(1000); //ScreenUtil.SetCursorPos(bid.submit.buttons[0].x + 188 / 2, bid.submit.buttons[0].y - 10);//确定按钮 //ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero); //ScreenUtil.SetCursorPos(bid.submit.buttons[0].x + 188 / 2, bid.submit.buttons[0].y - 10);//确定按钮 logger.Info("END submitCAPTCHA"); return true; } else { logger.InfoFormat("用户选择取消出价"); logger.DebugFormat("\tBUTTON[取消]({0}, {1})", bid.submit.buttons[0].x+188, bid.submit.buttons[0].y); ScreenUtil.SetCursorPos(bid.submit.buttons[0].x + 188, bid.submit.buttons[0].y);//取消按钮 ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero); logger.Info("END submitCAPTCHA"); return false; } //logger.Info("\tBEGIN click BUTTON[确定]"); //ScreenUtil.SetCursorPos(bid.submit.buttons[0].x, bid.submit.buttons[0].y); //ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero); //logger.Info("\tEND click BUTTON[确定]"); }