Exemplo n.º 1
0
        public string Catch()
        {
            var window = this.MonitorProcess.MainWindowHandle;

            if (window != IntPtr.Zero)
            {
                // 给最后一层的句柄,发送鼠标点击,激活文本框
                List <IntPtr> childHwndList = Api.GetChildHandles(window, "Qt5QWindowIcon", "");
                var           x             = Config.FlightX;
                var           y             = Config.FlightY;
                Api.SetForegroundWindow(window);
                Thread.Sleep(200);
                Api.PostMessage(childHwndList[0], Api.WM_LBUTTONDOWN, 1, x + (y << 16));
                Api.PostMessage(childHwndList[0], Api.WM_LBUTTONUP, 0, x + (y << 16));
                Thread.Sleep(500);

                for (int i = 0; i < 10; i++)
                {
                    Api.SendMessageEx(childHwndList[0], Api.WM_KEYDOWN, (int)ConsoleKey.Backspace, 1);
                    Api.SendMessageEx(childHwndList[0], Api.WM_KEYUP, (int)ConsoleKey.Backspace, 1);
                    Thread.Sleep(50);
                }

                Thread.Sleep(50 * 10);
                foreach (var item in this.Flight)
                {
                    /* 其他模拟器
                     * //Api.PostMessage(window, Api.WM_KEYDOWN, item, 1);
                     * //Api.PostMessage(window, Api.WM_KEYUP, item, 1);
                     * //Api.PostMessage(window, Api.WM_CHAR, item, 1);
                     */
                    Api.SendMessageEx(childHwndList[0], Api.WM_KEYDOWN, item, 1);
                    Api.SendMessageEx(childHwndList[0], Api.WM_KEYUP, item, 1);
                    Thread.Sleep(50);
                }

                Thread.Sleep(1000);
                x = Config.SearchX;
                y = Config.SearchY;
                Thread.Sleep(100);
                Api.PostMessage(window, Api.WM_LBUTTONDOWN, 1, x + (y << 16));
                Api.PostMessage(window, Api.WM_LBUTTONUP, 0, x + (y << 16));

                // 这里需要同步等待网络抓包
                var result = NetwrokFactory.WaitOne(Flight, 5);
                Thread.Sleep(2500);
                x = Config.BackX;
                y = Config.BackY;
                for (int i = 0; i < 2; i++)
                {
                    Api.PostMessage(childHwndList[0], Api.WM_LBUTTONDOWN, 1, x + (y << 16));
                    Api.PostMessage(childHwndList[0], Api.WM_LBUTTONUP, 0, x + (y << 16));
                    Thread.Sleep(100);
                }
                Thread.Sleep(1500);
                return(result);
            }

            return("获取失败,队列没有正确返回数据!");
        }
Exemplo n.º 2
0
        private static void Process(HttpListenerContext context)
        {
            string         rawUrl           = context.Request.Url.ToString();
            string         beforeRewriteUrl = rawUrl.Replace(":8000", string.Empty);
            HttpWebRequest request          = HttpWebRequest.Create(beforeRewriteUrl) as HttpWebRequest;

            SetCookies(request, context);

            request.UserAgent   = context.Request.UserAgent;
            request.Method      = context.Request.HttpMethod;
            request.ContentType = context.Request.ContentType;
            //request.ContentLength = context.Request.ContentLength64;
            if (context.Request.HasEntityBody)
            {
                using (System.IO.Stream body = context.Request.InputStream)
                {
                    byte[] requestdata = GetBytesFromStream(body);
                    request.ContentLength = requestdata.Length;
                    Stream s = request.GetRequestStream();
                    s.Write(requestdata, 0, requestdata.Length);
                    s.Close();
                }
            }
            //request processing
            WebResponse response = request.GetResponse() as HttpWebResponse;
            var         result   = GetBytesFromStream(response.GetResponseStream());

            context.Response.ContentType = response.ContentType;
            context.Response.AppendHeader("Set-Cookie", response.Headers.Get("Set-Cookie"));
            var contentEncoding = (response.Headers["Content-Encoding"] ?? "").Trim().ToLower();//压缩类型

            result = Decompress(result, contentEncoding);
            response.Close();
            try
            {
                //response
                byte[] buffer = result;
                buffer = ReplaceAndAppend(buffer, context.Response.ContentType, beforeRewriteUrl);
                context.Response.ContentLength64 = buffer.Length;
                context.Response.OutputStream.Write(buffer, 0, buffer.Length);
                context.Response.OutputStream.Close();

                if (beforeRewriteUrl.StartsWith("http://ume1.umetrip.com"))
                {
                    NetwrokFactory.AddResponse(Encoding.UTF8.GetString(result));
                }
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
            }
        }