public static List<TrainItemInfo> ToTrainItemInfos(string content)
        {
            string[] records = content.Split(new string[]{"\\n"},StringSplitOptions.RemoveEmptyEntries);
            //int step = 16;
            List<TrainItemInfo> list=new List<TrainItemInfo>();
            for (int i = 0; i < records.Length; i ++)
            {
                string[] contents = records[i].Split(',');

                TrainItemInfo itemInfo = new TrainItemInfo()
                                             {
                                                 No=contents[0],
                                                 TrainNo = Common.HtmlUtil.RemoveHtml(contents[ 1]),
                                                 StartStation =Common.HtmlUtil.HtmlDecode(Common.HtmlUtil.RemoveHtml(contents[2])).Trim(),
                                                 EndStation =Common.HtmlUtil.HtmlDecode( Common.HtmlUtil.RemoveHtml(contents[3])).Trim(),
                                                 lishi = Common.HtmlUtil.RemoveHtml(contents[4]),
                                                 ShangwuSeat = Common.HtmlUtil.RemoveHtml(contents[5]),
                                                 TedengSeat = Common.HtmlUtil.RemoveHtml(contents[6]),
                                                 YidengSeat = Common.HtmlUtil.RemoveHtml(contents[7]),
                                                 ErdengSeat = Common.HtmlUtil.RemoveHtml(contents[8]),
                                                 GaojiRuanwoSeat = Common.HtmlUtil.RemoveHtml(contents[9]),
                                                 RuanwoSeat = Common.HtmlUtil.RemoveHtml(contents[10]),
                                                 YingwoSeat = Common.HtmlUtil.RemoveHtml(contents[11]),
                                                 RuanzuoSeat = Common.HtmlUtil.RemoveHtml(contents[12]),
                                                 YingzuoSeat = Common.HtmlUtil.RemoveHtml(contents[13]),
                                                 WuzuoSeat = Common.HtmlUtil.RemoveHtml(contents[14]),
                                                 OtherSeat = Common.HtmlUtil.RemoveHtml(contents[15]),

                                                 Tag = Common.HtmlUtil.RemoveHtml(contents[16])
                                             };
                string tag = contents[16];//<input type='button' class='yuding_u' onmousemove=this.className='yuding_u_over' onmousedown=this.className='yuding_u_down' onmouseout=this.className='yuding_u' onclick=javascript:getSelected('K105#16:03#23:45#240000K1050Q#BXP#NCG#15:48#������#�ϲ�#1*****31714*****00041*****00063*****0000#6CFF0AEBE197C7375772402464FD0A02D0FBFA53D12A0190DE083F2A') value='Ԥ��'></input>
                if (!string.IsNullOrEmpty(tag) && tag.Contains("getSelected('"))
                {

                    tag = tag.Split(new string[] {"getSelected('"},StringSplitOptions.RemoveEmptyEntries)[1].Split('\'')[0];
                    //Z133#11:29#19:45#240000Z13307#BXP#NCG#07:14#������#�ϲ�#01#05#1*****30004*****00011*****00006*****00013*****0000#F3ED9FF7BC7D88A97D9AAD036FAABE99B4223BD3FB94FF50044F66A2#P2
                    //K105#16:03#23:45#240000K1050Q#BXP#NCG#15:48#������#�ϲ�#1*****31714*****00041*****00063*****0000#6CFF0AEBE197C7375772402464FD0A02D0FBFA53D12A0190DE083F2A
                    string[] tags = tag.Split('#');
                    itemInfo.TrainNo = tags[0];
                    itemInfo.lishi = tags[1];
                    itemInfo.TrainStartTime = tags[2];
                    itemInfo.TrainNo4 = tags[3];
                    itemInfo.FromStationTelecode = tags[4];
                    itemInfo.ToStationTelecode = tags[5];
                    itemInfo.ArriveTime = tags[6];
                    itemInfo.FromStationName = tags[7];
                    itemInfo.ToStationName = tags[8];
                    itemInfo.FromStationNo = tags[9];
                    itemInfo.ToStationNo = tags[10];
                    itemInfo.YpInfoDetail = tags[tags.Length - 3];
                    itemInfo.MmStr = tags[tags.Length-2];
                    itemInfo.LocationCode = tags[tags.Length - 1];
                }
                list.Add(itemInfo);
            }
            return list;
        }
        /// <summary>
        /// �¶������������ض������
        /// </summary>
        /// <returns>�޴���ʱ���ؿգ��������ش���</returns>
        public string OrderTicket(TrainItemInfo trainItemInfo,Passenger[] passengers,SeatType seatType)
        {
            /*POST https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=submutOrderRequest HTTP/1.1
             * Referer: https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init
             *
             * station_train_code=Z133&train_date=2012-10-12&seattype_num=&from_station_telecode=BXP&to_station_telecode=NCG&include_student=00
             * &from_station_telecode_name=%E5%8C%97%E4%BA%AC&to_station_telecode_name=%E5%8D%97%E6%98%8C
             * &round_train_date=2012-10-11&round_start_time_str=00%3A00--24%3A00&single_round_type=1&train_pass_type=QB&train_class_arr=QB%23D%23Z%23T%23K%23QT%23
             * &start_time_str=00%3A00--24%3A00&lishi=11%3A29&train_start_time=19%3A45&trainno4=240000Z13305
             * &arrive_time=07%3A14&from_station_name=%E5%8C%97%E4%BA%AC%E8%A5%BF&to_station_name=%E5%8D%97%E6%98%8C&ypInfoDetail=1*****31254*****00241*****00006*****00113*****0111&mmStr=7D1B712CD355990896422EECCC4C11205C7DFD31C26962626B630FEE
             */
            NameValueCollection forms=new NameValueCollection();
            forms["station_train_code"] = trainItemInfo.TrainNo;
            forms["train_date"] = BuyTicketConfig.Instance.OrderRequest.TrainDate.ToString("yyyy-MM-dd");
            forms["seattype_num"] = "";
            forms["from_station_telecode"] = trainItemInfo.FromStationTelecode;
            forms["to_station_telecode"] = trainItemInfo.ToStationTelecode;
            forms["include_student"] = "00";
            forms["from_station_telecode_name"] = BuyTicketConfig.Instance.OrderRequest.FromStationTelecodeName;
            forms["to_station_telecode_name"] = BuyTicketConfig.Instance.OrderRequest.ToStationTelecodeName;
            forms["round_train_date"] = System.DateTime.Today.ToString("yyyy-MM-dd");
            forms["round_start_time_str"] = BuyTicketConfig.Instance.OrderRequest.StartTimeStr;
            forms["single_round_type"] = "1";
            forms["train_pass_type"] = BuyTicketConfig.Instance.OrderRequest.TrainPassType;
            forms["train_class_arr"] = BuyTicketConfig.Instance.OrderRequest.TrainClass;
            forms["start_time_str"] = BuyTicketConfig.Instance.OrderRequest.StartTimeStr;
            forms["lishi"] = trainItemInfo.lishi;
            forms["train_start_time"] =trainItemInfo.TrainStartTime;
            forms["trainno4"] = trainItemInfo.TrainNo4;
            forms["arrive_time"] = trainItemInfo.ArriveTime;
            forms["from_station_name"] = trainItemInfo.FromStationName;
            forms["to_station_name"] = trainItemInfo.ToStationName;
            forms["from_station_no"] = trainItemInfo.FromStationNo;
            forms["to_station_no"] = trainItemInfo.ToStationNo;
            forms["ypInfoDetail"] = trainItemInfo.YpInfoDetail;
            forms["mmStr"] = trainItemInfo.MmStr;
            forms["locationCode"] = trainItemInfo.LocationCode;
            string content = HttpRequest.Create("https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=submutOrderRequest", "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init", Cookie, forms).GetString();
            NameValueCollection htmlForm = Utils.GetForms(content);
            trainItemInfo.YpInfoDetailReal = htmlForm["leftTicketStr"]; //����ʵʱ��ѯ��Ʊ��Ϣ
            if (string.IsNullOrEmpty(trainItemInfo.YpInfoDetailReal))
            {
                Common.LogUtil.Log(content);
                return "�µ�ʧ��:δ�ܻ�ȡ��ʵ����Ʊ����Ϣ";
            }

            ConfirmRequest:

            forms = new NameValueCollection();
            forms["org.apache.struts.taglib.html.TOKEN"] = htmlForm["org.apache.struts.taglib.html.TOKEN"];
            forms["leftTicketStr"] = htmlForm["leftTicketStr"];
            foreach (string key in htmlForm.Keys)
            {
                if(key.StartsWith("orderRequest"))
                {
                    forms[key] = htmlForm[key];
                }
            }
            //&randCode=5xpy&orderRequest.reserve_flag=A

            string vcode = "";
            do
            {
                Stream stream =
                    HttpRequest.Create("https://dynamic.12306.cn/otsweb/passCodeAction.do?rand=randp",
                                       "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init", Cookie,
                                       HttpMethod.GET, "").GetStream();
                Image image = Image.FromStream(stream);
                vcode = GetVCodeByForm(image);
            } while (vcode == "");
            forms["randCode"] = vcode;
            forms["orderRequest.reserve_flag"] = BuyTicketConfig.Instance.SystemSetting.PayType == PayType.Online ? "A" : "B";//A=����֧��,B=ȡƱ�ֳ�֧��
            string postStr = forms.ToQueryString();
            foreach (Passenger passenger in passengers)
            {
                /*
                 * passengerTickets=3,0,1,����,1,362201198...,15910675179,Y
                 * &oldPassengers=����,1,362201198...&passenger_1_seat=3&passenger_1_seat_detail_select=0&passenger_1_seat_detail=0&passenger_1_ticket=1&passenger_1_name=����&passenger_1_cardtype=1&passenger_1_cardno=362201198&passenger_1_mobileno=15910675179&checkbox9=Y
                 * */
                if (passenger.Checked)
                {
                    postStr += "&passengerTickets=" +
                               Common.HtmlUtil.UrlEncode(string.Format("{0},{1},{2},{3},{4},{5},{6},Y",
                                                                       //passenger.SeatType.ToSeatTypeValue(),
                                                                       seatType.ToSeatTypeValue(),
                                                                       (int) passenger.SeatDetailType,
                                                                       (int) passenger.TicketType, passenger.Name,
                                                                       passenger.CardType.ToCardTypeValue(),
                                                                       passenger.CardNo, passenger.MobileNo));
                    postStr += "&oldPassengers=" +
                               Common.HtmlUtil.UrlEncode(string.Format("{0},{1},{2}", passenger.Name,
                                                                       passenger.CardType.ToCardTypeValue(),
                                                                       passenger.CardNo));
                }
            }
            string confirmSingleForQueueOrderUrl = "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=confirmSingleForQueueOrder ";
               string resStateContent=  HttpRequest.Create(confirmSingleForQueueOrderUrl, "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init", Cookie, HttpMethod.POST, postStr).GetString();

            if(resStateContent.Contains("��֤��"))
            {
                goto ConfirmRequest;
            }
            ResState resState = resStateContent.ToJsonObject<ResState>();

            if(resState==null)
            {
                Common.LogUtil.Log(resStateContent);
                return "�µ�ʧ��:ȷ�϶���ʱ��ϵͳ���ص����ݲ���ȷ," + resStateContent;
            }
            else
            {
                if (resState.ErrMsg.Equals("Y"))
                {
                    return "";
                }
                else
                {
                    Common.LogUtil.Log(resStateContent);
                   return "�����쳣,��Ӧ״̬Ϊ��" + resState.ErrMsg;
                }
            }
        }
        /// <summary>
        /// ��ѯ��Ʊ,ȷ��trainItemInfo.YpInfoDetailReal�Ѿ���ȡ
        /// </summary>
        /// <param name="trainItemInfo"></param>
        /// <param name="seatType"></param>
        /// <returns></returns>
        public ResYpInfo Query(TrainItemInfo trainItemInfo,string seatType )
        {
            if(string.IsNullOrEmpty(trainItemInfo.YpInfoDetailReal)) return null;

            //https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=getQueueCount&train_date=2012-10-12&station=Z133&seat=3&from=BXP&to=NCG&ticket=10175031254048600024101750000060895000113030800111

             string queryUrl =string.Format("https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=getQueueCount&train_date={0}&station={1}&seat={2}&from={3}&to={4}&ticket={5}",
                BuyTicketConfig.Instance.OrderRequest.TrainDate.ToString("yyyy-MM-dd"),trainItemInfo.TrainNo,seatType,trainItemInfo.FromStationTelecode,trainItemInfo.ToStationTelecode,trainItemInfo.YpInfoDetailReal);
            ResYpInfo resYpInfo = HttpRequest.Create(queryUrl, "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init", Cookie, HttpMethod.GET, "").GetJsonObject<ResYpInfo>();
            return resYpInfo;
        }
Пример #4
0
        private void WaitOrder(TrainItemInfo optimizeTrain,SeatType seatType )
        {
            WaitResponse waitResponse = null;
            int dispTime = 1;
            int nextRequestTime = 1;
            int errCnt = 0;
            do
            {

                if (dispTime <= 0)
                {

                    switch (dispTime)
                    {
                        case -1:
                            string msg = string.Format("����ɹ��������ţ�{0}", waitResponse.OrderId);
                            Log(account, optimizeTrain.TrainNo + msg);
                            if (OrderSuccessed != null)
                            {
                                OrderSuccessed(this, null); //�����ɹ��¼�
                            }
                            return;
                        case -2:
                            Log(account, "ռ��ʧ�ܣ�ԭ��:" + waitResponse.Msg);
                            break;
                        case -3:
                            Log(account, "�����ѳ���");
                            break;
                        default:
                            Log(account, "�뵽δ��ɶ���ҳ�鿴");
                            break;
                    }
                    return;
                }
                if (dispTime == nextRequestTime)
                {
                    string resContent;
                    waitResponse = account.GetWaitResponse(out resContent);
                    if (waitResponse != null)
                    {
                        dispTime = waitResponse.WaitTime;

                        int flashWaitTime = (int) (waitResponse.WaitTime/1.5);
                        flashWaitTime = flashWaitTime > 60 ? 60 : flashWaitTime;
                        var nextTime = waitResponse.WaitTime - flashWaitTime;

                        nextRequestTime = nextTime <= 0 ? 1 : nextTime;
                    }
                    else
                    {
                        if(errCnt<3)
                        {
                            errCnt++;
                            continue;
                        }
                        else
                        {
                            dispTime = 1;
                        }

                    }
                }

                TimeSpan timeSpan = TimeSpan.FromSeconds(dispTime);

                Log(account, "���Ķ����Ѿ��ύ������Ԥ���ȴ�ʱ��" + timeSpan.ToString("hhСʱmm��ss��") + "��");

                dispTime--;
                Thread.Sleep(1000);
            } while (true);
        }
Пример #5
0
        private void OrderTrain(TrainItemInfo optimizeTrain,SeatType seatType)
        {
            Log(account, string.Format("{0}��ѡ����{1}�µ�", seatType, optimizeTrain.TrainNo));
            Passenger[] passengers =
                TicketSetting.Passengers.Where(p => p.Checked).ToArray();
            SubmitOrderRequest:
            NameValueCollection htmlForm = account.SubmitOrderRequest(optimizeTrain, passengers
                                                                      , seatType == SeatType.����
                                                                            ? SeatType.Ӳ��
                                                                            : seatType);

            optimizeTrain.YpInfoDetailReal = htmlForm["leftTicketStr"]; //����ʵʱ��ѯ��Ʊ��Ϣ
            if (string.IsNullOrEmpty(optimizeTrain.YpInfoDetailReal))
            {
                Log(account, "�µ�ʧ��:δ�ܻ�ȡ��ʵ����Ʊ����Ϣ");
                return;
            }
            if (Stop) return;

            ResPassengerJsonInfo resPassengerJsonInfo = account.GetPassengers(); //��ȡ�˿���Ϣ
            if (Stop) return;

            int vcodeCnt = 1;
            GETVCode:
            //��ȡ��֤��

            string vcode = GetVerifyCode(VCodeType.SubmitOrder, vcodeCnt);
            vcodeCnt = 0;
            if (vcode == "BREAK") return;

            // Thread.Sleep(4000);//��֤�������ʱ 4s
            if (Stop) return;
            string postStr;
            var forms = BuildOrderPostStr(seatType, htmlForm, vcode, passengers, out postStr);

            CheckOrderInfo:
            var checkOrderInfoContent = account.CheckOrderInfo(vcode, postStr);
            if (checkOrderInfoContent.Contains("��֤��"))
            {
                Log(account, "��֤�벻��ȷ:" + checkOrderInfoContent);
                // vcode = "";
                goto GETVCode;
            }
            if (Stop) return;

            //��ѯ���� ��ȡ��Ʊ��Ϣ
            ResYpInfo resYpInfo = account.GetQueueCount(forms, seatType == SeatType.���� ? SeatType.Ӳ�� : seatType);
            Thread.Sleep(1000);//�鿴ʣ����Ʊ ��ʱ1s
            int seatNum = Utils.GetRealSeatNumber(resYpInfo.Ticket, seatType);
            int wuzuo = 0;
            if (seatType == SeatType.Ӳ��)
                wuzuo = Utils.GetRealSeatNumber(resYpInfo.Ticket, SeatType.����);

            Log(account, string.Format("{0},�Ŷ�{1}��,{2} {3} �� {4}", optimizeTrain.TrainNo, resYpInfo.CountT, seatType, seatNum, wuzuo == 0 ? "" : ",���� " + wuzuo + " ��"));

            if (seatType == SeatType.Ӳ��)//Ӳ��Ҫ��ֹ��������Ʊ
            {
                if (seatNum - resYpInfo.CountT < passengers.Length) //��Ʊ����
                {
                    Log(account, optimizeTrain.TrainNo + " ,Ӳ�� ��Ʊ���㣡");
                    if (TicketSetting.ContinueCheckLeftTicketNum) //��ѯ��Ʊ����
                    {
                        Log(account, optimizeTrain.TrainNo + " ,���������Ʊ����");
                        Thread.Sleep(1000);
                        goto CheckOrderInfo;
                    }
                    return;
                }

            }
            else
            {
                if (seatNum < passengers.Length) //С����λ��
                {
                    Log(account, optimizeTrain.TrainNo + " ,��Ʊ���㣡");
                    if (!TicketSetting.ForceTicket) //ǿ���µ�
                    {
                        if (TicketSetting.ContinueCheckLeftTicketNum) //���������Ʊ
                        {
                            Log(account, optimizeTrain.TrainNo + " ,���������Ʊ����");
                            Thread.Sleep(1000);
                            goto CheckOrderInfo;
                        }
                        return;
                    }
                    Log(account, optimizeTrain.TrainNo + " ,ǿ���µ������");
                }
            }

            if (Stop) return;

            //�¶���
            string resStateContent = account.ConfirmSingleForQueue(postStr);
            if (resStateContent.Contains("��֤��"))
            {
                Log(account, "�µ�ʧ�ܣ���֤�벻��ȷ," + resStateContent);
                goto GETVCode;

            }
            ResState resState = resStateContent.ToJsonObject<ResState>();
            if (resState == null)
            {
                Common.LogUtil.Log(resStateContent);
                Log(account, optimizeTrain.TrainNo + ",�µ�ʧ��:ȷ�϶���ʱ��ϵͳ���ص����ݲ���ȷ," + resStateContent);

            }
            else
            {
                if (resState.ErrMsg.Equals("Y"))
                {
                    Log(account, optimizeTrain.TrainNo + "�µ��ɹ�");
                    WaitOrder(optimizeTrain,seatType);

                }
                else
                {
                    Log(account, "�µ�ʧ�ܣ�" + resState.ErrMsg);
                    goto GETVCode;
                }
            }
        }
Пример #6
0
 /// <summary>
 /// https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=submutOrderRequest
 /// </summary>
 /// <param name="trainItemInfo"></param>
 /// <param name="passengers"></param>
 /// <param name="seatType"></param>
 /// <returns>�õ�ҳ��ı����Ϣ</returns>
 public NameValueCollection SubmitOrderRequest(TrainItemInfo trainItemInfo, Passenger[] passengers, SeatType seatType)
 {
     /*POST https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=submutOrderRequest HTTP/1.1
     * Referer: https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init
     *
     * station_train_code=Z133&train_date=2012-10-12&seattype_num=&from_station_telecode=BXP&to_station_telecode=NCG&include_student=00
     * &from_station_telecode_name=%E5%8C%97%E4%BA%AC&to_station_telecode_name=%E5%8D%97%E6%98%8C
     * &round_train_date=2012-10-11&round_start_time_str=00%3A00--24%3A00&single_round_type=1&train_pass_type=QB&train_class_arr=QB%23D%23Z%23T%23K%23QT%23
     * &start_time_str=00%3A00--24%3A00&lishi=11%3A29&train_start_time=19%3A45&trainno4=240000Z13305
     * &arrive_time=07%3A14&from_station_name=%E5%8C%97%E4%BA%AC%E8%A5%BF&to_station_name=%E5%8D%97%E6%98%8C&ypInfoDetail=1*****31254*****00241*****00006*****00113*****0111&mmStr=7D1B712CD355990896422EECCC4C11205C7DFD31C26962626B630FEE
     */
     NameValueCollection forms = new NameValueCollection();
     forms["station_train_code"] = trainItemInfo.TrainNo;
     forms["train_date"] = BuyTicketConfig.Instance.OrderRequest.TrainDate.ToString("yyyy-MM-dd");
     forms["seattype_num"] = "";
     forms["from_station_telecode"] = trainItemInfo.FromStationTelecode;
     forms["to_station_telecode"] = trainItemInfo.ToStationTelecode;
     forms["include_student"] = "00";
     forms["from_station_telecode_name"] = BuyTicketConfig.Instance.OrderRequest.FromStationTelecodeName;
     forms["to_station_telecode_name"] = BuyTicketConfig.Instance.OrderRequest.ToStationTelecodeName;
     forms["round_train_date"] = System.DateTime.Today.ToString("yyyy-MM-dd");
     forms["round_start_time_str"] = BuyTicketConfig.Instance.OrderRequest.StartTimeStr;
     forms["single_round_type"] = "1";
     forms["train_pass_type"] = BuyTicketConfig.Instance.OrderRequest.TrainPassType;
     forms["train_class_arr"] = BuyTicketConfig.Instance.OrderRequest.TrainClass;
     forms["start_time_str"] = BuyTicketConfig.Instance.OrderRequest.StartTimeStr;
     forms["lishi"] = trainItemInfo.lishi;
     forms["train_start_time"] = trainItemInfo.TrainStartTime;
     forms["trainno4"] = trainItemInfo.TrainNo4;
     forms["arrive_time"] = trainItemInfo.ArriveTime;
     forms["from_station_name"] = trainItemInfo.FromStationName;
     forms["to_station_name"] = trainItemInfo.ToStationName;
     forms["from_station_no"] = trainItemInfo.FromStationNo;
     forms["to_station_no"] = trainItemInfo.ToStationNo;
     forms["ypInfoDetail"] = trainItemInfo.YpInfoDetail;
     forms["mmStr"] = trainItemInfo.MmStr;
     forms["locationCode"] = trainItemInfo.LocationCode;
     string content = HttpRequest.Create("https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=submutOrderRequest", "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init", Cookie, forms).GetString();
     NameValueCollection htmlForm = Utils.GetForms(content);
     //trainItemInfo.YpInfoDetailReal = htmlForm["leftTicketStr"]; //����ʵʱ��ѯ��Ʊ��Ϣ
     //if (string.IsNullOrEmpty(trainItemInfo.YpInfoDetailReal))
     //{
     //    Common.LogUtil.Log(content);
     //    return "�µ�ʧ��:δ�ܻ�ȡ��ʵ����Ʊ����Ϣ";
     //}
     return htmlForm;
 }
Пример #7
0
        /// <summary>
        /// �¶������������ض������
        /// </summary>
        /// <returns>�޴���ʱ���ؿգ��������ش���</returns>
        public string OrderTicket(TrainItemInfo trainItemInfo,Passenger[] passengers,SeatType seatType,ref bool stop, bool force=false,RichTextBox rtbLog=null)
        {
            /*POST https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=submutOrderRequest HTTP/1.1
             * Referer: https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init
             *
             * station_train_code=Z133&train_date=2012-10-12&seattype_num=&from_station_telecode=BXP&to_station_telecode=NCG&include_student=00
             * &from_station_telecode_name=%E5%8C%97%E4%BA%AC&to_station_telecode_name=%E5%8D%97%E6%98%8C
             * &round_train_date=2012-10-11&round_start_time_str=00%3A00--24%3A00&single_round_type=1&train_pass_type=QB&train_class_arr=QB%23D%23Z%23T%23K%23QT%23
             * &start_time_str=00%3A00--24%3A00&lishi=11%3A29&train_start_time=19%3A45&trainno4=240000Z13305
             * &arrive_time=07%3A14&from_station_name=%E5%8C%97%E4%BA%AC%E8%A5%BF&to_station_name=%E5%8D%97%E6%98%8C&ypInfoDetail=1*****31254*****00241*****00006*****00113*****0111&mmStr=7D1B712CD355990896422EECCC4C11205C7DFD31C26962626B630FEE
             */
            NameValueCollection forms=new NameValueCollection();
            forms["station_train_code"] = trainItemInfo.TrainNo;
            forms["train_date"] = BuyTicketConfig.Instance.OrderRequest.TrainDate.ToString("yyyy-MM-dd");
            forms["seattype_num"] = "";
            forms["from_station_telecode"] = trainItemInfo.FromStationTelecode;
            forms["to_station_telecode"] = trainItemInfo.ToStationTelecode;
            forms["include_student"] = "00";
            forms["from_station_telecode_name"] = BuyTicketConfig.Instance.OrderRequest.FromStationTelecodeName;
            forms["to_station_telecode_name"] = BuyTicketConfig.Instance.OrderRequest.ToStationTelecodeName;
            forms["round_train_date"] = System.DateTime.Today.ToString("yyyy-MM-dd");
            forms["round_start_time_str"] = BuyTicketConfig.Instance.OrderRequest.StartTimeStr;
            forms["single_round_type"] = "1";
            forms["train_pass_type"] = BuyTicketConfig.Instance.OrderRequest.TrainPassType;
            forms["train_class_arr"] = BuyTicketConfig.Instance.OrderRequest.TrainClass;
            forms["start_time_str"] = BuyTicketConfig.Instance.OrderRequest.StartTimeStr;
            forms["lishi"] = trainItemInfo.lishi;
            forms["train_start_time"] =trainItemInfo.TrainStartTime;
            forms["trainno4"] = trainItemInfo.TrainNo4;
            forms["arrive_time"] = trainItemInfo.ArriveTime;
            forms["from_station_name"] = trainItemInfo.FromStationName;
            forms["to_station_name"] = trainItemInfo.ToStationName;
            forms["from_station_no"] = trainItemInfo.FromStationNo;
            forms["to_station_no"] = trainItemInfo.ToStationNo;
            forms["ypInfoDetail"] = trainItemInfo.YpInfoDetail;
            forms["mmStr"] = trainItemInfo.MmStr;
            forms["locationCode"] = trainItemInfo.LocationCode;
            string content = HttpRequest.Create("https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=submutOrderRequest", "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init", Cookie, forms).GetString();
            NameValueCollection htmlForm = Utils.GetForms(content);
            trainItemInfo.YpInfoDetailReal = htmlForm["leftTicketStr"]; //����ʵʱ��ѯ��Ʊ��Ϣ
            if (string.IsNullOrEmpty(trainItemInfo.YpInfoDetailReal))
            {
                Common.LogUtil.Log(content);
                return "�µ�ʧ��:δ�ܻ�ȡ��ʵ����Ʊ����Ϣ";
            }

            ConfirmRequest:

            forms = new NameValueCollection();
            forms["org.apache.struts.taglib.html.TOKEN"] = htmlForm["org.apache.struts.taglib.html.TOKEN"];
            forms["leftTicketStr"] = htmlForm["leftTicketStr"];
            foreach (string key in htmlForm.Keys)
            {
                if(key.StartsWith("orderRequest"))
                {
                    forms[key] = htmlForm[key];
                }
            }
            //&randCode=5xpy&orderRequest.reserve_flag=A

            string vcode = "";
            do
            {
                Stream stream =
                    HttpRequest.Create("https://dynamic.12306.cn/otsweb/passCodeAction.do?rand=randp",
                                       "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init", Cookie,
                                       HttpMethod.GET, "").GetStream();
                Image image = Image.FromStream(stream);
                vcode = GetVCodeByForm(image);
                if (vcode == "BREAK")
                    return "�û���ֹ";
            } while (vcode == "");
            forms["randCode"] = vcode;
            forms["orderRequest.reserve_flag"] = BuyTicketConfig.Instance.SystemSetting.PayType == PayType.Online ? "A" : "B";//A=����֧��,B=ȡƱ�ֳ�֧��
            //if (force && trainItemInfo.GetRealSeatNumber(seatType) < passengers.Length)
            //{
            //    int p = trainItemInfo.YpInfoDetail.IndexOf(((char)seatType) + "*");
            //    if (p > -1)
            //    {
            //        string newLeftTickets = forms["leftTicketStr"].Remove(p + 6, 1);
            //        newLeftTickets = newLeftTickets.Insert(p + 6, "1");
            //        forms["leftTicketStr"] = newLeftTickets;
            //    }
            //}
            string postStr = forms.ToQueryString();
            foreach (Passenger passenger in passengers)
            {
                /*
                 * passengerTickets=3,0,1,����,1,362201198...,15910675179,Y
                 * &oldPassengers=����,1,362201198...&passenger_1_seat=3&passenger_1_seat_detail_select=0&passenger_1_seat_detail=0&passenger_1_ticket=1&passenger_1_name=����&passenger_1_cardtype=1&passenger_1_cardno=362201198&passenger_1_mobileno=15910675179&checkbox9=Y
                 * */
                if (passenger.Checked)
                {
                    postStr += "&passengerTickets=" +
                               Common.HtmlUtil.UrlEncode(string.Format("{0},{1},{2},{3},{4},{5},{6},Y",
                                                                       //passenger.SeatType.ToSeatTypeValue(),
                                                                       seatType.ToSeatTypeValue(),
                                                                       (int) passenger.SeatDetailType,
                                                                       (int) passenger.TicketType, passenger.Name,
                                                                       passenger.CardType.ToCardTypeValue(),
                                                                       passenger.CardNo, passenger.MobileNo));
                    postStr += "&oldPassengers=" +
                               Common.HtmlUtil.UrlEncode(string.Format("{0},{1},{2}", passenger.Name,
                                                                       passenger.CardType.ToCardTypeValue(),
                                                                       passenger.CardNo));
                }
            }

            string checkOrderInfoUrl = "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=checkOrderInfo&rand=" + vcode;

            CheckOrderInfo:
            if(stop)
            {
                return "�û���ִֹ��";
            }
            string resCheckContent = HttpRequest.Create(checkOrderInfoUrl, "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init", Cookie, HttpMethod.POST, postStr + "&tFlag=dc").GetString();

            if (resCheckContent.Contains("��֤��"))
            {
                goto ConfirmRequest;
            }
            //https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=getQueueCount&train_date=2013-02-04&train_no=24000000T50E&station=T5&seat=1&from=BXP&to=NNZ&ticket=1027353027407675000010273500003048050000
            string  getQueueCountUrl=@"https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=getQueueCount&train_date="
            +forms["orderRequest.train_date"]
            +"&train_no="+forms["orderRequest.train_no"]
            +"&station="+forms["orderRequest.station_train_code"]+
            "&seat="+seatType.ToSeatTypeValue()+
            "&from="+forms["orderRequest.from_station_telecode"]+
            "&to=" + forms["orderRequest.to_station_telecode"] +
            "&ticket="+ forms["leftTicketStr"];
              ResYpInfo resYpInfo =  HttpRequest.Create(getQueueCountUrl, "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init", Cookie, HttpMethod.GET, "").GetJsonObject<ResYpInfo>();;
               // {"countT":0,"count":355,"ticket":"1*****30504*****00001*****00003*****0000","op_1":true,"op_2":false}

            int seatNum = Utils.GetRealSeatNumber(resYpInfo.Ticket, seatType);
            int  wuzuo =0;
            if(seatType==SeatType.Ӳ��)
             wuzuo=Utils.GetRealSeatNumber(resYpInfo.Ticket, SeatType.����);
             if (rtbLog!=null)
              {
                  if (rtbLog.InvokeRequired)
                  {
                      rtbLog.Invoke(new Action(()=>
                          {
                              rtbLog.Text += string.Format("===>{0},{1}���Ŷ�,��Ʊ {2} �� {3}\r\n", seatType, resYpInfo.CountT, seatNum, wuzuo == 0 ? "" : ",���� " + wuzuo + " ��");
                              rtbLog.SelectionStart = rtbLog.TextLength;
                              rtbLog.ScrollToCaret();
                          }));

                  }
                  else
                  {
                      rtbLog.Text += string.Format("===>{0},{1}���Ŷ�,��Ʊ {2} �� {3}\r\n", seatType, resYpInfo.CountT, seatNum, wuzuo == 0 ? "" : ",���� " + wuzuo + " ��");
                      rtbLog.SelectionStart = rtbLog.TextLength;
                      rtbLog.ScrollToCaret();
                  }
              }
              if (force &&  seatNum< passengers.Length)
              {
              if(wuzuo==0)
              {
                  System.Threading.Thread.Sleep(1000);
                  goto CheckOrderInfo;
              }else
              {
                  if(wuzuo <passengers.Length)
                  {
                      System.Threading.Thread.Sleep(1000);
                      goto CheckOrderInfo;
                  }
              }

              }
            string confirmSingleForQueueOrderUrl = "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=confirmSingleForQueueOrder ";
               string resStateContent=  HttpRequest.Create(confirmSingleForQueueOrderUrl, "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init", Cookie, HttpMethod.POST, postStr).GetString();

            if(resStateContent.Contains("��֤��"))
            {
                goto ConfirmRequest;
            }
            ResState resState = resStateContent.ToJsonObject<ResState>();

            if(resState==null)
            {
                Common.LogUtil.Log(resStateContent);
                return "�µ�ʧ��:ȷ�϶���ʱ��ϵͳ���ص����ݲ���ȷ," + resStateContent;
            }
            else
            {
                if (resState.ErrMsg.Equals("Y"))
                {
                    return "";
                }
                else
                {
                    Common.LogUtil.Log(resStateContent);
                   return "�����쳣,��Ӧ״̬Ϊ��" + resState.ErrMsg;
                }
            }
        }
Пример #8
0
        public static List<TrainItemInfo> ToTrainItemInfos(string content, List<TrainItemInfo> oldList)
        {
            string[] records = content.Split(new string[]{"\\n"},StringSplitOptions.RemoveEmptyEntries);
            //int step = 16;
            List<TrainItemInfo> list=new List<TrainItemInfo>();
            for (int i = 0; i < records.Length; i ++)
            {
                string[] contents = records[i].Split(',');

                string trainNo = Common.HtmlUtil.RemoveHtml(contents[1]).Trim();
                TrainItemInfo itemInfo=oldList.Find(p=>p.TrainNo==trainNo);
                if (itemInfo == null)
                    itemInfo = new TrainItemInfo();

                itemInfo.No = contents[0];
                itemInfo.TrainNo = Common.HtmlUtil.RemoveHtml(contents[1]);
                itemInfo.StartStation = Common.HtmlUtil.HtmlDecode(Common.HtmlUtil.RemoveHtml(contents[2])).Trim();
                itemInfo.EndStation = Common.HtmlUtil.HtmlDecode(Common.HtmlUtil.RemoveHtml(contents[3])).Trim();
                itemInfo.lishi = Common.HtmlUtil.RemoveHtml(contents[4]);
                itemInfo.ShangwuSeat = Common.HtmlUtil.RemoveHtml(contents[5]);
                itemInfo.TedengSeat = Common.HtmlUtil.RemoveHtml(contents[6]);
                itemInfo.YidengSeat = Common.HtmlUtil.RemoveHtml(contents[7]);
                itemInfo.ErdengSeat = Common.HtmlUtil.RemoveHtml(contents[8]);
                itemInfo.GaojiRuanwoSeat = Common.HtmlUtil.RemoveHtml(contents[9]);
                itemInfo.RuanwoSeat = Common.HtmlUtil.RemoveHtml(contents[10]);
                itemInfo.YingwoSeat = Common.HtmlUtil.RemoveHtml(contents[11]);
                itemInfo.RuanzuoSeat = Common.HtmlUtil.RemoveHtml(contents[12]);
                itemInfo.YingzuoSeat = Common.HtmlUtil.RemoveHtml(contents[13]);
                itemInfo.WuzuoSeat = Common.HtmlUtil.RemoveHtml(contents[14]);
                itemInfo.OtherSeat = Common.HtmlUtil.RemoveHtml(contents[15]);

                itemInfo.Tag = Common.HtmlUtil.RemoveHtml(contents[16]);
                                             ;
                string tag = contents[16];//<input type='button' class='yuding_u' onmousemove=this.className='yuding_u_over' onmousedown=this.className='yuding_u_down' onmouseout=this.className='yuding_u' onclick=javascript:getSelected('K105#16:03#23:45#240000K1050Q#BXP#NCG#15:48#������#�ϲ�#1*****31714*****00041*****00063*****0000#6CFF0AEBE197C7375772402464FD0A02D0FBFA53D12A0190DE083F2A') value='Ԥ��'></input>
                if (!string.IsNullOrEmpty(tag) && tag.Contains("getSelected('"))
                {

                    tag = tag.Split(new string[] {"getSelected('"},StringSplitOptions.RemoveEmptyEntries)[1].Split('\'')[0];
                    //Z133#11:29#19:45#240000Z13307#BXP#NCG#07:14#������#�ϲ�#01#05#1*****30004*****00011*****00006*****00013*****0000#F3ED9FF7BC7D88A97D9AAD036FAABE99B4223BD3FB94FF50044F66A2#P2
                    //K105#16:03#23:45#240000K1050Q#BXP#NCG#15:48#������#�ϲ�#1*****31714*****00041*****00063*****0000#6CFF0AEBE197C7375772402464FD0A02D0FBFA53D12A0190DE083F2A
                   // K301#02:41#02:05#480000K30423#NCG#YCG#04:46#�ϲ�#�˴�#14#16#1*****31034*****00081*****00003*****0001#MzM1QThFRTVDODlBNjlCODVERUNDMUVEODc4NjdENjlCODNDN0I0OUQyRTJENkUwQzZCMjk4QkE6Ojo6MTM4MDM4MDY2NDk2Nw==#H2
                    string[] tags = tag.Split('#');
                    itemInfo.TrainNo = tags[0];
                    itemInfo.lishi = tags[1];
                    itemInfo.TrainStartTime = tags[2];
                    itemInfo.TrainNo4 = tags[3];
                    itemInfo.FromStationTelecode = tags[4];
                    itemInfo.ToStationTelecode = tags[5];
                    itemInfo.ArriveTime = tags[6];
                    itemInfo.FromStationName = tags[7];
                    itemInfo.ToStationName = tags[8];
                    itemInfo.FromStationNo = tags[9];
                    itemInfo.ToStationNo = tags[10];
                    itemInfo.YpInfoDetail = tags[tags.Length - 3];
                    itemInfo.MmStr = tags[tags.Length-2];
                    itemInfo.LocationCode = tags[tags.Length - 1];
                }
                list.Add(itemInfo);
            }
            return list;
        }