public void GetTickCount() { // 获取剩余票数 string s = TickCute.GetRegeditInfo(MachineCode); TickCount = TickCute.GetUseTick(MachineCode, s, false); SetTickText(); btnDuihuan.Enabled = true; btn_luntan.Enabled = true; if (TickCount > 0) { //登录ToolStripMenuItem.Enabled = true; int hour = DateTime.Now.Hour; if (hour > 7 && hour < 23) { 登录ToolStripMenuItem.Enabled = true; labUserInfo.ForeColor = Color.Green; labUserInfo.Text = "请登录!"; } else { 登录ToolStripMenuItem.Enabled = true; labUserInfo.ForeColor = Color.Red; labUserInfo.Text = "晚上23点后到凌晨7点前\n是12306系统维护时间,将无法购票!"; } } else { labUserInfo.ForeColor = Color.Red; labUserInfo.Text = "剩余购票卷数量不足,请购买!"; } }
private void button2_Click(object sender, EventArgs e) { string code = textBox1.Text; if (String.IsNullOrEmpty(code)) { label1.Text = "请输入兑换码!"; } else { // 先判断是否存在 List <String> list = TickCute.readHistoryStr(); String key = "", codeKey = "";// MyEncrypt.EncryptA(code); int count = 0; for (int i = 0; i < list.Count; i++) { key = list[i]; codeKey = MyEncrypt.DecryptB(key); if (code.Equals(codeKey)) { count++; } } if (count == 0) { count = TickCute.GetUseTick(Form1.MachineCode, code, true); if (count <= 0 && count > 50) { label1.Text = "您输入的兑换码无效!"; } else { TickCute.ChangeTickCount(count); TickCute.WriteHistoryToFile(code); this.Dispose(); } } else { label1.Text = "您输入的兑换码无效!"; } } }
private void button1_Click(object sender, EventArgs e) { String pwd = pwd_text.Text; String jqm = jiqima.Text; String zh = zh_text.Text; pwd = MyEncrypt.GetMd5_16(pwd, true); pwd = MyEncrypt.GetMD5(pwd); if (pwd.Equals(sap)) { errorInfo.ForeColor = Color.Green; errorInfo.Text = "生成成功!"; String text = TickCute.CreateKey(jqm, zh); textBox1.Text = text; Clipboard.SetData(DataFormats.Text, text); } else { errorInfo.ForeColor = Color.Red; errorInfo.Text = "错误!"; } }
public Form1() { InitializeComponent(); 登录ToolStripMenuItem.Enabled = false; Control.CheckForIllegalCrossThreadCalls = false; richTextBox1.BackColor = Color.OliveDrab; richTextBox1.ForeColor = Color.White; Console.WriteLine("Environment.CurrentDirectory==" + Environment.CurrentDirectory); Trains.TrainsChanged += Trains_TrainsChanged; Seat.SelectSeatsChange += TrainSeat_SelectSeatsChange; Thread12306.ShowMessage += Thread12306_Message; TranTime.TimeChanged += TranTime_TimeChanged; Thread12306.ThreadClosed += Thread12306_ThreadClosed; ThreadPool.QueueUserWorkItem((n) => { Thread.Sleep(100); // 获取机器码 string info = MyEncrypt.GetInfo(); MachineCode = MyEncrypt.GetMd5_16(info, false); this.tstbJqm.Text = "机器码:" + MachineCode; //GetTickCount(); }); ThreadPool.QueueUserWorkItem((a) => { Thread.Sleep(2500); if (!String.IsNullOrEmpty(MachineCode)) { GetTickCount(); } }); ThreadPool.QueueUserWorkItem((m) => { ShowMessage("正在初始化...", false); _12306Class.GetMainPage(cookie: new CookieCollection()); ShowMessage("完成"); // 先获取车站信息 //var v = Stations.List; TickCute.CreateDir(); }); ThreadPool.QueueUserWorkItem((m) => { // 初始化配置 ConfigStore.InitConfig(); SetAutoBaojing(ConfigStore.isAutoBaojing); SetAutoWriterVerify(ConfigStore.isAutoWriterVerify); setFailedTimes(ConfigStore.failedTimes); button1.Enabled = ConfigStore.islocalhost; }); ThreadPool.QueueUserWorkItem((a) => { Thread.Sleep(3500); String dateStr = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second; String s = "我的机器码:" + Form1.MachineCode + "\n"; s += "我使用了【隐心抢票助手】:" + dateStr + "\n"; CommonUtil.SendEMail("*****@*****.**", Form1.MachineCode, "*****@*****.**", "隐心", "使用【隐心抢票助手】报告", s, "", "smtp.163.com", "*****@*****.**", "sendemail"); }); }
public static CreateResponse GetTask(Train train, string date, SeatsType seat, List <Contact> selectContactList) { string seatType = ""; switch (seat) { case SeatsType.商务座: seatType = "9"; break; case SeatsType.特等座: seatType = "P"; break; case SeatsType.一等座: seatType = "M"; break; case SeatsType.二等座: seatType = "O"; break; case SeatsType.高级软卧: seatType = "5"; break; case SeatsType.软卧: seatType = "4"; break; case SeatsType.硬卧: seatType = "3"; break; case SeatsType.软座: seatType = "2"; break; case SeatsType.硬座: seatType = "1"; break; case SeatsType.无座: seatType = "1"; break; } StringBuilder passengerTicketStr = new StringBuilder(); StringBuilder oldPassengerStr = new StringBuilder(); foreach (Contact contact in selectContactList) { passengerTicketStr.AppendFormat("{0},0,1,{1},{2},{3},{4},N_", seatType, contact.Name, contact.IdTypeCode, contact.IdNo, contact.Mobile); oldPassengerStr.AppendFormat("{1},{2},{3},1_", seatType, contact.Name, contact.IdTypeCode, contact.IdNo, contact.Mobile); } Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("secretStr", train.Id); dic.Add("train_date", date); dic.Add("tour_flag", "dc"); dic.Add("purpose_codes", "ADULT"); dic.Add("query_from_station_name", From.Name); dic.Add("query_to_station_name", To.Name); dic.Add("", ""); dic.Add("cancel_flag", "2"); dic.Add("bed_level_order_num", "000000000000000000000000000000"); dic.Add("passengerTicketStr", passengerTicketStr.ToString().TrimEnd('_')); dic.Add("oldPassengerStr", oldPassengerStr.ToString()); var codeResquest = new HttpHelper2().Post(GetTask_1_GetToken, dic, Encoding.UTF8, Encoding.UTF8, Referer: "https://kyfw.12306.cn/otn/leftTicket/init", cookies: Cookies , headers: new Dictionary <string, string>() { { "Origin", "https://kyfw.12306.cn" } }); if (codeResquest == null) { return(new CreateResponse() { IsCreate = false, Message = "Errorl" }); } var serializer = new JavaScriptSerializer(); serializer.RegisterConverters(new[] { new DynamicJsonConverter() }); dynamic data = serializer.Deserialize <object>(codeResquest); if (data.status == null || !data.status || data.data == null || data.data.result == null) { try { return(new CreateResponse() { IsCreate = false, Message = data.messages != null ? data.messages[0] ?? "未知错误" : "未知错误" }); } catch (Exception) { return(new CreateResponse() { IsCreate = false, Message = data.errMsg ?? "未知错误" }); } } //Q6#BA6C4F23E49E84F96A07B8ECA37A9FF350DAD2E2F484AD96F61C2046#O007450669M0099501499019950025#1 Token token = new Token(); string[] tokens = data.data.result.Split('#');; token.Q = tokens[0]; token.LongToken = tokens[1]; token.ShortToken = tokens[2]; dic.Clear(); dic.Add("train_date", (Convert.ToDateTime(date).ToString("ddd MMM dd yyy ", DateTimeFormatInfo.InvariantInfo) + DateTime.Now.ToString("HH:mm:ss").Replace(":", "%3A") + " GMT%2B0800 (China Standard Time)").Replace(' ', '+')); dic.Add("train_no", train.TrainNo); dic.Add("stationTrainCode", train.StationTrainCode); dic.Add("seatType", seatType); dic.Add("fromStationTelecode", train.from_station_telecode); dic.Add("toStationTelecode", train.end_station_telecode); dic.Add("leftTicket", token.ShortToken); dic.Add("purpose_codes", "ADULT"); dic.Add("_json_att", ""); CookieCollection cookiesTemp = new CookieCollection(); cookiesTemp.Add(Cookies); cookiesTemp.Add(new Cookie("_jc_save_fromStation", escape(From.Name) + "%2C" + From.Code, "/otn") { Domain = "kyfw.12306.cn" }); cookiesTemp.Add(new Cookie("_jc_save_toStation", escape(To.Name) + "%2C" + To.Code, "/otn") { Domain = "kyfw.12306.cn" }); cookiesTemp.Add(new Cookie("_jc_save_fromDate", date, "/otn") { Domain = "kyfw.12306.cn" }); cookiesTemp.Add(new Cookie("_jc_save_toDate", Convert.ToDateTime(date).AddDays(15).ToString("yyyy-MM-dd"), "/otn") { Domain = "kyfw.12306.cn" }); cookiesTemp.Add(new Cookie("_jc_save_wfdc_flag", "dc", "/otn") { Domain = "kyfw.12306.cn" }); codeResquest = new HttpHelper2().Post(GetTask_2_GetQueueCount, dic, Encoding.UTF8, Encoding.UTF8, cookies: cookiesTemp, Referer: "https://kyfw.12306.cn/otn/leftTicket/init" , headers: new Dictionary <string, string>() { { "Origin", "https://kyfw.12306.cn" }, { "X-Requested-With", "XMLHttpRequest" } }); serializer = new JavaScriptSerializer(); serializer.RegisterConverters(new[] { new DynamicJsonConverter() }); data = serializer.Deserialize <object>(codeResquest); if (data.status == null || !data.status || data.data == null || data.data.ticket == null) { return(new CreateResponse() { IsCreate = false, Message = data.messages != null ? data.messages[0] ?? "未知错误" : "未知错误" }); } token.ticket = data.data.ticket; string Code = ""; try { do { var response = HttpHelper.CreateGetHttpResponse(GetTask_3_Image + new Random().NextDouble().ToString(), null, "https://kyfw.12306.cn/otn/leftTicket/init", Cookies); Stream resStream = response.GetResponseStream(); //得到验证码数据流 Bitmap bmp = new Bitmap(resStream); //初始化Bitmap图片 new Music(2).Play(); ImageFrom.GetImageFrom.Show(bmp); Code = ImageFrom.GetImageFrom.Code; } while (Code.Length != 4 && Program.mainForm.GetRunStatus()); } catch (Exception) { return(new CreateResponse() { IsCreate = false, Message = data.data.errMsg ?? "未知错误" }); } //dic.Clear(); //dic.Add("randCode", Code); //dic.Add("rand", "sjrand"); //dic.Add("_json_att", ""); //codeResquest = new HttpHelper2().Post("https://kyfw.12306.cn/otn/passcodeNew/checkRandCodeAnsyn", // dic, Encoding.UTF8, Encoding.UTF8, Referer: "https://kyfw.12306.cn/otn/leftTicket/init", cookies: cookiesTemp // , headers: // new Dictionary<string, string>() // { // {"Origin", "https://kyfw.12306.cn"}, // {"X-Requested-With", "XMLHttpRequest"} // }); dic.Clear(); dic.Add("passengerTicketStr", System.Web.HttpUtility.UrlEncode((passengerTicketStr.ToString().TrimEnd('_'))).ToUpper()); dic.Add("oldPassengerStr", System.Web.HttpUtility.UrlEncode(oldPassengerStr.ToString()).ToUpper()); dic.Add("randCode", Code); dic.Add("purpose_codes", "ADULT"); dic.Add("key_check_isChange", token.LongToken); dic.Add("leftTicketStr", token.ShortToken); dic.Add("train_location", token.Q); dic.Add("_json_att", ""); cookiesTemp = new CookieCollection(); cookiesTemp.Add(Cookies); cookiesTemp.Add(new Cookie("_jc_save_fromStation", escape(From.Name) + "%2C" + From.Code, "/otn") { Domain = "kyfw.12306.cn" }); cookiesTemp.Add(new Cookie("_jc_save_toStation", escape(To.Name) + "%2C" + To.Code, "/otn") { Domain = "kyfw.12306.cn" }); cookiesTemp.Add(new Cookie("_jc_save_fromDate", date, "/otn") { Domain = "kyfw.12306.cn" }); cookiesTemp.Add(new Cookie("_jc_save_toDate", Convert.ToDateTime(date).AddDays(15).ToString("yyyy-MM-dd"), "/otn") { Domain = "kyfw.12306.cn" }); cookiesTemp.Add(new Cookie("_jc_save_wfdc_flag", "dc", "/otn") { Domain = "kyfw.12306.cn" }); codeResquest = new HttpHelper2().Post(GetTask_4_SubmitStatus, dic, Encoding.UTF8, Encoding.UTF8, Referer: "https://kyfw.12306.cn/otn/leftTicket/init", cookies: cookiesTemp , headers: new Dictionary <string, string>() { { "Origin", "https://kyfw.12306.cn" }, { "X-Requested-With", "XMLHttpRequest" } }); if (codeResquest == null) { return(new CreateResponse() { IsCreate = false, Message = "Errorl" }); } serializer = new JavaScriptSerializer(); serializer.RegisterConverters(new[] { new DynamicJsonConverter() }); data = serializer.Deserialize <object>(codeResquest); if (data.status == null || !data.status || data.data == null || data.data.submitStatus == null) { try { return(new CreateResponse() { IsCreate = false, Message = data.messages != null ? data.messages[0] ?? "未知错误" : "未知错误" }); } catch (Exception) { return(new CreateResponse() { IsCreate = false, Message = data.data.errMsg ?? "未知错误" }); } } else if (data.data != null && data.data.submitStatus != null) { if (data.data.submitStatus) { TickCute.ChangeTickCount(-1); new Music(1).Play(); Program.mainForm.SetLinkLabelText("订票成功!登录12306查看!<-"); return(new CreateResponse() { IsCreate = true, Message = "订票成功!" }); } else { return(new CreateResponse() { IsCreate = false, Message = "订票失败!" }); } } return(new CreateResponse() { IsCreate = false, Message = data.messages != null ? data.messages[0] ?? "未知错误" : "未知错误" }); //else if (data.messages.Count <=0) //{ // return new LoginResponse() { IsLogined = true, Message = "", type = ErrorType.None, LoginName = userName }; //} }