protected bool ChencSubmitDatas(CookieContainer cookieContainer, String postData)
 {
     var submitAction = new SubmitOrderAction();
     var translation = new HTML_Translation();
     submitAction.PostData = postData;
     var str = submitAction.CheckOrderInfoEx(cookieContainer);
     var returnString = translation.TranslationHtmlEx(str);
     if (returnString["data"]["errMsg"] != null && returnString["data"]["errMsg"].ToString() != "")
     {
         return  _checkState = false;
     }
     if (str.Contains("取消次数过多"))
     {
         return _checkState = false;
     }
     if (returnString["data"]["get608Msg"] != null)
     {
         return  _checkState = false;
     }
     if (returnString["messages"].Any())
     {
         return _checkState = false;
     }
     return _checkState = true;
 }
 protected void InitPassengerDTO(CookieContainer cookieContainer, String token)
 {
     var passengerAction = new GetPassengerAction();
     passengerAction.PostData = string.Format("_json_att=&REPEAT_SUBMIT_TOKEN={0}", token);
     passengerAction.GetPassengersAllJson((strPassenger) =>
     {
         var htmlTrans = new HTML_Translation();
         var returnStrings = htmlTrans.TranslationHtmlEx(strPassenger);
         if (returnStrings["data"]["normal_passengers"].Count() > 0)
             _dataStatus= true;
         else
         {
             _dataStatus= false;
         }
     }, cookieContainer);
 }
        protected void InitTokenDatasDTO(CookieContainer cookieContainer,string postData)
        {
            TokenDatas.Clear();
            var submitAction = new SubmitOrderAction();
            var htmlTran = new HTML_Translation();
            submitAction.PostData = postData;
            submitAction.EnterSubmitPage((str) =>
            {
                var returnString = htmlTran.TranslationHtmlEx(str);
                if (returnString["messages"].Any())
                {
                    if (str.Contains("未完成订单"))
                    {
                        TokenDatas["errMsg"] = "你有未完成的订单等待处理";
                        return;
                    }
                    else
                    {
                        TokenDatas["errMsg"] = "获取Token失败";
                        return;
                    }
                }
                string tokenHtml = submitAction.GetTokenFromSubmitPage(cookieContainer);
                TokenDatas["Token"] =
                    System.Text.RegularExpressions.Regex.Match(tokenHtml,
                        "(?<=var globalRepeatSubmitToken = ')[0-9abcdefABCDEF]{32}").ToString();
                TokenDatas["leftTicket"] =
                    System.Text.RegularExpressions.Regex.Match(tokenHtml, "(?<='leftTicketStr':')[0-9A-Za-z]{30,50}")
                        .ToString();
                TokenDatas["keyCheck"] =
                    System.Text.RegularExpressions.Regex.Match(tokenHtml, "(?<='key_check_isChange':')[0-9A-Za-z]*")
                        .ToString();
                TokenDatas["trainLocation"] =
                    System.Text.RegularExpressions.Regex.Match(tokenHtml, "(?<='train_location':')[^']*").ToString();
                TokenDatas["purposeCodes"] =
                    System.Text.RegularExpressions.Regex.Match(tokenHtml, "(?<='purpose_codes':')[^']*").ToString();
                TokenDatas["ticketInfoForPassengerForm"] =
                    System.Text.RegularExpressions.Regex.Match(tokenHtml, "(?<=ticketInfoForPassengerForm=)[^;]*")
                        .ToString()
                        .Replace("'", "\"");
                var javaObj = htmlTran.TranslationHtmlEx(TokenDatas["ticketInfoForPassengerForm"].ToString());
                TokenDatas["queryLeftNewDetailDTO"] = javaObj["queryLeftNewDetailDTO"] as JObject;

                if (TokenDatas["Token"] != null && TokenDatas["Token"].ToString() != "" &&
                    TokenDatas["leftTicket"] != null && TokenDatas["leftTicket"].ToString() != "")
                {
                    _dataReady = true;
                }
                else
                {
                    _dataReady = false;
                }
            },cookieContainer);
        }
Beispiel #4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            lblInfomation.Text = "";
            if (cboName.Text.Length < 4) return;
            if (txtPwd.Text.Length < 4) return;
            if (txtRandCode.TextLength < 4) return;
            btnLogin.Enabled = false;
            btnLogin.Text = "正在登录";
            Application.DoEvents();
            string name = cboName.Text;
            string pwd = txtPwd.Text;
            var htmlTran = new HTML_Translation();

            //采用同步方式登录
            _la.PostData = string.Format(@"loginUserDTO.user_name={0}&userDTO.password={1}&randCode={2}",
                name, pwd, txtRandCode.Text);
            var strHash = _la.BeginLogin();
            string strHtml = "";
            var cookie = new CookieContainer();
            if (strHash == null)
            {
                MessageBox.Show("难道12306又挂了?","提示",MessageBoxButtons.OK,MessageBoxIcon.Question);
                return;
            }
            foreach (var v in strHash.Keys)
            {
                cookie = (CookieContainer) v;
                strHtml = strHash[v].ToString();
                break;
            }
            if (strHtml == "")
            {
                lblInfomation.Text = "登录失败!";
                btnLogin.Enabled = true;
                btnLogin.Text = "登录";
                txtRandCode.Focus();
                GetRandCodeImg();
                return;
            }
            try
            {

                var returnString = htmlTran.TranslationHtmlEx(strHtml);
                if (returnString["messages"].Any())
                {
                    GetRandCodeImg();
                    DeterMineCall(() =>
                    {
                        lblInfomation.Text = returnString["messages"][0].ToString();
                        this.BeginInvoke(new Action(FormShake));
                        txtRandCode.Text = "";
                        btnLogin.Enabled = true;
                        btnLogin.Text = "登录";
                        txtRandCode.Focus();
                        Application.DoEvents();
                    });
                    return;
                }
                //var loginCheck = returnString["data"] as JavaScriptObject;
                if (returnString["data"] != null && returnString["data"]["loginCheck"].ToString() == "Y")
                {
                    if (chkUserInfo.Checked)
                    {
                        var dc = new DesCryption();
                        ConfigInfo.conf.username = name;
                        ConfigInfo.conf.password = dc.EncryptString(pwd, name);

                        ConfigInfo.savetofile(ConfigInfo.conf.username);
                        string path = AppDomain.CurrentDomain.BaseDirectory + "data\\" + name;
                        if (!System.IO.Directory.Exists(path))
                            System.IO.Directory.CreateDirectory(path);
                        LocalCookie.WriteCookiesToDisk(path + "\\usrCookie.cfg", LoginAction.cookieContainer);

                    }

                    btnLogin.Enabled = true;
                    btnLogin.Text = "登录";
                    this.Hide();
                    //                MessageBox.Show(@"温馨提示:
                    //
                    //1. 自2013年1月4日起,火车票互联网、电话订票预售期延长至20天(含当日),代售点和车站部分售票窗口预售期延长至18天(含当日)。
                    //
                    //2. 自2013年1月1日起,通过电话预订车票的旅客可凭订票时乘车人有效身份证件,到全国任一车站窗口或代售点换取已订车票。当日12:00前已订车票于第二日12:00前取有效;当日12:00后已订车票于第二日24:00前取有效。
                    //
                    //
                    //请广大旅客注意电话订票取票时间和范围、互联网和电话订票起售时间、火车票预售期的变化,合理安排好购票计划。", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    var selectForm = new formSelectTicket(cookie)
                    {
                        ThisCookie = cookie,
                        /*formSelectTicket.cookieContainer = cookie;*/
                        UserName = cboName.Text
                    };
                    selectForm.Show();
                }
                else
                {
                    GetRandCodeImg();
                    lblInfomation.Text = "登录失败";
                    txtRandCode.Text = "";
                    btnLogin.Enabled = true;
                    btnLogin.Text = "登录";
                    txtRandCode.Focus();
                    return;
                }
            }
            catch (Exception)
            {

                MessageBox.Show("23:00至07:00为系统维护时间!","温馨提醒",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                return;
            }
            finally { }
        }
Beispiel #5
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            lblInfomation.Text = "";
            if (cboName.Text.Length < 4)
            {
                return;
            }
            if (txtPwd.Text.Length < 4)
            {
                return;
            }
            if (txtRandCode.TextLength < 4)
            {
                return;
            }
            btnLogin.Enabled = false;
            btnLogin.Text    = "正在登录";
            Application.DoEvents();
            string name     = cboName.Text;
            string pwd      = txtPwd.Text;
            var    htmlTran = new HTML_Translation();

            //采用同步方式登录
            _la.PostData = string.Format(@"loginUserDTO.user_name={0}&userDTO.password={1}&randCode={2}",
                                         name, pwd, txtRandCode.Text);
            var    strHash = _la.BeginLogin();
            string strHtml = "";
            var    cookie  = new CookieContainer();

            if (strHash == null)
            {
                MessageBox.Show("难道12306又挂了?", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return;
            }
            foreach (var v in strHash.Keys)
            {
                cookie  = (CookieContainer)v;
                strHtml = strHash[v].ToString();
                break;
            }
            if (strHtml == "")
            {
                lblInfomation.Text = "登录失败!";
                btnLogin.Enabled   = true;
                btnLogin.Text      = "登录";
                txtRandCode.Focus();
                GetRandCodeImg();
                return;
            }
            try
            {
                var returnString = htmlTran.TranslationHtmlEx(strHtml);
                if (returnString["messages"].Any())
                {
                    GetRandCodeImg();
                    DeterMineCall(() =>
                    {
                        lblInfomation.Text = returnString["messages"][0].ToString();
                        txtRandCode.Text   = "";
                        btnLogin.Enabled   = true;
                        btnLogin.Text      = "登录";
                        txtRandCode.Focus();
                        Application.DoEvents();
                    });
                    return;
                }
                //var loginCheck = returnString["data"] as JavaScriptObject;
                if (returnString["data"] != null && returnString["data"]["loginCheck"].ToString() == "Y")
                {
                    if (chkUserInfo.Checked)
                    {
                        var dc = new DesCryption();
                        ConfigInfo.conf.username = name;
                        ConfigInfo.conf.password = dc.EncryptString(pwd, name);

                        ConfigInfo.savetofile(ConfigInfo.conf.username);
                        string path = AppDomain.CurrentDomain.BaseDirectory + "data\\" + name;
                        if (!System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.CreateDirectory(path);
                        }
                        LocalCookie.WriteCookiesToDisk(path + "\\usrCookie.cfg", LoginAction.cookieContainer);
                    }

                    btnLogin.Enabled = true;
                    btnLogin.Text    = "登录";
                    this.Hide();

                    var selectForm = new formSelectTicket(cookie)
                    {
                        ThisCookie = cookie,
                        /*formSelectTicket.cookieContainer = cookie;*/
                        UserName = cboName.Text
                    };
                    selectForm.Show();
                }
                else
                {
                    GetRandCodeImg();
                    lblInfomation.Text = "登录失败";
                    txtRandCode.Text   = "";
                    btnLogin.Enabled   = true;
                    btnLogin.Text      = "登录";
                    txtRandCode.Focus();
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("23:00至07:00为系统维护时间!", "温馨提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            finally { }
        }
        /// <summary>
        /// 获取联系人列表
        /// </summary>
        private void GetAllPassenger()
        {
            //System.Threading.Thread.Sleep(5000);
            /********************************更新***************************************/
            #region 获取联系人
            modifyAction.GetPassenger((str) =>
            {
                var returnString = translation.TranslationHtmlEx(str);
                if (returnString["data"]["normal_passengers"] == null)
                {
                    MessageBox.Show("获取联系人失败!\r\n" + returnString["data"]["exMsg"].ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //opcmd.HideOpaqueLayer();  //隐藏遮挡层
                    return;
                }
                var htmlTrans = new HTML_Translation();
                htmlTrans.TranslationPassengerJson(str, (passengerList) =>
                {
                    DeterMineCall(() =>
                    {
                        if (passengerList != null)
                        {
                            dgvPassenger.DataSource = passengerList;
                            //opcmd.HideOpaqueLayer();  //隐藏遮挡层
                        }
                    });

                });

            }, _cookieContainer);
            #endregion
        }