Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
12306 Auto Login
/*
12306 Auto Login => A javascript snippet to help you auto login 12306.com.
Copyright (C) 2011 Kevintop
Includes jQuery
Copyright 2011, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
Includes 12306.user.js
https://gist.github.com/1554666
Copyright (C) 2011 Jingqin Lynn
Released GNU Licenses.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// ==UserScript==
// @name 12306 Auto Login
// @author kevintop@gmail.com
// @namespace https://plus.google.com/107416899831145722597
// @description A javascript snippet to help you auto login 12306.com
// @include *://dynamic.12306.cn/otsweb/loginAction.do*
// @include *://dynamic.12306.cn/otsweb/login.jsp*
// ==/UserScript==
function withjQuery(callback, safe){
if(typeof(jQuery) == "undefined") {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
if(safe) {
var cb = document.createElement("script");
cb.type = "text/javascript";
cb.textContent = "jQuery.noConflict();(" + callback.toString() + ")(jQuery);";
script.addEventListener('load', function() {
document.head.appendChild(cb);
});
}
else {
var dollar = undefined;
if(typeof($) != "undefined") dollar = $;
script.addEventListener('load', function() {
jQuery.noConflict();
$ = dollar;
callback(jQuery);
});
}
document.head.appendChild(script);
} else {
callback(jQuery);
}
}
withjQuery(function($){
//login
var url = "https://dynamic.12306.cn/otsweb/loginAction.do?method=login";
var queryurl = "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init";
function submitForm(){
var submitUrl = url;
$.ajax({
type: "POST",
url: submitUrl,
data: {
"loginUser.user_name": $("#UserName").val()
, "user.password": $("#password").val()
, "randCode": $("#randCode").val()
},
timeout: 30000,
//cache: false,
//async: false,
success: function(msg){
if (msg.indexOf('请输入正确的验证码') > -1) {
alert('请输入正确的验证码!');
};
if (msg.indexOf('当前访问用户过多') > -1|| msg.match(/var\s+isLogin\s*=\s*false/i)) {
reLogin();
}
else {
$('#refreshButton').html("成功,请点车票预订!");
location.replace(queryurl);
};
},
error: function(msg){
reLogin();
},
beforeSend: function(XHR){
//alert("Data Saved: " + XHR);
}
});
}
var count = 1;
function reLogin(){
count ++;
$('#refreshButton').html("("+count+")次登录中...");
setTimeout(submitForm, 2000);
}
//初始化
if($("#refreshButton").size()<1){
$("#subLink").after($("<a href='#' style='padding: 5px 10px; background: #2CC03E;border-color: #259A33;border-right-color: #2CC03E;border-bottom-color:#2CC03E;color: white;border-radius: 5px;text-shadow: -1px -1px 0 rgba(0, 0, 0, 0.2);'/>").attr("id", "refreshButton").html("自动登录").click(function() {
alert('开始尝试登录,请点确定后耐心等待!');
count = 1;
$(this).html("(1)次登录中...");
submitForm();
return false;
}));
alert('如果使用自动登录功能,请输入用户名、密码及验证码后,点击自动登录,系统会尝试登录,直至成功!');
}
}, true);
@Blog2012
Copy link

Blog2012 commented Jan 9, 2012

IE8上面有自动提交功能了吗?我的怎么没有啊?但是我的是WIN7 有自动刷票功能啊 就是没有自动提交功能

@arronzhang
Copy link

@arronzhang
Copy link

@wnkwu 再更新一下吧.

@nellochen
Copy link

太帅了!非常感谢!

@luo87
Copy link

luo87 commented Jan 10, 2012

这个目前能用吗?我这边显示87行的||||是个错误

@kevintop
Copy link
Author

@ luobailiang 感谢反馈,已经修正。。。

@cest713
Copy link

cest713 commented Jan 10, 2012

还有个BUG,如果验证码错误,还会继续提交,一直出错。

@4801681
Copy link

4801681 commented Jan 10, 2012

脚本地址呢?楼主

@4801681
Copy link

4801681 commented Jan 10, 2012

新改的之后,脚本地址在哪儿?用那个脚本?我不太明白!!

@4801681
Copy link

4801681 commented Jan 10, 2012

谢谢

@Blog2012
Copy link

下一步的验证码可能会变的 刚才看了一下正常登陆之后查询余票 尽然让输入验证码:弎加?=9 这个可能有点难度了 但是对于大大们来说这个可能又是个新的挑战 也对于你们来说简单 只是我们行外人看不懂 O(∩_∩)O~ 有最新的一定会及时反馈的

@kaysonli
Copy link

提交订单太难了,能不能把这个也解决一下?

@luo87
Copy link

luo87 commented Jan 10, 2012

@lzkwin 不是已经有了自动提交订单的?

@kaysonli
Copy link

没看到有自动提交订单的啊

@luo87
Copy link

luo87 commented Jan 10, 2012

@KindleL
Copy link

KindleL commented Jan 10, 2012

这个自动登录是利用了 当出现“当前访问用户过多”后验证码 Session 没有被清空的原理吗?

@doingwell
Copy link

firefox 5.0 下运行有个小bug:第50行,原:
});

修正为:
},false);

@yhdkzy
Copy link

yhdkzy commented Jan 11, 2012

想要在ie下自动登录,安装教程操作后,在登录页面无显示自动登录按钮

@Blog2012
Copy link

IE上面的test已经做了好几天了 完全可以自动登录 自动刷票 修改日期 自动提交 只是暂时自动提交是也会提示 ‘请不要重复提交'和 '确认客票状态再操作' 其他的都已经很完美了 所以可能是你用的脚本不对吧 换个脚本吧、、

@pythonsan
Copy link

提示“您的用户已经被锁定, 请稍候再试”, 杯具了。。。

@cest713
Copy link

cest713 commented Jan 11, 2012

不要紧,点忘记密码,会发送个新密码到邮箱,再用新密码登陆就可以了,再改成原来的也可以正常登陆,今天我也遇到了,估计是做了登陆检测

@tonylzw
Copy link

tonylzw commented Jan 12, 2012

把程序用写字板打开另存为UTF-8格式就不会有乱码了,

@nellochen
Copy link

IE9 不可以么?

@creazestone
Copy link

现在好像都不能用了吧, 登都登不进去。。。。

@cashdiy
Copy link

cashdiy commented Jan 16, 2012

貌似登不进去了。。。

@pythonsan
Copy link

已经登陆不了了, 第一次登陆尝试N次后, 提示未知错误, 第二次登陆尝试了几次后就提示未知错误 :-(

@njuidog
Copy link

njuidog commented Jan 17, 2012

我也是一直未知错误 希望开发人员能尽快解决这个问题 谢谢了

@arronzhang
Copy link

@luneyq
Copy link

luneyq commented Jan 18, 2012

谁能给个最终版本的下载地址啊?不知道哪个是最后的!!!!

@pcrazyc
Copy link

pcrazyc commented Jan 13, 2013

这个现在还能用么。。?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment