Beispiel #1
0
        //获取Token
        private void AutoSubmitPage()
        {
            submitAction.PostData = _postData;
            submitAction.SubmitOrderRequestAsync((str) =>
            {
                var returnString = translation.TranslationHtmlEx(str);
                if (returnString["messages"].Any())
                {
                    if (str.Contains("未完成订单"))
                    {
                        MessageBox.Show("您有未处理订单!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    else
                    {
                        MessageBox.Show(returnString["messages"].ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                if (returnString["data"]["submitStatus"].ToString() != "True")
                {
                    MessageBox.Show("订单验证失败~请重新提交", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                var datas = returnString["data"]["result"].ToString().Split('#');

                _tokenAndLeftTicket["leftTicket"]    = datas[2];
                _tokenAndLeftTicket["keyCheck"]      = datas[1];
                _tokenAndLeftTicket["trainLocation"] = datas[0];
                _tokenAndLeftTicket["purposeCodes"]  = orderData.Purpose_codes;

                ConfirGetQueueCountAsync();
            }, _cookieContainer);
        }
Beispiel #2
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 { }
        }