Spring Festival grab Ticket introduction play 12306 of inquiries, booking

Source: Internet
Author: User
Tags rand ticket

Book on the last, today I will query and booking the entire process of detailed introduction to everyone.

First, inquires the ticket information

First, let's take a look at the HTTP request for the remainder of the ticket (the query for the following illustration is an example)

The full HTTP request is as follows:

Https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=queryLeftTicket&orderRequest.train_date= 2013-10-11&orderrequest.from_station_telecode=bjp&orderrequest.to_station_telecode=whn& orderrequest.train_no=&trainpasstype=qb&trainclass=qb%23d%23z%23t%23k%23qt%23&includestudent=00 &seattypeandnum=&orderrequest.start_time_str=00%3a00–24%3a00

The requested parameter:

Method:queryleftticket orderrequest.train_date:2013-10-11 OrderRequest.from_station_telecode:BJP orderrequest.to_ STATION_TELECODE:WHN OrderRequest.train_no:trainPassType:QB trainclass:qb#d#z#t#k#qt# includestudent:00 seattypeandnum:orderrequest.start_time_str:00:00–24:00

We see the parameter of method, which is read from the literal meaning, is the query of the remainder of the ticket. Then Orderrequest.train_date said the date of the ride, Orderrequest.from_station_telecode said the departure of the simple code, Orderrequest.to_station_ Telecode represents the destination of the simple code, Orderrequest.train_no train code, Trainpasstype said the car's passing type, are all: QB, Originating: SF, passing: Lg,trainclass express the type of car, respectively: All: Qb,d car: d,z Word head: z,t word head: t,k word head: K, Other: QT, if more select middle with # connection. Includestudent indicates whether the inclusion of student tickets, included as 0x00, is not included as 00,seattypeandnum and quantity, is not used at this stage. ORDERREQUEST.START_TIME_STR indicates the departure time.

Then look at the result of this request response (the result is too long, take a record to analyze)

0,<span id= ' id_330000k5980k ' class= ' base_txtdiv ' onmouseover=javascript:onstophover (' 330000K5980K#BXP#WCN ') Onmouseout= ' onstopout () ' >K599</span>,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; Beijing West &nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;& nbsp;05:20,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; Wuchang &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; 20:37,15:17,–,–,–,–,–,9,4,–,8,<font color= ' #008800 ′> has </font>,–,<a name= ' btn130_2′class= ' btn130_2′ Style= ' Text-decoration:none ' onclick=javascript:getselected (' k599#15:17#05:20#330000k5980k#bxp#wcn#20:37# Beijing West # Wuchang #08#27#1*****30364*****00091*****00083*****0004# muffmdhdqtncnemzqjmwmtu4qzg5njddodmxrei2mknfodfdmtherem3mzm0nda5ney0rtuzmtu6ojo6mtm4mtmwmtixmtg2mq== #C1) > Pre &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsP. </a>

The result of a response is a string, which is a record of the interception, and observes that the result of the response is to return the train information, with each record ending with N.

For a record, the various fields of information that are separated by "," correspond to each field in the Query results table.

Focus on the following data:

<a name= ' btn130_2′class= ' btn130_2′style= ' Text-decoration:none; ' onclick=javascript:getselected (' K599#15:17# 05:20#330000k5980k#bxp#wcn#20:37# Beijing West # Wuchang #08#27#1*****30364*****00091*****00083*****0004# muffmdhdqtncnemzqjmwmtu4qzg5njddodmxrei2mknfodfdmtherem3mzm0nda5ney0rtuzmtu6ojo6mtm4mtmwmtixmtg2mq== #C1) > Pre &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Reservations </a>

This is when the user clicks on the reservation, to send the data to the server, the data is separated by the #, which I call it orderkey.

OK, when we click on the reservation, look at what HTTP requests have occurred

Post:https://dynamic.12306.cn/otsweb/order/querysingleaction.do?method=submutorderrequest

Post's data:

station_train_code:k599 train_date:2013-10-11 Seattype_num:from_station_telecode:BXP TO_STATION_TELECODE:WCN include_student:00 from_station_telecode_name: Beijing to_station_telecode_name: Wuhan round_train_date:2013-10-09 round_ start_time_str:00:00–24:00 single_round_type:1 train_pass_type:qb train_class_arr:qb#d#z#t#k#qt# start_time_str:0 0:00–24:00 lishi:15:17 train_start_time:05:20 trainno4:330000k5980k arrive_time:20:37 from_station_name: Beijing West To_ Station_Name: Wuchang from_station_no:08 to_station_no:27 ypinfodetail:1*****30364*****00091*****00083*****0004 mmStr: qzg1nuezmzuzqtuwqzgzquvfrkm1mdm0mdk4qknemzm4quu1ouq0mjneodmynerdnendmjy3qky6ojo6mtm4mtmwmte0mzk4oq== LOCATIONCODE:C1 otkwnju2oa==:ywjjyju2ndbiote0mwvizq== myversion:undefined

Most of the above parameters can be obtained by clicking on the "Orderkey" at the time of the reservation, just a red-labeled dynamic key and dynamic value in the back, which has already been mentioned in the previous article, and is no longer said here.

The result returned is a 302,302 address is:

Https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init

Open this page and find the page that selects the passenger information and submits the order.

Then we select the passenger, enter the verification code and submit it to see what the request has been:

Post:https://dynamic.12306.cn/otsweb/order/confirmpassengeraction.do?method=checkorderinfo&rand=x8t6

Rand represents a CAPTCHA, from the literal meaning of method to detecting order information

Post data:

The data in this post, as shown in the previous figure, contains information about the ride, and passenger information. Travel information, in the last step of the book can be obtained, passenger information, observation,

Https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=getpassengerJson This address can get all of the user's information about the passengers, By selecting the passenger information, we can construct the data we want to submit.

Post Data Org.apache.struts.taglib.html.TOKEN and LEFTTICKETSTR is how to come, look back to the book after the 302 address, found in the source code there are such a paragraph

<input type= "hidden" name= Org.apache.struts.taglib.html.TOKEN "value=" 21f84a6c22c03df66fcd90a5d1eb9818″>

<input type= "hidden" name= "Leftticketstr" id= "Left_ticket" value= >

Compared to the value of the data above, this is exactly what we need, so we can get these values from the 302 address source.

Look at the result of the request:

{"CHECKHUIMD": "Y", "Check608″:" Y "," msg ":" "," errmsg ":" Y "}

Where CHECKHUIMD is n words: Because you cancel too many times, today will not continue to accept your booking request!

check608 for n words: This car for the real-name train, the implementation of one day a car a ticket system!

MSG displays an error message when the above 2 values have one n.

OK, if this step without error message prompts, will continue to query the remaining ticket information

Get:https://dynamic.12306.cn/otsweb/order/confirmpassengeraction.do?method=getqueuecount&train_date= 2013-10-11&train_no=330000k5980k&station=k599&seat=3&from=bxp&to=wcn&ticket= 1015253035404275000910152500003027050004

The result returned is:

{"Countt": 0, "Count": 0, "Ticket": "1*****30354*****00091*****00003*****0004″," Op_1″:false, "Op_2″:false}"

If Op_2 is true, it means that the number of queues has exceeded the number of votes, Countt says the number of queues is currently available.

Ticket represents the remaining ticket information.

If there is a ticket, we continue to request:

Post:https://dynamic.12306.cn/otsweb/order/confirmpassengeraction.do?method=confirmsingleforqueue

The data for the post is roughly the same as the data for the test order, but one tflag:dc is missing.

The result of the response: {"errmsg": "Y"}, which means that the order confirmation was successful. If ErrMsg is n, the result of the response will be MSG information to indicate the error message.

The order confirmation is successful, we have to check whether the order is completed

Get:https://dynamic.12306.cn/otsweb/order/myorderaction.do?method=queryorderwaittime&tourflag=dc

Result of response: {"Tourflag": "DC", "waittime":-1, "Waitcount": 0, "orderId": "E493113786″," RequestID ": 5793605912349971391," Count ": 0}

Waittime indicates that the waiting time, if 1 means the order is successful, you can go to pay. OrderID represents the order number, which appears when the order succeeds.

At this point, the entire query, the process of placing orders completed.

The last one I wrote the query booking map:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.