当前位置:   article > 正文

JAVA版12306订票代码分享_12306抢票java

12306抢票java

注意:

1.实现了从登陆到查询出票的所有过程

2.代码简单,但功能全在,具体的查询信息条件没有做,例子里面是明天的北京到上海的车票有余票的

3.代码仅供学习,对了解httpClient,http+ssl协议有些小小的帮助。

4.运行代码,需要修改四个变量myStore,codeImg,loginUserName,loginPassWord


先上代码

  1. /**
  2. * @Title: GetCodeImg.java
  3. * @Package com.renfy.test
  4. * @Description: TODO
  5. * @author renfy
  6. * @date 2013-7-24 下午04:59:58
  7. * @version V1.0
  8. */
  9. package com.renfy.ssl.ticket;
  10. import java.io.BufferedInputStream;
  11. import java.io.BufferedOutputStream;
  12. import java.io.BufferedReader;
  13. import java.io.File;
  14. import java.io.FileInputStream;
  15. import java.io.FileOutputStream;
  16. import java.io.InputStream;
  17. import java.io.InputStreamReader;
  18. import java.security.KeyStore;
  19. import java.text.SimpleDateFormat;
  20. import java.util.ArrayList;
  21. import java.util.Date;
  22. import java.util.List;
  23. import java.util.Scanner;
  24. import org.apache.http.Consts;
  25. import org.apache.http.Header;
  26. import org.apache.http.HttpResponse;
  27. import org.apache.http.NameValuePair;
  28. import org.apache.http.client.HttpClient;
  29. import org.apache.http.client.entity.GzipDecompressingEntity;
  30. import org.apache.http.client.entity.UrlEncodedFormEntity;
  31. import org.apache.http.client.methods.HttpGet;
  32. import org.apache.http.client.methods.HttpPost;
  33. import org.apache.http.conn.scheme.Scheme;
  34. import org.apache.http.conn.ssl.SSLSocketFactory;
  35. import org.apache.http.impl.client.DefaultHttpClient;
  36. import org.apache.http.message.BasicNameValuePair;
  37. /**
  38. * @ClassName GetCodeImg
  39. * @Description TODO
  40. * @author renfy
  41. * @date 2013-7-24 下午04:59:58
  42. *
  43. */
  44. public class TicketHunter {
  45. private static final String myStore = "F:/FUN/ticket/t1547";//store文件
  46. private static final String codeImg = "F:/FUN/ticket/chkcode/1.png";//登陆验证码生成文件
  47. private static final String loginUserName = "XXXXXXXXXX@126.com";//12306账号
  48. private static final String loginPassWord = "**********";//12306密码
  49. public static void main(String[] args) throws Exception {
  50. //创建HttpClient对象
  51. HttpClient httpclient = zeroGoal();
  52. //获得sessionId
  53. oneGoal(httpclient);
  54. //获得验证码
  55. twoGoal(httpclient);
  56. //获得登陆随机数
  57. String threeResult = threeGoal(httpclient);
  58. //登陆
  59. fourGoal(httpclient,threeResult);
  60. //查询车票
  61. fiveGoal(httpclient);
  62. }
  63. /**
  64. * @Title: fiveGoal
  65. * @Description: TODO
  66. * @author renfy
  67. * @date 2013-7-25 上午11:59:09
  68. * @param @param httpclient
  69. *
  70. */
  71. private static List<String> fiveGoal(HttpClient httpclient) throws Exception{
  72. long times = new Date().getTime() + 1l * 24 * 60 * 60 * 1000;
  73. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  74. String trainDate = "2013-09-11";//查询的火车票时间
  75. trainDate = sdf.format(new Date(times));
  76. System.out.println("查询的火车票日期:" + trainDate);
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/632085
推荐阅读
相关标签
  

闽ICP备14008679号