惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
Recorded Future
Recorded Future
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
Y
Y Combinator Blog
N
News | PayPal Newsroom
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Help Net Security
Help Net Security
博客园 - Franky
SecWiki News
SecWiki News
Recent Announcements
Recent Announcements
T
Troy Hunt's Blog
The Register - Security
The Register - Security
The Last Watchdog
The Last Watchdog
Webroot Blog
Webroot Blog
S
Security Affairs
博客园 - 司徒正美
S
Schneier on Security
I
InfoQ
博客园_首页
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Threat Research - Cisco Blogs
Forbes - Security
Forbes - Security
腾讯CDC
N
Netflix TechBlog - Medium
N
News and Events Feed by Topic
Cloudbric
Cloudbric
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
Recent Commits to openclaw:main
Recent Commits to openclaw:main
B
Blog
V
Vulnerabilities – Threatpost
C
Check Point Blog
Google DeepMind News
Google DeepMind News
Google Online Security Blog
Google Online Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Cisco Blogs
Schneier on Security
Schneier on Security
O
OpenAI News
K
Kaspersky official blog

博客园 - 武广敬

There is no mode by that name loaded / mode not given 产生原因(个案) 使用VS调试JS 使用U盘安装Windows Server2008 德广火车票助手源码 请各位前辈给些建议 用户中心 - 博客园 vs2008 SmartDevice 程序 访问Internet时出错 提示:未能建立与网络的连接。解决方案 关于微软有自增列父子表更新程序的问题 免费的网上问卷调查程序 在线HTML标签验证工具.很好用的. 微软扶持软件公司计划 使用Visual Studio生成安装程序并设定连接字符串及其他自定义操作. - 武广敬 - 博客园 新鲜出炉的Asp.Net MVC电子书 我理解的云计算 设定了窗口的AcceptButton及CancelButton点击时无动作的原因 使用电脑+MODEM 订火车票 (可以一直自动重拨) 黄牛党/铁路内部人员不得进入!!! UI设计注意点 可以让DataGridView中多个ComboBox级联的工具类-初版 通过反射得到对象 DataGridViewComboBoxColumn 可以让用户输入并自动匹配选项的问题 [问了很多人,找了很多站都没得到答案,所以只好放首页,请管理员体谅.谢谢!]
德广火车票助手登录12306代码详解-登录
武广敬 · 2012-09-28 · via 博客园 - 武广敬

*以下为内容仅于用技术交流学习,欢迎指教.

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="obj">此参数是为了符合WaitCallback委托的方法签名而设,无实际意义</param>
        private void login(object obj)
        {
            try
            {
                running = true;
                // 等待
                sleep();
                if (stop == true)
                {
                    return;
                }
                if (obj != null)
                {
                    Thread.CurrentThread.Name = obj.ToString();
                }
                if (logged == true)
                {
                    if (MessageBox.Show("您已经登录,您需要再次进入12306网站吗?如果您已经退出,就需要重新登录!", "德广火车票助手 温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        this.Invoke(LoggedDelegate);
                        //openie();
                    }
                    running = false;
                    return;
                }

                Trace.WriteLine("login()");
                count++;
                System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
                //通过此路径取得登录需要的loginRand变量的值,随机码.
                string uri = "https://dynamic.12306.cn/otsweb/loginAction.do?method=loginAysnSuggest";

                string randStr = CommUitl.getString(uri, CommData.cookieContainer);
                
                randStr = randStr.Split(',')[0].Split(':')[1].Replace("\"", string.Empty);


                //登录请求提交路径
                uri = "https://dynamic.12306.cn/otsweb/loginAction.do?method=login";

                // 为参数变量赋值
                List<KeyValuePair<string, string>> param = new List<KeyValuePair<string, string>>();
                // 随机码
                param.Add(new KeyValuePair<string, string>("loginRand", randStr));
                // 退票登录
                param.Add(new KeyValuePair<string, string>("refundLogin", "N"));
                // 退票标识
                param.Add(new KeyValuePair<string, string>("refundFlag", "Y"));
                // 登录用户名
                param.Add(new KeyValuePair<string, string>("loginUser.user_name", txtUserName.Text));
                // 
                param.Add(new KeyValuePair<string, string>("nameErrorFocus", string.Empty));
                // 密码
                param.Add(new KeyValuePair<string, string>("user.password", txtPassword.Text));
                // 
                param.Add(new KeyValuePair<string, string>("passwordErrorFocus", string.Empty));
                // 图形验证码
                param.Add(new KeyValuePair<string, string>("randCode", txtVerificationCode.Text));
                // 
                param.Add(new KeyValuePair<string, string>("randErrorFocus", string.Empty));

                HttpWebResponse response = null;
                try
                {
                    // 提交登录请求
                    response = HttpWebResponseUtility.CreatePostHttpResponse(uri, param, null, DefaultUserAgent, Encoding.ASCII, cookieCollection, uri);
                }
                catch (Exception ex)
                {
                    // 显示异常信息
                    this.Invoke(this.showMsgDelegate, ex.Message);
                }

                if (response != null)
                {
                    // 得到返回的数据流
                    Stream receiveStream = response.GetResponseStream();
                    // 如果有压缩,则进行解压
                    if (response.ContentEncoding.ToLower().Contains("gzip"))
                    {
                        receiveStream = new GZipStream(receiveStream, CompressionMode.Decompress);
                    }
                    // 得到返回的字符串
                    html = new StreamReader(receiveStream).ReadToEnd();
                    // 进行各种错误判断
                    if (html.IndexOf("当前访问用户过多") > 0)
                    {
                        this.Invoke(this.showMsgDelegate, "当前访问用户过多");
                        login(null);
                    }
                    else if (html.IndexOf("请输入正确的验证码") > 0)
                    {
                        messageBoxShowInfo("请输入正确的验证码!");
                        this.Invoke(focusDelegate, new object[] { txtVerificationCode });
                        this.Invoke(setControlTextDelegate, new object[] { txtVerificationCode, string.Empty, true });
                        getVerificationCode(this);
                    }
                    else if (html.IndexOf("登录名不存在") > 0)
                    {
                        messageBoxShowInfo("登录名不存在!!");
                        this.Invoke(focusDelegate, new object[] { txtUserName });
                    }
                    else if (html.IndexOf("密码输入错误") > 0)
                    {
                        messageBoxShowInfo("密码输入错误,如果多次输入错误可能会被锁定帐户!");
                        this.Invoke(focusDelegate, new object[] { txtPassword });
                        this.Invoke(setControlTextDelegate, new object[] { txtPassword, string.Empty, true });
                    }
                    else if (html.IndexOf("已经被锁定") > 0)
                    {
                        messageBoxShowInfo("您的用户已经被锁定,请稍候再试!");
                    }
                    else if (html.IndexOf("系统维护中") > 0)
                    {
                        //messageBoxShowInfo("系统维护中!");
                        this.Invoke(this.showMsgDelegate, "系统维护中!");
                        Thread.Sleep((Int32)numInterval.Value*1000);
                        login(null);
                    }
                    else if (html.IndexOf("我的12306") > 0)
                    {
                        // 登录成功,激活窗口,提醒用户
                        this.Invoke(activateDelegate);
                        // 记录登录用时及次数
                        endTime = DateTime.Now;
                        logged = true;
                        timeSpan = endTime.Subtract(beginTime);
                        timeSpanStr = getTimeSpanString(timeSpan);

                        //MessageBox.Show("经过 " + timeSpanStr + ", " + count + " 次的尝试后,您已经登录成功!" + Environment.NewLine
                        //    + "点击确定打开12306网站,请忽略登录界面,直接点击\"车票预订\"就可以啦!" + Environment.NewLine
                        //    + Environment.NewLine
                        //    + "深圳市德广信息技术有限公司 祝您:" + Environment.NewLine
                        //    + "回家一路顺风!全家身体健康!幸福快乐!事事如意!", "德广火车票助手 恭喜您", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                        this.Invoke(this.showMsgDelegate, "登录成功:用"+timeSpanStr + "/" + count + " 次");
                        // 触发登录成功事件
                        this.Invoke(LoggedDelegate);
                        // 修改要发布到微博的默认内容
                        this.Invoke(shareToWeiboDelegate, new object[] { "我用#德广火车票助手#经过" + timeSpanStr + "尝试登录" + count + "次后,成功登录上了12306.cn!你用了多长时间才登录成功的呢?" });
                        //openie();
                        //this.Invoke(this.showMsgDelegate, "登录成功!");
                    }
                    else
                    {
                        Trace.WriteLine(html);
                        login(null);
                    }

                    Trace.WriteLine(response.StatusCode);
                }
                else
                {
                    login(null);
                }
            }
            catch (WebException webex)
            {
                this.Invoke(this.showMsgDelegate, webex.Message);
                login(null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Invoke(setControlTextDelegate, new object[] { btnLogin, "登录", true });
                running = false;
            }
        }