示例#1
0
        private void getOrder(bool reQuery)
        {
            try
            {
                while (true)
                {
                    string tem = getText("https://dynamic.12306.cn/otsweb/order/myOrderAction.do?method=queryOrderWaitTime&tourFlag=dc", false);
                    JObject json = (JObject)JsonConvert.DeserializeObject(tem);
                    object oWaiteTime = json["waitTime"];
                    object oWaiteCount = json["waitCount"];
                    object oOrderId = json["orderId"];
                    object msg = json["msg"];
                    if (oWaiteTime != null)
                    {
                        int waiteTime = Convert.ToInt32(oWaiteTime.ToString());
                        int count = Convert.ToInt32(oWaiteCount.ToString());
                        TimeSpan span = new TimeSpan(0, 0, waiteTime);
                        string strSpan = ((int)span.TotalMinutes).ToString() + "分钟" + span.Seconds + "秒";
                        if (waiteTime >= 0)
                        {
                            addLog("排队时间:" + strSpan + " 排队人数:" + count, true);
                        }
                        else
                        {
                            if (waiteTime == -1)
                            {
                                addLog("购票成功,订单号:" + oOrderId, true);
                                OpenIE open = new OpenIE("购票成功,订单号:" + oOrderId + "。快去付款!");
                                open.ShowDialog();

                            }
                            else if (waiteTime == -2)
                            {
                                addLog("出票失败:" + msg + ",重新购票.", true);
                                if (reQuery && !queryCanRun)
                                {
                                    QueryCount = 0;
                                    queryCanRun = true;
                                    setImage(pcxCommitCode, null);
                                    getCommitPage();
                                }
                            }
                            else if (waiteTime == -3)
                            {
                                addLog("订单已经被取消!", true);
                            }
                            else if (waiteTime == -4)
                            {
                                addLog("正在处理中....", true);
                            }
                            break;
                        }
                    }
                    else
                    {
                        addLog("未知状态", true);
                        break;
                    }
                    Thread.Sleep(1000);
                }
            }
            catch
            {
                addLog("未知状态", true);
            }
        }
示例#2
0
        void checkForm_PostCallBack(HtmlForm sender, string result)
        {
            if (result.IndexOf("登录名") != -1)
            {
                reLogin();
                return;
            }

            try
            {
                JObject o = (JObject)JsonConvert.DeserializeObject(result);
                string error = o["errMsg"].ToString();
                addLog("check:" + error, true);
                if (error.IndexOf("验证码") != -1)
                {
                    getCommitImgCode();

                }
                else if (error.IndexOf("非法") != -1)
                {
                    if (!queryCanRun)
                    {
                        Thread.Sleep(3000);
                        commit(lefttick, token, txtCommitCode.Text);
                    }
                }
                else if (error.IndexOf("重复提交") != -1)
                {
                    if (!queryCanRun)
                    {
                        addLog("##########################", true);
                        getCommitPage();
                    }
                }
                else if (error.IndexOf("已超过余票数") != -1)
                {
                    if (!queryCanRun)
                    {
                        Thread.Sleep(3000);
                        commit(lefttick, token, txtCommitCode.Text);
                    }
                }
                else if (error.IndexOf("未付款订单") != -1)
                {
                    OpenIE openite = new OpenIE("包含未付款订单,快去付款!");
                    openite.ShowDialog();
                    //MessageBox.Show("包含未付款订单,快去付款!");
                }
                else if (error == "Y")
                {
                    addLog("成功提交订单", true);
                    getOrder(true);
                }
            }
            catch
            {
                if (!queryCanRun)
                {
                    getCommitPage();
                }
            }
        }