Esempio n. 1
0
        public static Resource getInstance(String endPoint)
        {
            Resource rtn = new Resource();
            String hostName = System.Net.Dns.GetHostName();
            String epKeepAlive = endPoint + "/command/global.do";
            RestClient restGlobalConfig = new RestClient(endpoint: epKeepAlive, method: HttpVerb.GET);

            GlobalConfig global = null;
            Stream stream = null;
            String urlResource = null;
            try
            {
                logger.DebugFormat("获取全局配置...【{0}】", String.Format("{0}?ip={1}", epKeepAlive, hostName));
                String jsonResponse = restGlobalConfig.MakeRequest(String.Format("?ip={0}", hostName));
                global = Newtonsoft.Json.JsonConvert.DeserializeObject<GlobalConfig>(jsonResponse);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("获取全局配置异常:{0}", ex);
            }

            try
            {
                urlResource = endPoint + global.repository;
                logger.DebugFormat("获取全局配置资源...【{0}】", urlResource);
                stream = new HttpUtil().getAsBinary(urlResource);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("获取全局配置资源异常:{0}", ex);
            }

            IDictionary<Bitmap, String> dictPrice = new Dictionary<Bitmap, String>();
            IDictionary<Bitmap, String> dictLoading = new Dictionary<Bitmap, String>();
            IDictionary<Bitmap, String> dictTips = new Dictionary<Bitmap, String>();
            IDictionary<Bitmap, String> dictTipsNo = new Dictionary<Bitmap, String>();

            ZipInputStream zip = new ZipInputStream(stream);
            ZipEntry entry = null;
            logger.Debug("解析资源...");
            while ((entry = zip.GetNextEntry()) != null)
            {
                if (entry.IsFile)
                {
                    logger.Debug(entry.Name);
                    MemoryStream binaryStream = new MemoryStream();
                    int size = 2048;
                    byte[] data = new byte[2048];
                    while (true)
                    {
                        size = zip.Read(data, 0, data.Length);
                        if (size > 0)
                            binaryStream.Write(data, 0, size);
                        else
                            break;
                    }

                    String[] array = entry.Name.Split(new char[] { '.', '/' });
                    Bitmap bitmap = new Bitmap(binaryStream);
                    if (entry.Name.ToLower().StartsWith("price"))
                        dictPrice.Add(bitmap, array[array.Length - 2]);
                    else if (entry.Name.ToLower().StartsWith("loading"))
                        dictLoading.Add(bitmap, array[array.Length - 2]);
                    else if (entry.Name.ToLower().StartsWith("captcha.tip"))
                    {
                        if (entry.Name.ToLower().StartsWith("captcha.tip/no"))
                            dictTipsNo.Add(bitmap, array[array.Length - 2]);
                        else
                            dictTips.Add(bitmap, array[array.Length - 2]);
                    }
                }
            }

            rtn.m_tag = global.tag;
            rtn.m_price = OrcUtil.getInstance(global.price, dictPrice);
            rtn.m_tips = new OrcUtil[]{
                OrcUtil.getInstance(global.tips0, dictTips),
                OrcUtil.getInstance(global.tips1, dictTips)
            };
            rtn.m_tipsNo = OrcUtil.getInstance(global.tipsNo, dictTipsNo);
            rtn.m_loading = OrcUtil.getInstance(global.loading, dictLoading);
            return rtn;
        }
Esempio n. 2
0
        private void subimt(String URL, SubmitPrice points, int type)
        {
            logger.Info("BEGIN 验证码");
            ScreenUtil.SetCursorPos(points.inputBox.x, points.inputBox.y);
            ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero);
            //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(50); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0);

            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0);
            logger.Info("\tEND   make INPUTBOX blank");

            byte[] content = new ScreenUtil().screenCaptureAsByte(points.captcha[0].x, points.captcha[0].y, 128, 28);
            this.pictureBox1.Image = Bitmap.FromStream(new System.IO.MemoryStream(content));
            String strLoading = this.m_orcCaptchaLoading.getCharFromPic(new Bitmap(new MemoryStream(content)));
            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;
            }

            //byte[] content = null;
            //Boolean isLoading = true;
            //int retry = 0;
            //while (isLoading)
            //{
            //    content = new ScreenUtil().screenCaptureAsByte(points.captcha[0].x, points.captcha[0].y, 128, 28);
            //    String strLoading = this.m_orcCaptchaLoading.getCharFromPic(new Bitmap(new MemoryStream(content)));
            //    logger.InfoFormat("\t try to LOADING = {0}", strLoading);
            //    if ("正在获取校验码".Equals(strLoading))
            //    {
            //        if (retry > 3)//4次都在获取
            //            return;//放弃本次出价
            //        logger.InfoFormat("\t re-try {0}", ++retry);
            //        System.Threading.Thread.Sleep(250);
            //    }
            //    else
            //        isLoading = false;
            //}

            logger.Info("\tBEGIN postCaptcha");
            String txtCaptcha = new HttpUtil().postByteAsFile(URL + "/receive/dynamic/captcha.do", content);
            logger.Info("\tEND   postCaptcha");

            logger.Info("\tBEGIN input ACTIVE CAPTCHA [" + type + "]");
            if (type == 0)
            {
                for (int i = 0; i < 4; i++)
                {
                    ScreenUtil.keybd_event(ScreenUtil.keycode[txtCaptcha[i].ToString()], 0, 0, 0);
                    System.Threading.Thread.Sleep(50);
                }
            }
            else if (type == 1)
            {
                for (int i = 1; i < 5; i++)
                {
                    ScreenUtil.keybd_event(ScreenUtil.keycode[txtCaptcha[i].ToString()], 0, 0, 0);
                    System.Threading.Thread.Sleep(50);
                }
            }
            else if (type == 2)
            {
                for (int i = 2; i < 6; i++)
                {
                    ScreenUtil.keybd_event(ScreenUtil.keycode[txtCaptcha[i].ToString()], 0, 0, 0);
                    System.Threading.Thread.Sleep(50);
                }
            }
            logger.Info("\tEND   input ACTIVE CAPTCHA");

            {
                System.Threading.Thread.Sleep(50);
                MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
                DialogResult dr = MessageBox.Show("确定要提交出价吗?", "提交出价", messButton, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                if (dr == DialogResult.OK)
                {
                    logger.InfoFormat("用户选择确定出价");
                    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.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);
                }

                //if (points.Length > 3)
                //{
                //    System.Threading.Thread.Sleep(50);
                //    ScreenUtil.SetCursorPos(points[3].X, points[3].Y);
                    //ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero);
                //}
            }
            logger.Info("END   验证码");
        }
Esempio n. 3
0
        private Boolean submit(String URL, SubmitPrice submitPoints)
        {
            logger.Info("BEGIN giveCAPTCHA");
            logger.Info("\tBEGIN make INPUT blank");
            ScreenUtil.SetCursorPos(submitPoints.inputBox.x, submitPoints.inputBox.y);
            ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero);

            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["BACKSPACE"], 0, 0, 0);

            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0);
            System.Threading.Thread.Sleep(50); ScreenUtil.keybd_event(ScreenUtil.keycode["DELETE"], 0, 0, 0);
            logger.Info("\tEND   make INPUT blank");

            logger.Info("\tBEGIN identify CAPTCHA...");
            byte[] binaryCaptcha = null;
            Boolean isLoading = true;
            int retry = 0;
            while (isLoading)
            {
                logger.InfoFormat("\t try LOADING = {0}", retry++);
                binaryCaptcha = new ScreenUtil().screenCaptureAsByte(submitPoints.captcha[0].x, submitPoints.captcha[0].y, 128, 28);
                String strLoading = this.m_orcLoading.getCharFromPic(new Bitmap(new MemoryStream(binaryCaptcha)));
                logger.InfoFormat("\t LOADING = {0}", strLoading);
                if ("正在获取校验码".Equals(strLoading))
                {
                    if (retry > 2)
                    {//重试0,1,2,3都在获取校验码
                        logger.InfoFormat("Abort,close & re-open");
                        ScreenUtil.SetCursorPos(submitPoints.buttons[0].x+188, submitPoints.buttons[0].y);//取消按钮
                        ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero);
                        return false;//放弃本次出价
                    }
                    Thread.Sleep(250);
                }
                else
                    isLoading = false;
            }

            logger.Info("\t\tBEGIN post CAPTACH");
            String txtCaptcha = new HttpUtil().postByteAsFile(URL + "/receive/captcha.do", binaryCaptcha);
            logger.Info("\t\tEND   post CAPTACH");
            byte[] binaryTips = new ScreenUtil().screenCaptureAsByte(submitPoints.captcha[1].x, submitPoints.captcha[1].y, 112, 16);
            String strActive = this.m_captchaUtil.getActive(txtCaptcha, new Bitmap(new System.IO.MemoryStream(binaryTips)));
            logger.InfoFormat("\tEND   identified CAPTCHA = {0}, ACTIVE = {1}", txtCaptcha, strActive);

            logger.Info("\tBEGIN input CAPTCHA");
            {
                for (int i = 0; i < strActive.Length; i++)
                {
                    ScreenUtil.keybd_event(ScreenUtil.keycode[strActive[i].ToString()], 0, 0, 0);
                    System.Threading.Thread.Sleep(50);
                }
            }
            logger.Info("\tEND   input CAPTCHA");

            logger.Info("\tBEGIN click BUTTON[确定]");
            ScreenUtil.SetCursorPos(submitPoints.buttons[0].x, submitPoints.buttons[0].y);
            ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero);
            logger.Info("\tEND   click BUTTON[确定]");

            ScreenUtil.SetCursorPos(submitPoints.buttons[0].x + 188 / 2, submitPoints.buttons[0].y - 10);//确定按钮

            //System.Threading.Thread.Sleep(3000);
            //if (points.Length > 2)
            //{
            //    System.Threading.Thread.Sleep(50);
            //    ScreenUtil.SetCursorPos(points[2].X, points[2].Y);
            //    ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero);

            //    if (points.Length > 3)
            //    {
            //        System.Threading.Thread.Sleep(50);
            //        ScreenUtil.SetCursorPos(points[3].X, points[3].Y);
                    //ScreenUtil.mouse_event((int)(MouseEventFlags.Absolute | MouseEventFlags.LeftDown | MouseEventFlags.LeftUp), 0, 0, 0, IntPtr.Zero);
            //    }
            //}
            logger.Info("END   giveCAPTCHA");
            return true;
        }
Esempio n. 4
0
        /// <summary>
        /// 测试验证码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_captcha_Click(object sender, EventArgs e)
        {
            ScreenUtil screen = new ScreenUtil();
            String[] pos = this.textBox2.Text.Split(new char[] { ',' });
            byte[] content = screen.screenCaptureAsByte(Int32.Parse(pos[0]), Int32.Parse(pos[1]), 120, 38);
            this.pictureBox3.Image = Bitmap.FromStream(new System.IO.MemoryStream(content));

            #region DEBUG
            File.WriteAllBytes("captcha.bmp", content);
            //Bitmap subImg = screen.subImage(new Bitmap(new MemoryStream(content)));
            //this.pictureBox3.Image = subImg;
            //MemoryStream ms = new MemoryStream();
            //subImg.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            //content = ms.ToArray();
            //ms.Close();
            #endregion

            if (this.checkBox1.Checked)//如果选中“校验码”
            {
                String txtCaptcha = new HttpUtil().postByteAsFile(this.textURL.Text + "/receive/dynamic/captcha/detail.do", content);
                String[] array = Newtonsoft.Json.JsonConvert.DeserializeObject<String[]>(txtCaptcha);

                this.pictureBox4.Image = new Bitmap(new MemoryStream(Convert.FromBase64String(array[0])));
                this.pictureBox5.Image = new Bitmap(new MemoryStream(Convert.FromBase64String(array[1])));
                this.pictureBox6.Image = new Bitmap(new MemoryStream(Convert.FromBase64String(array[2])));
                this.pictureBox7.Image = new Bitmap(new MemoryStream(Convert.FromBase64String(array[3])));
                this.pictureBox8.Image = new Bitmap(new MemoryStream(Convert.FromBase64String(array[4])));
                this.pictureBox9.Image = new Bitmap(new MemoryStream(Convert.FromBase64String(array[5])));
                this.label1.Text = array[6];
                //String txtCaptcha = new HttpUtil().postByteAsFile(this.textURL.Text + "/receive/captcha/red.do", content);
                //this.label1.Text = txtCaptcha;

            }
            else//测试“正在加载校验码”
            {
                String strLoading = this.m_orcCaptchaLoading.getCharFromPic(new Bitmap(new System.IO.MemoryStream(content)));

                this.pictureBox4.Image = this.m_orcCaptchaLoading.SubImgs[0];
                this.pictureBox5.Image = this.m_orcCaptchaLoading.SubImgs[1];
                this.pictureBox6.Image = this.m_orcCaptchaLoading.SubImgs[2];
                this.pictureBox7.Image = this.m_orcCaptchaLoading.SubImgs[3];
                this.pictureBox7.Image = this.m_orcCaptchaLoading.SubImgs[4];
                this.pictureBox7.Image = this.m_orcCaptchaLoading.SubImgs[5];
                this.label2.Text = strLoading;
            }
        }