Created
January 8, 2012 08:11
-
-
Save kevintop/1577671 to your computer and use it in GitHub Desktop.
12306 Auto Submit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
12306 Auto Submit => A javascript snippet to help you auto submit. | |
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 Submit | |
// @author [email protected],luobailiang | |
// @namespace https://plus.google.com/107416899831145722597/none | |
// @description A javascript snippet to help you auto submit 12306.cn | |
// @include *://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do* | |
// ==/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($){ | |
var userInfoUrl = 'https://dynamic.12306.cn/otsweb/sysuser/user_info.jsp'; | |
//var userInfoUrl = 'https://dynamic.12306.cn/otsweb/order/myOrderAction.do?method=queryMyOrderNotComplete&leftmenu=Y'; | |
var count = 0; | |
var t; | |
var doing = false; | |
function submitForm(){ | |
//更改提交列车日期参数 | |
var wantDate = $("#startdatepicker").val(); | |
$("#start_date").val(wantDate); | |
$("#_train_date_str").val(wantDate); | |
jQuery.ajax({ | |
url: $("#confirmPassenger").attr('action'), | |
data: $('#confirmPassenger').serialize(), | |
type: "POST", | |
timeout: 60000, | |
success: function(msg) | |
{ | |
//Refresh token | |
var match = msg && msg.match(/org\.apache\.struts\.taglib\.html\.TOKEN['"]?\s*value=['"]?([^'">]+)/i); | |
var newToken = match && match[1]; | |
if(newToken) { | |
$("input[name='org.apache.struts.taglib.html.TOKEN']").val(newToken); | |
} | |
if( msg.indexOf('payButton') > -1 ) { | |
//Success! | |
alert("车票预订成功,恭喜!"); | |
window.location.replace(userInfoUrl); | |
return; | |
}else if(msg.indexOf('未处理的订单') > -1){ | |
alert("有未处理的订单!"); | |
window.location.replace(userInfoUrl); | |
} | |
var reTryMessage = ['用户过多','确认客票的状态后再尝试后续操作','请不要重复提交']; | |
for (var i = reTryMessage.length - 1; i >= 0; i--) { | |
if( msg.indexOf( reTryMessage[i] ) > -1 ) { | |
showMsg(reTryMessage[i]); | |
if (doing){ | |
reSubmitForm(); | |
} | |
return; | |
} | |
}; | |
//Parse error message | |
msg = msg.match(/var\s+message\s*=\s*"([^"]*)/); | |
stop(msg && msg[1] || '出错了。。。。 啥错? 我也不知道。。。。。'); | |
}, | |
error: function(msg){ | |
showMsg(msg); | |
reSubmitForm(); | |
} | |
}); | |
}; | |
function showMsg(msg){ | |
$("#msg_div").html($("#msg_div").html() + "<div>第"+count+"次:"+msg+"</div>"); | |
} | |
function reSubmitForm(){ | |
count++; | |
$('#refreshButton').html("("+count+")次提交中...单击停止"); | |
//t = setTimeout(submitForm, 500); | |
} | |
function reloadSeat(){ | |
$("select[name$='_seat']").html('<option value="M" selected="">一等座</option><option value="O" selected="">二等座</option><option value="1">硬座</option><option value="3">硬卧</option><option value="4">软卧</option>'); | |
} | |
//初始化 | |
if($("#refreshButton").size()<1){ | |
//重置后加载所有席别 | |
$("select[name$='_seat']") .each(function(){this.blur(function(){ | |
alert(this.attr("id") + "blur"); | |
});}); | |
//初始化所有席别 | |
$(".qr_box :checkbox[name^='checkbox']").each(function(){$(this).click(reloadSeat)}); | |
reloadSeat(); | |
$(".conWrap").append("<div id='msg_div'></div>"); | |
//日期可选 | |
$("td.bluetext:first").html('<input type="text" name="orderRequest.train_date" value="' +$("td.bluetext:first").html()+'" id="startdatepicker" style="width: 150px;" class="input_20txt" onfocus="WdatePicker({firstDayOfWeek:1})" />'); | |
$(".tj_btn").append($("<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() { | |
if (doing == true){ | |
clearInterval(t); | |
t = 0; | |
$(this).html("自动提交订单"); | |
$('#msg_div').html(""); | |
count = 0; | |
}else { | |
if(window.submit_form_check && !submit_form_check("confirmPassenger") ) { | |
return; | |
} | |
count = 1; | |
$(this).html("(1)次提交中...单击停止"); | |
var freq; | |
switch($("#freq").val()){ | |
case '0': | |
freq = 500; | |
break; | |
case '1': | |
default: | |
freq = 1000; | |
break; | |
case '2': | |
freq = 2000; | |
break; | |
} | |
t = setInterval(submitForm, freq); | |
//submitForm(); | |
} | |
doing = !doing; | |
return false; | |
})); | |
$(".tj_btn").append("自动提交频率:<select id='freq' ><option value='0' >频繁</option><option value='1' selected='' >正常</option><option value='2' >缓慢</option></select>"); | |
} | |
}, true); |
不是这个意思了,呵呵,楼上误会了~~~
其实我已经手工订到了,回家的票是各位大大们的脚本帮忙搞定的,
我说这句话完全木有说生气的意思,因为这是各位达人们无私的奉献,即使不能用了,也要心存感激,
而且当初订回家的票的时候,几位大大,尤其是kevintop 凌晨2点多都还在更新脚本,这个真的不是一般人能做到的
我只是告诉我楼上几位发现脚本不能用的朋友手工订一下,这个时候了,大家肯定都回家了~~
今天,19号,验证码只能使用1次就失效了,求更新。。。。。
昨天测试都很完美。。。。。
别吵,
我想知道 有木有破解这种“使用一次就失效” 验证码的方式。 我还等着订票了。
不管有无成功订到票,都要感谢各位作者的奉献!
验证码只能使用1次,好像没解决办法哦?
϶а취
…------------------ ԭʼʼ ------------------
: "liuming239";
ʱ: 2012119() 1:08
ռ: "yystar"[email protected];
: Re: gist gist: 1577671
ֻ֤ʹ1Σû취Ŷ
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1577671
kevintop 验证码.有没有办法解决啊. 不知道铁道部的用的什么验证机制.
@yystar 目前没有好的办法解决,不过,有一个小技巧,肯定比系统自带的提交功能要方便一些的,自行体会!
能具体说下吗? 对js不是太熟悉。
看了大家的讨论,挺长。首先感谢各位大大的努力 工作,过年了,祝春节快乐。
有几个问题,不知道在zzdhidden公布的1.4版本中修改没有。
第一个,春运过后,12306的登陆压力没那么大,验证码的问题,应该不是啥问题了。
第二个,铁道部对于同账号刷新一个车次问题,有个时间限制,频繁刷新,只是几分钟后返回个结果,看到票之后,也可能被别人定走了,不知道1.4中设定天数循环后这个问题能否解决。
第三个,提交订单时不知道验证码报错能否解决。
提个建议:ie下面有票的时候能否也用音乐提醒?现在是系统提示,不知道在代码中什么地方改,学习下。。1.4版本已经挺完善,希望继续努力,我的联系方式qq100958888。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
怎么可以这么说呢,在之前,那个脚本已经非常完善了,要更新也是该bug的问题,今天凌晨铁道部改了验证码机制,说明需求改了吗。大大们也是要有时间,也需要时间来修改吗!你这样说就是大大们订到了票,就不管他人了,如果这样人家也不会放出这个脚本出来。你要有气,就往铁道部撒。