找回密码
 注册
搜索
热搜: 超星 读书 找书
查看: 847|回复: 12

[【心情日记】] 妙啊!网友开发出了《12306网站自动登录代码》!!!

[复制链接]
发表于 2012-1-9 19:43:57 | 显示全部楼层 |阅读模式
[b]妙啊!网友开发出了《12306网站自动登录代码》!!!

可惜啊,我不知怎样用,园地高手多,那位高人解读一下?急用!


========================================

12306 Auto Login
  
  https://gist.github.com/1570973/ ... 41e59e999807befd8aa
  
  
  /*
   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
  
   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*
  // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
  // ==/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 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 + \"&loginUser.user_name=\" + $(\"#UserName\").val() + \"&user.password=\" + $(\"#password\").val() + \"&randCode=\" + $(\"#randCode\").val();
   $.ajax({
   type: \"OST\",
   url: submitUrl,
   cache: false,
   async: false,
   success: function(msg){
   if (msg.indexOf(’请输入正确的验证码’) > -1) {
   alert(’请输入正确的验证码!’);
   };
   if (msg.indexOf(’当前访问用户过多’) > -1) {
   reLogin();
   }
   else {
   $(’#reloginNum’).html(’登录成功,请刷新!’);
   location.replace(queryurl);
   };
   },
   error: function(msg){
   reLogin();
   },
   beforeSend: function(XHR){
   //alert(\"Data Saved: \" + XHR);
   }
   });
   }
  
   function reLogin(){
   var currNum = $(’#reloginNum’).html();
   $(’#reloginNum’).html(parseInt(currNum) + 1);
   setTimeout(’submitForm()’, 2000);
   }
   //初始化
   $(\"body\").prepend(\"<div style=’white-space:nowrap;’>重试次数:<div id=’reloginNum’ >0</div></div>\");
   $(\"#subLink\").after(\"<a href=’#’ id=’autoSubmit’ class=’button_a’ ><span><ins>自动登录</ins> </span> </a>\");
   $(\"#autoSubmit\").live(\"click\", function(){
   alert(’开始尝试登录,请耐心等待!’);
   submitForm();
   });
   alert(’如果使用自动登录功能,请输入用户名、密码及验证码后,点击自动登录,系统会尝试登录,直至成功!’);
  }, true);
回复

使用道具 举报

发表于 2012-1-9 20:49:44 | 显示全部楼层
引用第0楼weist123于2012-01-09 19:43发表的 妙啊!网友开发出了《12306网站自动登录代码》!!! :
[b]妙啊!网友开发出了《12306网站自动登录代码》!!!

可惜啊,我不知怎样用,园地高手多,那位高人解读一下?急用!


========================================

  /*
   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
  
   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*
  // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
  // ==/UserScript==
  function withjQuery(callback, safe){
   if(typeof(jQuery) == "undefined") {//当前页jQuery变量如果不存在
   var script = document.createElement("script"); //插入jQuery.js
   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 url = "https://dynamic.12306.cn/otsweb/loginAction.do?method=login";
   var queryurl = "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init";
   function submitForm(){
//定义AJAX提交的变量
   var submitUrl = url + "&loginUser.user_name=" + $("#UserName").val() + "&user.password=" + $("#password").val() + "&randCode=" + $("#randCode").val();
   $.ajax({
//AJAX闭包
   type: "OST",
   url: submitUrl,
   cache: false,
   async: false,
   success: function(msg){//有返回值,则分析返回值内容
   if (msg.indexOf(’请输入正确的验证码’) > -1) {//如果返回值内容包含’请输入正确的验证码’字符串
   alert(’请输入正确的验证码!’);//弹出要求输入验证码的对话框
   };
   if (msg.indexOf(’当前访问用户过多’) > -1) {{//如果返回值内容包’当前访问用户过多’字符串

   reLogin();//执行重新登录函数
   }
   else {//如果不包含以上内容,则在id=’reloginNum’的表中插入 登录成功提示,并自动刷新当前页,以使页面变为用户登录状态
   $(’#reloginNum’).html(’登录成功,请刷新!’);
   location.replace(queryurl);
   };
   },
   error: function(msg){ //如果没有返回值或者返回非200(如500错误),执行重新登录函数
   reLogin();
   },
   beforeSend: function(XHR){//AJAX提交前数据处理,已注销
   //alert("Data Saved: " + XHR);
   }
   });
   }
  
   function reLogin(){//重新登录函数
//将id=reloginNum的div中显示的重新登录次数+1,并重新存储,并在2000毫秒(2秒)后执行’submitForm()函数
   var currNum = $(’#reloginNum’).html();
   $(’#reloginNum’).html(parseInt(currNum) + 1);
   setTimeout(’submitForm()’, 2000);
   }
   //初始化
   $("body").prepend("<div style=’white-space:nowrap;’>重试次数:<div id=’reloginNum’ >0</div></div>");
   $("#subLink").after("<a href=’#’ id=’autoSubmit’ class=’button_a’ ><span><ins>自动登录</ins> </span> </a>");
   $("#autoSubmit").live("click", function(){
   alert(’开始尝试登录,请耐心等待!’);
   submitForm();
   });
   alert(’如果使用自动登录功能,请输入用户名、密码及验证码后,点击自动登录,系统会尝试登录,直至成功!’);
  }, true);


.......
此内容很简单。我们再IE中登录的时候,每次错误都会刷新验证码,此处由于是脚本执行,页面中的验证码并没有得到刷新,所以只要sessio不失效,就一直使用第一次显示的验证码值向服务器发出请求,而不是每次都用新的验证码。
回复

使用道具 举报

发表于 2012-1-9 21:02:20 | 显示全部楼层
你这个只是自动登录程序,还有自动刷票程序。等页面上没有票的时候,每隔2秒向服务器提交一次信息。一旦出现票源,则停止刷票,高亮显示出现车次,并播放提醒音乐,及时提醒你票来了。
可惜没有自动订票程序,之前看过一个修改页面源码等票的程序,一旦有票,则自动提交生成订单。
回复

使用道具 举报

发表于 2012-1-10 08:49:50 | 显示全部楼层
现在查余额的页面都改成
七+?=11
这种了
回复

使用道具 举报

 楼主| 发表于 2012-1-10 10:41:42 | 显示全部楼层
哈哈,2楼的自动刷票好啊,期待出台!
回复

使用道具 举报

发表于 2012-1-10 10:57:15 | 显示全部楼层
引用第1楼hoowho于2012-01-09 20:49发表的 :

此内容很简单。我们再IE中登录的时候,每次错误都会刷新验证码,此处由于是脚本执行,页面中的验证码并没有得到刷新,所以只要sessio不失效,就一直使用第一次显示的验证码值向服务器发出请求,而不是每次都用新的验证码。
高人
回复

使用道具 举报

发表于 2012-1-10 13:10:12 | 显示全部楼层
引用第5楼what于2012-01-10 10:57发表的 :

高人

俺不是高手,俺宿舍十多位兄弟姐妹等着回家呢

Chrome 适用

https://github.com/zzdhidden/12306

支持自动登录、自动刷票,自动提交订单。

回复

使用道具 举报

发表于 2012-1-10 15:13:05 | 显示全部楼层
太好了,安装试一下
回复

使用道具 举报

发表于 2012-1-10 16:35:58 | 显示全部楼层
回复

使用道具 举报

发表于 2012-1-10 18:40:49 | 显示全部楼层
等待小白,不会是盗网银的吧。
回复

使用道具 举报

发表于 2012-1-10 19:18:07 | 显示全部楼层
引用第6楼hoowho于2012-01-10 13:10发表的 :


俺不是高手,俺宿舍十多位兄弟姐妹等着回家呢

Chrome 适用
.......

你们宿舍真幸福,有兄弟有姐妹
回复

使用道具 举报

发表于 2012-1-10 19:23:27 | 显示全部楼层
引用第10楼铁道于2012-01-10 19:18发表的 :


你们宿舍真幸福,有兄弟有姐妹
同样的疑惑
回复

使用道具 举报

发表于 2012-1-10 22:11:31 | 显示全部楼层
网络支付太慢,查到有票后还是电话订票的好。本人在成都成功在售票开始前3分钟内订到两张卧铺,过几天就回家过年了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|网上读书园地

GMT+8, 2024-9-27 15:28 , Processed in 0.100917 second(s), 4 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表