private void button1_Click(object sender, EventArgs e) { //Dictionary<string, string> postdic = new Dictionary<string, string>(); List<string> keys = new List<string>(); List<string> values = new List<string>(); SendOrderReqParams postdic = new SendOrderReqParams(keys, values); postdic.Add("org.apache.struts.taglib.html.TOKEN", token); postdic.Add("leftTicketStr", leftTicketStr); postdic.Add("textfield", "中文或拼音首字母");//搜索乘客框value for (int j = 0; j < this.checkedListBox1.Items.Count; j++) { if (checkedListBox1.GetItemChecked(j)) { postdic.Add("checkbox" + j.ToString(), j.ToString()); } } postdic.Add("orderRequest.train_date", queryTicketParams["orderRequest.train_date"]); postdic.Add("orderRequest.train_no", orderParams["trainno4"]); postdic.Add("orderRequest.station_train_code", orderParams["station_train_code"]); postdic.Add("orderRequest.from_station_telecode", queryTicketParams["orderRequest.from_station_telecode"]); postdic.Add("orderRequest.to_station_telecode", queryTicketParams["orderRequest.to_station_telecode"]); postdic.Add("orderRequest.seat_type_code", string.Empty); postdic.Add("orderRequest.ticket_type_order_num", string.Empty); postdic.Add("orderRequest.bed_level_order_num", "000000000000000000000000000000"); postdic.Add("orderRequest.start_time", orderParams["train_start_time"]); postdic.Add("orderRequest.end_time", orderParams["arrive_time"]); postdic.Add("orderRequest.from_station_name", orderParams["from_station_name"]); postdic.Add("orderRequest.to_station_name", orderParams["to_station_name"]); postdic.Add("orderRequest.cancel_flag", "1"); postdic.Add("orderRequest.id_mode", "Y"); int passengerCounts = 1; for (int i = 0; i < this.dataGridView1.Rows.Count; i++) { if (i == this.dataGridView1.Rows.Count - 1) { continue; } Dictionary<string, string> passengetDic = new Dictionary<string, string>(); passengetDic.Add(string.Format("passenger_{0}_seat", passengerCounts), "M"); passengetDic.Add(string.Format("passenger_{0}_ticket", passengerCounts), "1"); passengetDic.Add(string.Format("passenger_{0}_name", passengerCounts), this.dataGridView1.Rows[i].Cells[3].Value.ToString().Trim()); foreach (string key in cardTypeDic.Keys) { if (cardTypeDic[key] == this.dataGridView1.Rows[i].Cells[4].Value.ToString()) { passengetDic.Add(string.Format("passenger_{0}_cardtype", passengerCounts), key); } } passengetDic.Add(string.Format("passenger_{0}_cardno", passengerCounts), this.dataGridView1.Rows[i].Cells[5].Value.ToString().Trim()); passengetDic.Add(string.Format("passenger_{0}_mobileno", passengerCounts), this.dataGridView1.Rows[i].Cells[6].Value.ToString().Trim()); string passengerTickets = string.Format("M,0,1,{0},{1},{2},{3},Y", passengetDic[string.Format("passenger_{0}_name", passengerCounts)] , passengetDic[string.Format("passenger_{0}_cardtype", passengerCounts)], passengetDic[string.Format("passenger_{0}_cardno", passengerCounts)], passengetDic[string.Format("passenger_{0}_mobileno", passengerCounts)]); string oldPassengers = passengetDic[string.Format("passenger_{0}_name", passengerCounts)] + "," + passengetDic[string.Format("passenger_{0}_cardtype", passengerCounts)] + "," + passengetDic[string.Format("passenger_{0}_cardno", passengerCounts)]; postdic.Add("passengerTickets", passengerTickets); postdic.Add("oldPassengers", oldPassengers); foreach (string key in passengetDic.Keys) { postdic.Add(key, passengetDic[key]); } postdic.Add("checkbox9", "Y"); passengerCounts++; } for (int k = 0; k < 5 - passengerCounts + 1; k++) { postdic.Add("oldPassengers", string.Empty); postdic.Add("checkbox9", "Y"); } postdic.Add("randCode", this.textBox1.Text.Trim()); postdic.Add("orderRequest.reserve_flag", "A"); postdic.Add("tFlag", "dc"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < keys.Count; i++) { sb.AppendFormat("{0}={1}&", keys[i], values[i]); } sb.Remove(sb.ToString().LastIndexOf("&"), 1); HttpPost post = new HttpPost("https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=checkOrderInfo&rand=" + this.textBox1.Text + "", sb.ToString()); post.req.CookieContainer.Add(reqCookies); string resultstr = post.SendReqReturnResponseString(); if (!string.IsNullOrEmpty(resultstr)) { JObject json1 = JObject.Parse(resultstr); if (json1["msg"] != null && !string.IsNullOrEmpty(json1["msg"].Value<string>())) { MessageBox.Show(json1["msg"].Value<string>()); return; } } HttpGet ticketLeftGet = new HttpGet(string.Format("https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=getQueueCount&train_date={0}&train_no={1}&station={2}&seat={3}&from={4}&to={5}&ticket={6}", queryTicketParams["orderRequest.train_date"], orderParams["trainno4"], orderParams["station_train_code"], "M", queryTicketParams["orderRequest.from_station_telecode"], queryTicketParams["orderRequest.to_station_telecode"], leftTicketStr)); ticketLeftGet.req.CookieContainer.Add(reqCookies); string ticketLeftGetResult = ticketLeftGet.SendReqReturnResponseString(); HttpPost orderpost = new HttpPost("https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=confirmSingleForQueue", sb.ToString().Replace("&tFlag=dc", string.Empty)); orderpost.req.CookieContainer.Add(reqCookies); string orderpostresult = orderpost.SendReqReturnResponseString(); }
private void button1_Click(object sender, EventArgs e) { //Dictionary<string, string> postdic = new Dictionary<string, string>(); List <string> keys = new List <string>(); List <string> values = new List <string>(); SendOrderReqParams postdic = new SendOrderReqParams(keys, values); postdic.Add("org.apache.struts.taglib.html.TOKEN", token); postdic.Add("leftTicketStr", leftTicketStr); postdic.Add("textfield", "中文或拼音首字母");//搜索乘客框value for (int j = 0; j < this.checkedListBox1.Items.Count; j++) { if (checkedListBox1.GetItemChecked(j)) { postdic.Add("checkbox" + j.ToString(), j.ToString()); } } postdic.Add("orderRequest.train_date", queryTicketParams["orderRequest.train_date"]); postdic.Add("orderRequest.train_no", orderParams["trainno4"]); postdic.Add("orderRequest.station_train_code", orderParams["station_train_code"]); postdic.Add("orderRequest.from_station_telecode", queryTicketParams["orderRequest.from_station_telecode"]); postdic.Add("orderRequest.to_station_telecode", queryTicketParams["orderRequest.to_station_telecode"]); postdic.Add("orderRequest.seat_type_code", string.Empty); postdic.Add("orderRequest.ticket_type_order_num", string.Empty); postdic.Add("orderRequest.bed_level_order_num", "000000000000000000000000000000"); postdic.Add("orderRequest.start_time", orderParams["train_start_time"]); postdic.Add("orderRequest.end_time", orderParams["arrive_time"]); postdic.Add("orderRequest.from_station_name", orderParams["from_station_name"]); postdic.Add("orderRequest.to_station_name", orderParams["to_station_name"]); postdic.Add("orderRequest.cancel_flag", "1"); postdic.Add("orderRequest.id_mode", "Y"); int passengerCounts = 1; for (int i = 0; i < this.dataGridView1.Rows.Count; i++) { if (i == this.dataGridView1.Rows.Count - 1) { continue; } Dictionary <string, string> passengetDic = new Dictionary <string, string>(); passengetDic.Add(string.Format("passenger_{0}_seat", passengerCounts), "M"); passengetDic.Add(string.Format("passenger_{0}_ticket", passengerCounts), "1"); passengetDic.Add(string.Format("passenger_{0}_name", passengerCounts), this.dataGridView1.Rows[i].Cells[3].Value.ToString().Trim()); foreach (string key in cardTypeDic.Keys) { if (cardTypeDic[key] == this.dataGridView1.Rows[i].Cells[4].Value.ToString()) { passengetDic.Add(string.Format("passenger_{0}_cardtype", passengerCounts), key); } } passengetDic.Add(string.Format("passenger_{0}_cardno", passengerCounts), this.dataGridView1.Rows[i].Cells[5].Value.ToString().Trim()); passengetDic.Add(string.Format("passenger_{0}_mobileno", passengerCounts), this.dataGridView1.Rows[i].Cells[6].Value.ToString().Trim()); string passengerTickets = string.Format("M,0,1,{0},{1},{2},{3},Y", passengetDic[string.Format("passenger_{0}_name", passengerCounts)] , passengetDic[string.Format("passenger_{0}_cardtype", passengerCounts)], passengetDic[string.Format("passenger_{0}_cardno", passengerCounts)], passengetDic[string.Format("passenger_{0}_mobileno", passengerCounts)]); string oldPassengers = passengetDic[string.Format("passenger_{0}_name", passengerCounts)] + "," + passengetDic[string.Format("passenger_{0}_cardtype", passengerCounts)] + "," + passengetDic[string.Format("passenger_{0}_cardno", passengerCounts)]; postdic.Add("passengerTickets", passengerTickets); postdic.Add("oldPassengers", oldPassengers); foreach (string key in passengetDic.Keys) { postdic.Add(key, passengetDic[key]); } postdic.Add("checkbox9", "Y"); passengerCounts++; } for (int k = 0; k < 5 - passengerCounts + 1; k++) { postdic.Add("oldPassengers", string.Empty); postdic.Add("checkbox9", "Y"); } postdic.Add("randCode", this.textBox1.Text.Trim()); postdic.Add("orderRequest.reserve_flag", "A"); postdic.Add("tFlag", "dc"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < keys.Count; i++) { sb.AppendFormat("{0}={1}&", keys[i], values[i]); } sb.Remove(sb.ToString().LastIndexOf("&"), 1); HttpPost post = new HttpPost("https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=checkOrderInfo&rand=" + this.textBox1.Text + "", sb.ToString()); post.req.CookieContainer.Add(reqCookies); string resultstr = post.SendReqReturnResponseString(); if (!string.IsNullOrEmpty(resultstr)) { JObject json1 = JObject.Parse(resultstr); if (json1["msg"] != null && !string.IsNullOrEmpty(json1["msg"].Value <string>())) { MessageBox.Show(json1["msg"].Value <string>()); return; } } HttpGet ticketLeftGet = new HttpGet(string.Format("https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=getQueueCount&train_date={0}&train_no={1}&station={2}&seat={3}&from={4}&to={5}&ticket={6}", queryTicketParams["orderRequest.train_date"], orderParams["trainno4"], orderParams["station_train_code"], "M", queryTicketParams["orderRequest.from_station_telecode"], queryTicketParams["orderRequest.to_station_telecode"], leftTicketStr)); ticketLeftGet.req.CookieContainer.Add(reqCookies); string ticketLeftGetResult = ticketLeftGet.SendReqReturnResponseString(); HttpPost orderpost = new HttpPost("https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=confirmSingleForQueue", sb.ToString().Replace("&tFlag=dc", string.Empty)); orderpost.req.CookieContainer.Add(reqCookies); string orderpostresult = orderpost.SendReqReturnResponseString(); }