private static void HasTask(TrainSeat train, string data, Seat seat) { if (ShowMessage != null) { ShowMessage(null, new List <Message>() { new Message(string.Format("{0},{1},{2}有票", train.ToString(), data, seat.Name), Color.Yellow) }); MessageBox.Show(Program.mainForm, "有票啦。。。。" + seat.Name); ThreadPool.QueueUserWorkItem((m) => { SpeechSynthesizer synthesizer = new SpeechSynthesizer(); PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("买到票啦,我能回家啦!"); synthesizer.SpeakAsync(promptBuilder); }); } }
private static void HasTask(TrainSeat train, string data, Seat seat) { if (ShowMessage != null) { ShowMessage(null, new List<Message>() { new Message(string.Format("{0},{1},{2}有票", train.ToString(), data, seat.Name), Color.Yellow) }); MessageBox.Show(Program.mainForm, "有票啦。。。。" + seat.Name); ThreadPool.QueueUserWorkItem((m) => { SpeechSynthesizer synthesizer = new SpeechSynthesizer(); PromptBuilder promptBuilder = new PromptBuilder(); promptBuilder.AppendText("买到票啦,我能回家啦!"); synthesizer.SpeakAsync(promptBuilder); }); } }
/// <summary> /// 获取座位信息 /// </summary> /// <param name="date"></param> /// <param name="startStationCode"></param> /// <param name="endStationCode"></param> /// <param name="trainNo"></param> /// <param name="timeout"></param> /// <param name="userAgent"></param> /// <param name="cookie"></param> /// <returns></returns> public static TrainSeat CreateTask(TrainSeat trainSeat, int? timeout = null, string userAgent = null, CookieCollection cookie = null) { Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("station_train_code", trainSeat.station_train_code); dic.Add("train_date", trainSeat.train_date); dic.Add("seattype_num", trainSeat.seattype_num); dic.Add("from_station_telecode", trainSeat.from_station_telecode); dic.Add("to_station_telecode", trainSeat.to_station_telecode); dic.Add("include_student", trainSeat.include_student); dic.Add("from_station_telecode_name", trainSeat.from_station_telecode_name); dic.Add("to_station_telecode_name", trainSeat.to_station_telecode_name); dic.Add("round_train_date", trainSeat.round_train_date); dic.Add("round_start_time_str", trainSeat.round_start_time_str); dic.Add("single_round_type", trainSeat.single_round_type); dic.Add("train_pass_type", trainSeat.train_pass_type); dic.Add("train_class_arr", trainSeat.train_class_arr); dic.Add("start_time_str", trainSeat.start_time_str); dic.Add("lishi", trainSeat.lishi); dic.Add("train_start_time", trainSeat.train_start_time); dic.Add("trainno4", trainSeat.trainno4); dic.Add("arrive_time", trainSeat.arrive_time); dic.Add("from_station_name", trainSeat.from_station_name); dic.Add("to_station_name", trainSeat.to_station_name); dic.Add("from_station_no", trainSeat.from_station_no); dic.Add("to_station_no", trainSeat.to_station_no); dic.Add("ypInfoDetail", trainSeat.ypInfoDetail); dic.Add("mmStr", trainSeat.mmStr); dic.Add("locationCode", trainSeat.locationCode); string str = ""; try { var response = HttpHelper.CreatePostHttpResponse(UrlCreateTask1_PostData, dic, timeout, userAgent, UTF8Encoding.UTF8, cookie ?? Cookies , "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init"); cookies.Add(response.Cookies); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { str = reader.ReadToEnd(); } } catch (Exception) { return null; } try { var response = HttpHelper.CreateGetHttpResponse(UrlCreateTask2_Get, timeout, userAgent, cookie ?? Cookies , "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init"); cookies.Add(response.Cookies); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { str = reader.ReadToEnd(); } } catch (Exception) { return null; } return null; // return trainSeat; }
/// <summary> /// 获取座位信息 /// </summary> /// <param name="date"></param> /// <param name="startStationCode"></param> /// <param name="endStationCode"></param> /// <param name="trainNo"></param> /// <param name="timeout"></param> /// <param name="userAgent"></param> /// <param name="cookie"></param> /// <returns></returns> public static TrainSeat CreateTask(TrainSeat trainSeat, int?timeout = null, string userAgent = null, CookieCollection cookie = null) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("station_train_code", trainSeat.station_train_code); dic.Add("train_date", trainSeat.train_date); dic.Add("seattype_num", trainSeat.seattype_num); dic.Add("from_station_telecode", trainSeat.from_station_telecode); dic.Add("to_station_telecode", trainSeat.to_station_telecode); dic.Add("include_student", trainSeat.include_student); dic.Add("from_station_telecode_name", trainSeat.from_station_telecode_name); dic.Add("to_station_telecode_name", trainSeat.to_station_telecode_name); dic.Add("round_train_date", trainSeat.round_train_date); dic.Add("round_start_time_str", trainSeat.round_start_time_str); dic.Add("single_round_type", trainSeat.single_round_type); dic.Add("train_pass_type", trainSeat.train_pass_type); dic.Add("train_class_arr", trainSeat.train_class_arr); dic.Add("start_time_str", trainSeat.start_time_str); dic.Add("lishi", trainSeat.lishi); dic.Add("train_start_time", trainSeat.train_start_time); dic.Add("trainno4", trainSeat.trainno4); dic.Add("arrive_time", trainSeat.arrive_time); dic.Add("from_station_name", trainSeat.from_station_name); dic.Add("to_station_name", trainSeat.to_station_name); dic.Add("from_station_no", trainSeat.from_station_no); dic.Add("to_station_no", trainSeat.to_station_no); dic.Add("ypInfoDetail", trainSeat.ypInfoDetail); dic.Add("mmStr", trainSeat.mmStr); dic.Add("locationCode", trainSeat.locationCode); string str = ""; try { var response = HttpHelper.CreatePostHttpResponse(UrlCreateTask1_PostData, dic, timeout, userAgent, UTF8Encoding.UTF8, cookie ?? Cookies , "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init"); cookies.Add(response.Cookies); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { str = reader.ReadToEnd(); } } catch (Exception) { return(null); } try { var response = HttpHelper.CreateGetHttpResponse(UrlCreateTask2_Get, timeout, userAgent, cookie ?? Cookies , "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=init"); cookies.Add(response.Cookies); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { str = reader.ReadToEnd(); } } catch (Exception) { return(null); } return(null); // return trainSeat; }