Ejemplo n.º 1
0
 /// <summary>
 /// 确认购票
 /// </summary>
 /// <param name="passengerTicketStr"></param>
 /// <param name="oldPassengerStr"></param>
 /// <param name="randCode"></param>
 /// <param name="info"></param>
 /// <returns></returns>
 private bool ConfirmSingleForQueue(string passengerTicketStr, string oldPassengerStr, string randCode,
                                    InitInfo info, out string msg)
 {
     msg = "确认购票失败!";
     try
     {
         string url  = "https://kyfw.12306.cn/otn/confirmPassenger/confirmSingleForQueue";
         string data =
             string.Format(
                 "passengerTicketStr={0}&oldPassengerStr={1}&randCode={2}&purpose_codes={3}&key_check_isChange={4}C&leftTicketStr={5}&train_location={6}&choose_seats=&seatDetailType=000&whatsSelect=1&roomType=00&dwAll=N&_json_att=&REPEAT_SUBMIT_TOKEN={7}",
                 UrlEncode(passengerTicketStr), UrlEncode(oldPassengerStr), randCode, info.PurposeCodes,
                 info.KeyCheck, info.LeftTicketInfo,
                 info.Location,
                 info.SubmitToken);
         HttpJsonEntity <Dictionary <string, string> > contentEntity =
             HttpHelper.Post(_agent, url, data, _cookie);
         if (contentEntity.status.ToUpper().Equals("TRUE") && contentEntity.httpstatus.Equals(200))
         {
             if (contentEntity.data.ContainsKey("submitStatus") &&
                 contentEntity.data["submitStatus"].ToUpper().Equals("TRUE"))
             {
                 return(true);
             }
             if (contentEntity.data.ContainsKey("errMsg"))
             {
                 msg = contentEntity.data["errMsg"];
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error("ConfirmSingleForQueue", ex);
     }
     return(false);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 购票
 /// </summary>
 /// <param name="info"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 private bool QueryOrderWaitTime(InitInfo info, out string msg)
 {
     msg = "购票失败,请重试!";
     try
     {
         string timeSpan = GetTimeStamp();
         string url      =
             string.Format(
                 "https://kyfw.12306.cn/otn/confirmPassenger/queryOrderWaitTime?random={0}&tourFlag=dc&_json_att=&REPEAT_SUBMIT_TOKEN={1}",
                 timeSpan, info.SubmitToken);
         string response = HttpHelper.StringGet(_agent, url, _cookie);
         HttpJsonEntity <Dictionary <string, string> > contentEntity =
             JsonConvert.DeserializeObject <HttpJsonEntity <Dictionary <string, string> > >(response);
         if (contentEntity.status.ToUpper().Equals("TRUE") &&
             contentEntity.httpstatus.Equals(200))
         {
             if (contentEntity.data.ContainsKey("msg"))
             {
                 msg = contentEntity.data["msg"];
                 return(false);
             }
             if (contentEntity.data.ContainsKey("orderId") &&
                 !string.IsNullOrEmpty(contentEntity.data["orderId"]))
             {
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         LogHelper.Error("QueryOrderWaitTime", ex);
         return(false);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 预提交订单
 /// </summary>
 /// <param name="secretStr"></param>
 /// <returns></returns>
 private bool SubmitOrderRequest(string secretStr, out string msg)
 {
     msg = "提交失败,需重新登录!";
     try
     {
         string url  = "https://kyfw.12306.cn/otn/leftTicket/submitOrderRequest";
         string data =
             string.Format(
                 "secretStr={0}&train_date={1}&back_train_date={2}&tour_flag=dc&purpose_codes={3}&query_from_station_name={4}&query_to_station_name={5}&undefined=",
                 secretStr,
                 _date, DateTime.Now.ToString("yyyy-MM-dd"), _type, _fromStation.Name, _toStation.Name);
         string ret = HttpHelper.StringPost(_agent, url, data, _cookie);
         HttpJsonEntity <string> retEntity =
             JsonConvert.DeserializeObject <HttpJsonEntity <string> >(ret);
         if (retEntity.messages.Count > 0)
         {
             msg = retEntity.messages[0];
         }
         return(retEntity.status.ToUpper().Equals("TRUE") && retEntity.httpstatus.Equals(200));
     }
     catch (Exception ex)
     {
         LogHelper.Error("SubmitOrderRequest", ex);
         return(false);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取排队数
        /// </summary>
        /// <param name="selectedTrain"></param>
        /// <param name="buySeat"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        private bool GetQueueCount(QueryTicket selectedTrain, string buySeat, InitInfo info)
        {
            try
            {
                string   url = "https://kyfw.12306.cn/otn/confirmPassenger/getQueueCount";
                DateTime dt;
                DateTime.TryParse(_date, out dt);

                string trainDate = UrlEncode(dt.ToString("ddd MMM dd yyyy ",
                                                         CultureInfo.CreateSpecificCulture("en-GB")) + "00:00:00 GMT+0800 (CST)");
                string fromStationTelecode = _fromStation.Code;
                string toStationTelecode   = _toStation.Code;
                string stationTrainCode    = selectedTrain.Station_Train_Code;
                string trainNo             = selectedTrain.Train_No;

                string data =
                    string.Format(
                        "train_date={0}&train_no={1}&stationTrainCode={2}&seatType={3}&fromStationTelecode={4}&toStationTelecode={5}&leftTicket={6}&purpose_codes={7}&train_location={8}&_json_att=&REPEAT_SUBMIT_TOKEN={9}",
                        trainDate, trainNo, stationTrainCode, buySeat, fromStationTelecode, toStationTelecode,
                        info.LeftTicketInfo, info.PurposeCodes, info.Location, info.SubmitToken);
                HttpJsonEntity <Dictionary <string, string> > contentEntity =
                    HttpHelper.Post(_agent, url, data, _cookie);
                LogHelper.Info(selectedTrain.Station_Train_Code + " GetQueueCount成功");
                return(contentEntity.status.ToUpper().Equals("TRUE") && contentEntity.httpstatus.Equals(200));
            }
            catch (Exception ex)
            {
                LogHelper.Error("GetQueueCount", ex);
                return(false);
            }
        }
Ejemplo n.º 5
0
        private bool BuyTicket(string secretStr, List <Passenger> selectedPassengers, string buySeat,
                               QueryTicket selectedTrain, out string msg)
        {
            string url  = " https://kyfw.12306.cn/otn/login/checkUser";
            string data = "_json_att=";

            msg = "购票失败!";
            HttpJsonEntity <Dictionary <string, string> > contentEntity = HttpHelper.Post(_agent, url, data, _cookie);

            if (contentEntity.status.ToUpper().Equals("TRUE") && contentEntity.httpstatus.Equals(200))
            {
                if (SubmitOrderRequest(secretStr, out msg))
                {
                    FormatLogInfo("预提交订单成功!");
                    InitInfo info = GetInitInfo();
                    FormatLogInfo("获取页面信息成功!");
                    if (info != null)
                    {
                        Thread.Sleep(1000);
                        string randCode, passengerTicketStr, oldPassengerStr;
                        if (CheckOrderInfo(selectedPassengers, buySeat, info, out randCode, out passengerTicketStr,
                                           out oldPassengerStr))
                        {
                            FormatLogInfo("核查订单成功!");
                            Thread.Sleep(1000);
                            if (GetQueueCount(selectedTrain, buySeat, info))
                            {
                                FormatLogInfo("获取排队人数成功!");
                                Thread.Sleep(1000);
                                if (ConfirmSingleForQueue(passengerTicketStr, oldPassengerStr, randCode, info,
                                                          out msg))
                                {
                                    Thread.Sleep(1000);
                                    FormatLogInfo("开始排队!");
                                    if (QueryOrderWaitTime(info, out msg))
                                    {
                                        EmailHelper.Send("*****@*****.**", "", selectedTrain.Station_Train_Code);
                                        MessageBox.Show("订票成功,请及时查询及支付订单!");
                                        return(true);
                                    }
                                    FormatLogInfo(msg);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("状态异常,需重新登录");
            }
            return(false);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 核查订单
        /// </summary>
        /// <param name="passengers"></param>
        /// <param name="buySeat"></param>
        /// <param name="info"></param>
        /// <param name="randCode"></param>
        /// <param name="passengerTicketStr"></param>
        /// <param name="oldPassengerStr"></param>
        /// <returns></returns>
        private bool CheckOrderInfo(List <Passenger> passengers, string buySeat, InitInfo info, out string randCode,
                                    out string passengerTicketStr, out string oldPassengerStr)
        {
            randCode           = "";
            passengerTicketStr = string.Empty;
            oldPassengerStr    = string.Empty;
            try
            {
                string url = "https://kyfw.12306.cn/otn/confirmPassenger/checkOrderInfo";
                foreach (Passenger passenger in passengers)
                {
                    string passengerticket = string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", buySeat, "0", "1",
                                                           passenger.passenger_name, passenger.passenger_id_type_code, passenger.passenger_id_no,
                                                           passenger.mobile_no, 'N');
                    passengerTicketStr = passengerTicketStr + passengerticket + "_";

                    string oldPassenger = string.Format("{0},{1},{2},{3}", passenger.passenger_name,
                                                        passenger.passenger_id_type_code, passenger.passenger_id_no, passenger.passenger_type);
                    oldPassengerStr = oldPassengerStr + oldPassenger + "_";
                }

                string data =
                    string.Format(
                        "cancel_flag=2&bed_level_order_num=000000000000000000000000000000&passengerTicketStr={0}&oldPassengerStr={1}&tour_flag=dc&randCode=&_json_att=&REPEAT_SUBMIT_TOKEN={2}",
                        passengerTicketStr.TrimEnd('_'), oldPassengerStr, info.SubmitToken);
                LogHelper.Info("CheckOrderInfo data+" + data);
                HttpJsonEntity <Dictionary <string, string> > contentEntity =
                    HttpHelper.Post(_agent, url, data, _cookie);
                if (contentEntity.status.ToUpper().Equals("TRUE") && contentEntity.httpstatus.Equals(200))
                {
                    if (contentEntity.data.ContainsKey("ifShowPassCode") &&
                        contentEntity.data["ifShowPassCode"].ToUpper().Equals("Y"))
                    {
                        ImgCodeForm form = new ImgCodeForm();
                        form.Cookie = _cookie;
                        form.Agent  = _agent;
                        randCode    = form.RandCode;
                        form.ShowDialog();
                    }
                    LogHelper.Info("checkOrderInfo" + url + "成功");
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                LogHelper.Error("CheckOrderInfo", ex);
                return(false);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns>
        public static bool Login(string userName, string passWord, string randCode)
        {
            //  var popup_passport_appId = "otn";

            string postData = string.Format("loginUserDTO.user_name={0}&userDTO.password={1}&randCode={2}", userName,
                                            passWord, randCode);
            HttpJsonEntity <Dictionary <string, string> > retEntity =
                HttpHelper.Post(DefaultAgent, UrlConfig.login, postData, _cookie);

            if (retEntity.status.ToUpper().Equals("TRUE") && retEntity.httpstatus.Equals(200))
            {
                return(true);
            }
            //   msg = retEntity.messages[0];
            return(false);
        }
Ejemplo n.º 8
0
        private bool Login(string userName, string passWord, string randCode, out string msg)
        {
            msg = "";
            const string loginUrl = "https://kyfw.12306.cn/otn/login/loginAysnSuggest";
            string       postData = string.Format("loginUserDTO.user_name={0}&userDTO.password={1}&randCode={2}", userName,
                                                  passWord, randCode);
            HttpJsonEntity <Dictionary <string, string> > retEntity =
                HttpHelper.Post(DefaultAgent, loginUrl, postData, _cookie);

            if (retEntity.status.ToUpper().Equals("TRUE") && retEntity.httpstatus.Equals(200))
            {
                return(true);
            }
            msg = retEntity.messages[0];
            return(false);
        }
Ejemplo n.º 9
0
        private bool CaptchaCheck0(string answer)
        {
            string postUrl     = "https://kyfw.12306.cn/otn/passcodeNew/checkRandCodeAnsyn";
            string postDataStr = "randCode=" + answer.TrimEnd(',') + "&rand=sjrand";

            if (Type == "1")
            {
                postDataStr = "randCode=" + answer.TrimEnd(',') + "&rand=randp&_json_att=&REPEAT_SUBMIT_TOKEN=" +
                              Token;
            }
            HttpJsonEntity <Dictionary <string, string> > retEntity =
                HttpHelper.Post(Agent, postUrl, postDataStr, Cookie);

            if (retEntity.status.ToUpper().Equals("TRUE") && retEntity.httpstatus.Equals(200))
            {
                if (retEntity.data["result"] == "1")
                {
                    return(true);
                }
            }
            return(false);
        }