Ejemplo n.º 1
0
 public string GetUserName()
 {
     HttpClient client =new HttpClient(Cookies);
     if (StaticValues.Proxy != "")
     {
         client.Proxy = new WebProxy(StaticValues.Proxy);
     }
     string url = "https://kyfw.12306.cn/otn/index/initMy12306";
     string result = client.Get(url);
     string userName = HtmlHelper.GetContent(result, "user_name=", ";").Replace("'", "");
     return Regex.Unescape(userName);
 }
Ejemplo n.º 2
0
 public GetPassengerDTOsResponseInfo GetMyPassengers()
 {
     HttpClient client = new HttpClient(Cookies);
     if (StaticValues.Proxy != "")
     {
         client.Proxy = new WebProxy(StaticValues.Proxy);
     }
     string url = "https://kyfw.12306.cn/otn/confirmPassenger/getPassengerDTOs";
     string result = client.Get(url);
     if (result != "")
     {
         GetPassengerDTOsResponseInfo ri = JsonHelper.JsonDeserialize<GetPassengerDTOsResponseInfo>(result);
         return ri;
     }
     else
         return null;
 }
Ejemplo n.º 3
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            if (txtIP.Text.Trim() != "" && txtPort.Text.Trim() != "")
            {
                string proxy = txtIP.Text.Trim() + ":" + txtPort.Text.Trim();
                string result = string.Empty;
                btnTest.Enabled = false;
                Thread thread = new Thread(() =>
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        HttpClient client = new HttpClient();
                        client.Proxy = new System.Net.WebProxy(proxy);
                        client.TimeOut = 2000;
                        try
                        {
                            string html = client.Get("http://www.baidu.com");
                            if (html != "")
                            {
                                result = "响应成功!";

                            }
                            else
                            {
                                result = "响应失败!";
                            }
                        }
                        catch
                        { }
                        sw.Stop();
                        result += ",响应花费:" + sw.ElapsedMilliseconds + "ms";
                        this.BeginInvoke(new MethodInvoker(delegate()
                        {
                            lbResult.Text = result;
                            btnTest.Enabled = true;
                        }));
                    });
                thread.IsBackground = true;
                thread.Start();
            }
            else
            {
                lbResult.Text = "请输入完整再提交!";
            }
        }
Ejemplo n.º 4
0
 public QueryTicketResponseInfo QueryLeftTicketDTO(string train_date, string from_station, string to_station)
 {
     HttpClient client =new HttpClient(Cookies);
     if (StaticValues.Proxy != "")
     {
         client.Proxy = new WebProxy(StaticValues.Proxy);
     }
     string url = "https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date={0}&leftTicketDTO.from_station={1}&leftTicketDTO.to_station={2}&purpose_codes=ADULT";
     url = string.Format(url, train_date, from_station, to_station);
     string result = client.Get(url);
     if (result != "")
     {
         QueryTicketResponseInfo ri = JsonHelper.JsonDeserialize<QueryTicketResponseInfo>(result);
         return ri;
     }
     else
         return null;
 }
Ejemplo n.º 5
0
 public TicketInfo GetTicketInfo()
 {
     try
     {
         TicketInfo ti = null;
         HttpClient client = new HttpClient(Cookies);
         if (StaticValues.Proxy != "")
         {
             client.Proxy = new WebProxy(StaticValues.Proxy);
         }
         string url = "https://kyfw.12306.cn/otn/confirmPassenger/initDc";
         string result = client.Get(url, "kyfw.12306.cn", "https://kyfw.12306.cn", "https://kyfw.12306.cn/otn/leftTicket/init");
         var pTicketInfo = HtmlHelper.GetContent(result, "'leftDetails':\\[", "],");
         pTicketInfo = Regex.Unescape(pTicketInfo).Replace("'", "");
         string[] list = pTicketInfo.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
         if (list.Length > 0)
         {
             ti = new TicketInfo();
             List<TickePriceInfo> tpiList = new List<TickePriceInfo>();
             for (int i = 0; i < list.Length; i++)
             {
                 string trainTicketInfoStr = list[i];
                 trainTicketInfoStr = trainTicketInfoStr.Replace("(", "#").Replace(")", "#");
                 string[] priceArray = trainTicketInfoStr.Split("#".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                 TickePriceInfo tpi = new TickePriceInfo();
                 tpi.SeatType = priceArray[0];
                 tpi.Price = priceArray[1];
                 tpi.TicektCnt = priceArray[2];
                 tpiList.Add(tpi);
             }
             ti.TicketList = tpiList;
             ti.Token = HtmlHelper.GetContent(result, "globalRepeatSubmitToken", ";").Replace("=", "").Replace("'", "").Trim();
             string leftTicket = HtmlHelper.GetContent(result, "'queryLeftTicketRequestDTO':", "}");
             leftTicket = leftTicket + "}";
             QueryLeftTicketRequestDTO leftTicketRequst = JsonHelper.FromJson<QueryLeftTicketRequestDTO>(leftTicket);
             //日期转换
             string trainDate = leftTicketRequst.train_date;
             leftTicketRequst.train_date = trainDate.Substring(0, 4) + "-" + trainDate.Substring(4, 2) + "-" + trainDate.Substring(6);
             var key_check_isChange = HtmlHelper.GetContent(result, "'key_check_isChange':", ",").Replace("'", "");
             var _temp = HtmlHelper.GetContent(result, "'queryLeftTicketRequestDTO':", "};");
             _temp = _temp + "};";
             var train_location = HtmlHelper.GetContent(_temp, "'train_location':", "};").Replace("'", "");
             ti.CheckKey = key_check_isChange;
             ti.TrainLocation = train_location;
             ti.LeftTicketInfo = leftTicketRequst;
         }
         return ti;
     }
     catch
     {
         return null;
     }
 }
Ejemplo n.º 6
0
 public bool SubmitOrderRequest(string secretStr,QueryEntity qe,ref string msg)
 {
     HttpClient client = new HttpClient(Cookies);
     if (StaticValues.Proxy != "")
     {
         client.Proxy = new WebProxy(StaticValues.Proxy);
     }
     string url = "https://kyfw.12306.cn/otn/leftTicket/submitOrderRequest";
     string data = "secretStr={0}&train_date={1}&back_train_date={2}&tour_flag=dc&purpose_codes=ADULT&query_from_station_name={3}&query_to_station_name={4}&undefined";
     object[] objs = new object[] { secretStr, qe.train_date, qe.train_date,qe.from_station_telecode_name, qe.to_station_telecode_name};
     data = string.Format(data, objs);
     url = url + "?" + data;
     string result = client.Get(url, "kyfw.12306.cn", "https://kyfw.12306.cn", "https://kyfw.12306.cn/otn/leftTicket/init").Replace("\"","");
     string status = HtmlHelper.GetContent(result, "status:", ",");
     msg = HtmlHelper.GetContent(result, "messages:", ",").Replace("[","").Replace("]","");
     return status == "true";
 }
Ejemplo n.º 7
0
        public List<TrainDetails> GetTrainDetails(string train_no, string start_station, string aim_station, string date)
        {
            try
            {
                HttpClient client = new HttpClient(Cookies);
                if (StaticValues.Proxy != "")
                {
                    client.Proxy = new WebProxy(StaticValues.Proxy);
                }
                List<TrainDetails> list = new List<TrainDetails>();
                string url = "https://kyfw.12306.cn/otn/czxx/queryByTrainNo?";
                string data = "train_no=" + train_no + "&from_station_telecode=" + start_station + "&to_station_telecode=" + aim_station + "&depart_date=" + date; ;
                data = string.Format(data, train_no, start_station, aim_station, date);
                url = url + data;
                string result = client.Get(url);
                string json = HtmlHelper.GetContent(result, "\"data\":{\"data\":", "]}");
                json = json + "]";
                list = JsonHelper.FromJson<List<TrainDetails>>(json);
                return list;
            }
            catch
            {
                return null;
            }
 
        }
Ejemplo n.º 8
0
 public QueryWaitTimeResult QueryOrderWaitTime(string token)
 {
     try
     {
         HttpClient client = new HttpClient(Cookies);
         if (StaticValues.Proxy != "")
         {
             client.Proxy = new WebProxy(StaticValues.Proxy);
         }
         string url = "https://kyfw.12306.cn/otn/confirmPassenger/queryOrderWaitTime?tourFlag=dc&_json_att=&REPEAT_SUBMIT_TOKEN=" + token;
         string result = client.Get(url, "kyfw.12306.cn", "https://kyfw.12306.cn", "https://kyfw.12306.cn/otn/confirmPassenger/initDc");
         string json = HtmlHelper.GetContent(result, "\"data\":", "},") + "}";
         QueryWaitTimeResult qw = JsonHelper.FromJson<QueryWaitTimeResult>(json);
         return qw;
     }
     catch
     {
         return null;
     }
 }
Ejemplo n.º 9
0
        static void Main()
        {
            try
            {
                //处理未捕获的异常   
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理UI线程异常   
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常   
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);


                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                //删除老版本文件
                string[] oldFiles = { "Common.dll", "GlassButton.dll", "TicketHelper.exe" };
                foreach (string str in oldFiles)
                {
                    if (File.Exists(str))
                        File.Delete(str);
                }
                string checkUpdateUrl = "http://waner8.sinaapp.com/Update.txt";
                HttpClient client = new HttpClient();
                FileVersionInfo myFileVersion = FileVersionInfo.GetVersionInfo(System.Windows.Forms.Application.ExecutablePath);
                client.TimeOut = 5000;
                string json = client.Get(checkUpdateUrl);
                bool exit = false;
                if (json != "")
                {
                    if (json != "timeout")
                    {
                        UpdateInfo ui = JsonHelper.FromJson<UpdateInfo>(json);
                        if (ui.NewVersion != myFileVersion.FileVersion)
                        {
                            exit = true;
                        }
                    }
                }
                if (exit)
                {
                    json = json.Replace("\"", "'");
                    Process.Start("AutoUpdater.exe", json);
                    Application.Exit();
                }
                else
                {
                    LoadingForm lf = new LoadingForm();
                    if (lf.ShowDialog() == DialogResult.OK)
                    {
                        LoginForm l = new LoginForm();
                        if (l.ShowDialog() == DialogResult.OK)
                        {
                            Application.Run(new MainForm());
                        }
                        else
                        {
                            Application.Exit();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string str = "";
                string strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now.ToString() + "\r\n";
                if (ex != null)
                {
                    str = string.Format(strDateInfo + "异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n",
                         ex.GetType().Name, ex.Message, ex.StackTrace);
                }
                else
                {
                    str = string.Format("应用程序线程错误:{0}", ex);
                }

                writeLog(str);
            }
        }
Ejemplo n.º 10
0
 private void KeyLoginState()
 {
     Thread t = new Thread(() =>
     {
         while (true)
         {
             HttpClient client = new HttpClient(StaticValues.MyCookies);
             string html = client.Get("https://kyfw.12306.cn/otn/index/initMy12306");
             toolStatusBarSys.Text = "已刷新登陆状态," + DateTime.Now.AddMinutes(5).ToString() + "再次刷新!";
             Thread.Sleep(1000 * 60 * 5);//每5分钟检测一次
         }
     });
     t.IsBackground = true;
     t.Start();
 }