Esempio n. 1
0
        /// <summary>
        /// 由于余票查询连接经常变动所以通过该方法实时获取连接
        /// </summary>
        private void InitLeftTicketQueryUrl()
        {
            string   ticketUrl = StringHelper.GetConfigValByKey(Constant.InitQueryUrl, false);
            HttpItem item      = new HttpItem()
            {
                URL     = ticketUrl,
                Cookie  = HttpRequest.JSessionCookie + "tk=" + AppTk,
                Referer = "https://kyfw.12306.cn/otn/index/initMy12306"
            };
            string ret   = HttpRequest.HttpGet(item).ToString();
            string token = StringHelper.GetSubstring(ret, "CLeftTicketUrl", ';').Replace("'", "");

            SystemCache.SetSysObj(Constant.PassportAppId, StringHelper.GetSubstring(ret, Constant.PassportAppId, ';'));
            string queryUrl = StringHelper.GetConfigValByKey(Constant.QueryUrl, false);
            //更新余票查询连接
            string newQueryUrl = queryUrl.Replace("leftTicket/queryA", token);

            StringHelper.SetConfig(Constant.QueryUrl, newQueryUrl, false);
            LogHelper.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, "余票查询连接 " + newQueryUrl);
            SystemCache.SetSysObj("LeftTicketQueryUrl", newQueryUrl);

            string QueryMinDate   = StringHelper.GetSubstring(ret, "otherMindate", ';').Replace("'", "");
            string QueryMaxDate   = StringHelper.GetSubstring(ret, "otherMaxdate", ';').Replace("'", "");
            string StudentMindate = StringHelper.GetSubstring(ret, "studentMindate", ';').Replace("'", "");
            string StudentMaxdate = StringHelper.GetSubstring(ret, "studentMaxdate", ';').Replace("'", "");

            SystemCache.SetSysObj(Constant.OtherMindate, QueryMinDate);     //最小查询日期
            SystemCache.SetSysObj(Constant.OtherMaxdate, QueryMaxDate);     //最大查询日期
            SystemCache.SetSysObj(Constant.StudentMindate, StudentMindate); //学生票最小查询日期
            SystemCache.SetSysObj(Constant.StudentMaxdate, StudentMaxdate); //学生票最大查询日期
        }
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            GetNetwork();
            this.textBlockHead.Text = StringHelper.GetConfigValByKey("NOTICE", false);
            this.mainFrame.Source   = new Uri(this.train.Tag.ToString(), UriKind.RelativeOrAbsolute);
            this.train.IsChecked    = true;
            //添加缓存(初始化已选乘车日期)
            List <Object> list = new List <Object>();

            list.Add(new { TrainDateMore = DateTime.Now.ToString("yyyy-MM-dd") });
            SystemCache.SetSysObj(Constant.SelectedTakeTrainDateList, list);
        }
Esempio n. 3
0
        /// <summary>
        /// 根据INITIALURL生成的Cookie1生成全局Cookie 如:Set-Cookie: JSESSIONID=E033C660B967E8A0A6F16EAF565EA049; Path=/otn  以后获取联系人以及下订单需要应用
        /// </summary>
        private void MakeClientJSession()
        {
            string   sessionUrl = StringHelper.GetConfigValByKey(Constant.JSessionIDUrl, false);
            HttpItem item       = new HttpItem();

            item.URL                        = sessionUrl;
            item.Referer                    = @"https://kyfw.12306.cn/otn/login/init";
            item.Cookie                     = HttpRequest.InitialCookie + HttpRequest.BeforLoginCookie;
            item.NeedSetJSessionID          = true;
            item.NeedInitReqCookieContainer = true;
            //设置JSessionCookie
            HttpRequest.HttpGet(item);
            string JSessionCookie = HttpRequest.JSessionCookie;

            SystemCache.SetSysObj(Constant.JSessionCookieID, JSessionCookie);
        }
Esempio n. 4
0
        private void Test_Loaded(object sender, RoutedEventArgs e)
        {
            List <Object> list = new List <object>();

            list.Add(new { dateTime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") });
            list.Add(new { dateTime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") });
            list.Add(new { dateTime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") });
            list.Add(new { dateTime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") });
            dataGrid.ItemsSource = list;


            string   url  = StringHelper.GetConfigValByKey(Constant.StartSaleTime, false);
            HttpItem item = new HttpItem()
            {
                URL = url
            };
            string ret  = TrainCommon.HttpRequest.HttpGet(item).ToString();
            string retx = StringHelper.GetValueBetween(ret, "<div id=\"pretime\">", "</div>");
            string temp = retx.Replace("<p>", "").Replace("</p>", "").Replace("<b>", "").Replace("</b>", "").Replace("&nbsp;", "").Replace("<br />", "").Trim();

            string[] tempArr = temp.Split('。');
            for (int i = 0; i < tempArr.Length - 1; i++)
            {
                string[] tempArr2 = tempArr[i].Trim().Replace("\n", "").Replace("起售车站", "$").Trim().Split('$');
                Dictionary <String, List <String> > dict = SystemCache.GetCache().GetObjByKey(Constant.AllSaleStation) as Dictionary <String, List <String> >;
                if (dict == null)
                {
                    dict = new Dictionary <String, List <String> >();
                }
                dict.Add(tempArr2[0].Trim(), tempArr2[1].Trim().Split('、').ToList());
                SystemCache.SetSysObj(Constant.AllSaleStation, dict);
            }

            Dictionary <String, List <String> > dict2 = SystemCache.GetCache().GetObjByKey(Constant.AllSaleStation) as Dictionary <String, List <String> >;

            cb1.ItemsSource       = dict2.Keys.ToList();
            cb1.SelectionChanged += Cb1_SelectionChanged;
        }
Esempio n. 5
0
        private void AuthClient(string uamtk)
        {
            //根据uamtk生成 newapptk
            string   authUrl    = StringHelper.GetConfigValByKey(Constant.Auth, false);
            string   uamauthUrl = StringHelper.GetConfigValByKey(Constant.UamAuthClient, false);
            HttpItem item       = new HttpItem()
            {
                URL      = authUrl,
                PostData = new Dictionary <string, string>()
                {
                    { "appid", "otn" }
                },
                Cookie  = HttpRequest.BeforLoginCookie + ";" + "uamtk=" + uamtk,
                Referer = @"https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin"
            };
            string  authRet  = HttpRequest.HttpPost(item);
            JObject json     = JObject.Parse(authRet);
            string  newapptk = json["newapptk"].ToString();

            AppTk = newapptk;
            SystemCache.SetSysObj(Constant.AppToken, newapptk);
            //获取验证信息(好像只显示用户名)
            HttpItem item2 = new HttpItem()
            {
                URL      = uamauthUrl,
                Cookie   = HttpRequest.JSessionCookie,
                PostData = new Dictionary <String, String>()
                {
                    { "tk", newapptk }
                }
            };
            //string uamauthRet = HttpRequest.HttpPost(item2);
            //JObject json2 = JObject.Parse(uamauthRet);
            //string userName = json2["username"].ToString();
            //SystemCache.SetSysObj(Constant.CurrentUserName, UserName);
        }
Esempio n. 6
0
        private void InitAllSaleStation()
        {
            string   url  = StringHelper.GetConfigValByKey(Constant.StartSaleTime, false);
            HttpItem item = new HttpItem()
            {
                URL = url
            };
            string ret  = TrainCommon.HttpRequest.HttpGet(item).ToString();
            string retx = StringHelper.GetValueBetween(ret, "<div id=\"pretime\">", "</div>");
            string temp = retx.Replace("<p>", "").Replace("</p>", "").Replace("<b>", "").Replace("</b>", "").Replace("&nbsp;", "").Replace("<br />", "").Trim();

            string[] tempArr = temp.Split('。');
            for (int i = 0; i < tempArr.Length - 1; i++)
            {
                string[] tempArr2 = tempArr[i].Trim().Replace("\n", "").Replace("起售车站", "$").Trim().Split('$');
                Dictionary <String, List <String> > dict = SystemCache.GetCache().GetObjByKey(Constant.AllSaleStation) as Dictionary <String, List <String> >;
                if (dict == null)
                {
                    dict = new Dictionary <String, List <String> >();
                }
                dict.Add(tempArr2[0].Trim(), tempArr2[1].Trim().Split('、').ToList());
                SystemCache.SetSysObj(Constant.AllSaleStation, dict);
            }
        }
        /// <summary>
        /// 查询火车信息列表
        /// </summary>
        /// <param name="startStation">出发站</param>
        /// <param name="endStation">到达站</param>
        /// <param name="takeDate">出发日期</param>
        /// <param name="ticketType">席座类型(软卧,硬座等)</param>
        /// <param name="seat">票种(成人,学生,儿童)</param>
        /// <returns></returns>
        public List <Train> GetTrainTableList(string startStation, string endStation, DateTime takeDate, string ticketType, Int32 seat)
        {
            List <Train> trainList = null;
            //DataTable dt = new DataTable("Datas");
            //dt.Columns.Add("序号", Type.GetType("System.Int32"));
            //dt.Columns[0].AutoIncrement = true;
            //dt.Columns[0].AutoIncrementSeed = 1;
            //dt.Columns[0].AutoIncrementStep = 1;
            //dt.Columns.Add("车次", Type.GetType("System.String"));
            //dt.Columns.Add("出发站(s)", Type.GetType("System.String"));
            //dt.Columns.Add("目的站(s)", Type.GetType("System.String"));
            //dt.Columns.Add("历时", Type.GetType("System.String"));
            //dt.Columns.Add("商务座", Type.GetType("System.String"));
            //dt.Columns.Add("一等座", Type.GetType("System.String"));
            //dt.Columns.Add("二等座", Type.GetType("System.String"));
            //dt.Columns.Add("高级软卧", Type.GetType("System.String"));
            //dt.Columns.Add("软卧", Type.GetType("System.String"));
            //dt.Columns.Add("动卧", Type.GetType("System.String"));
            //dt.Columns.Add("硬卧", Type.GetType("System.String"));
            //dt.Columns.Add("软座", Type.GetType("System.String"));
            //dt.Columns.Add("硬座", Type.GetType("System.String"));
            //dt.Columns.Add("无座", Type.GetType("System.String"));
            //dt.Columns.Add("其他", Type.GetType("System.String"));
            //dt.Columns.Add("备注", Type.GetType("System.String"));
            //dt.Rows.Add(new object[] { null, train[3], "郑州 " + train[8], "上海 " + train[9]);

            string url = StringHelper.GetConfigValByKey("QUERYURL", false);
            //席座类型
            //ticketType
            //票种
            string seatType = seat == 0 ? "ADULT" : (seat == 1 ? "0X00" : " ");
            Dictionary <String, String> parames = new Dictionary <string, string> {
                { "leftTicketDTO.train_date", takeDate.ToString("yyyy-MM-dd") },
                { "leftTicketDTO.from_station", startStation },
                { "leftTicketDTO.to_station", endStation },
                { "purpose_codes", seatType.ToString() },
            };
            HttpItem item = new HttpItem()
            {
                URL      = url,
                Referer  = "https://kyfw.12306.cn/otn/leftTicket/init",
                PostData = parames,
                Cookie   = HttpRequest.JSessionCookie + "tk=" + Login.AppTk
            };
            string originJSON = TrainCommon.HttpRequest.HttpGet(item).ToString();

            //string originJSON = "{\"data\":{\"flag\":\"1\",\"map\":{\"SHH\":\"上海\",\"SNH\":\"上海南\",\"XUN\":\"信阳\"},\"result\":[\"ANNFYzQXMTSV6Z5AQ32qZwMm2YztAH1wV7p%2FeNEQ1W%2BYjRZ8kpo%2Bhds9JlnsROxfl%2BqluEGylrf8%0ANxQ5aDwJadAJL6u5i1ypTtT9GunzhMFX1Q7ZKA8rVnCph44fYuOFkUY4smS1jhoiSqIo3kV%2FpbOf%0A4jVlb1kwjpHUI3pVlS0CDktXXm38xNcXGeXoCNt08akMCNoHqBGhp%2Bl5L1ilpaAnIP8IsPUYkNkE%0A%2B0%2Fi65aH4qAs70%2FaeWKYDs26lX9kZbpM8MLNYjA%3D|预订|390000K7520G|K752|XUN|SNH|XUN|SNH|13:30|05:42|16:12|Y|IowYIPoZ%2B6ym2KcqJHtu3Gwhvqs47ejPulCrl2HJgIY%2FfuoNfW6we9VDgbs%3D|20180121|3|N2|01|21|0|0||||无|||有||2|有|||||10401030|1413|1\",\"dw5KsNj4bymOaI2zlkbZiLTBD78rRGi4S542V4sUCibDn0h6fJJb16mZ%2F30yi0J3FCMUO8Iufmh3%0AmLomu0QY70xhJu2RSxMo4z7a879uEqzE3rUCFLoDVBYcKmJG0%2BIqLS4XGkx2xpXNmgh4uMB9A76S%0Aod%2FpwlmDb4o6HKDVAW2j%2ByD9cbDg8a5WubmQMTwmJYrObcWQNstt%2FRHaV4gxiAzYzRY%2BgOBF9hI3%0A35uKONBSylE96WTtnAAVFSsXupg1oEGSLg%3D%3D|预订|390000K4620C|K462|PEN|SHH|XUN|SHH|22:00|10:20|12:20|Y|MKMqQGpPXOIE56zzBLrLJBPtCYVvR9%2B%2FheycY60d%2BfEFFWrVcEoBga7%2FcJg%3D|20180121|3|N2|05|16|0|0||||1|||有||无|有|||||10401030|1413|0\"]},\"httpstatus\":200,\"messages\":\"\",\"status\":true}";
            if (!originJSON.Contains("\"flag\":\"1\""))
            {
                LogHelper.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, "出错了请检查网络");
                return(null);
            }
            JObject json   = JObject.Parse(originJSON);
            JArray  result = JObject.Parse(json["data"].ToString())["result"] as JArray;

            string[] train     = null;
            Train    trainItem = null;

            if (result != null)
            {
                trainList = new List <Train>();
                foreach (var arry in result)
                {
                    train     = arry.ToString().Split('|');
                    trainItem = new Train();
                    trainItem.TrainSecretStr  = System.Web.HttpUtility.UrlDecode(train[0]);                 //车次加密信息解码
                    trainItem.TrainID         = GetFormatTicket(train[3]);                                  //车次
                    trainItem.TrainNo         = GetFormatTicket(train[2]);                                  //车次码
                    trainItem.FromStation     = GetFormatTicket(SystemCache._station[train[6]].ToString()); //出发站
                    trainItem.ToStation       = GetFormatTicket(SystemCache._station[train[5]].ToString()); //到达站
                    trainItem.StartTime       = GetFormatTicket(train[8]);                                  //出发时间
                    trainItem.EndTime         = GetFormatTicket(train[9]);                                  //到达时间
                    trainItem.Duration        = GetFormatTicket(train[10]);                                 //历时
                    trainItem.BusinessSeat    = GetFormatTicket(train[32]);                                 //商务座特等座
                    trainItem.FirstLevelSeat  = GetFormatTicket(train[31]);                                 //一等座
                    trainItem.SecondLevelSeat = GetFormatTicket(train[32]);                                 //二等座
                    trainItem.HighSoftBerth   = GetFormatTicket(train[25]);                                 //高级软卧(un)
                    trainItem.SoftBerth       = GetFormatTicket(train[23]);                                 //软卧
                    trainItem.PneumaticBerth  = GetFormatTicket(train[27]);                                 //动卧
                    trainItem.HardBerth       = GetFormatTicket(train[28]);                                 //硬卧
                    trainItem.SoftSeate       = GetFormatTicket(train[24]);                                 //软座
                    trainItem.HardSeate       = GetFormatTicket(train[29]);                                 //硬座
                    trainItem.NoSeat          = GetFormatTicket(train[26]);                                 //无座
                    trainItem.Other           = GetFormatTicket(train[22]);                                 //其他
                    trainItem.TrainLocation   = GetFormatTicket(train[15]);                                 //列车坐标
                    trainItem.IsOpen          = GetFormatTicket(train[11]);                                 //是否开票(Y 如14:30起售)或者系统维护时间(IS_TIME_NOT_BUY)

                    trainItem.Remark = GetFormatTicket(train[1]);                                           //备注
                                                                                                            //train[13]出发日期
                    trainList.Add(trainItem);
                }
            }

            SystemCache.SetSysObj(Constant.TrainList, trainList);
            return(trainList);
        }