Home >php教程 >php手册 >Train ticket booking interface completes the train ticket booking process

Train ticket booking interface completes the train ticket booking process

WBOY
WBOYOriginal
2016-10-18 08:41:411564browse

This tutorial is used to demonstrate the usage process of the aggregated data-train ticket booking interface.
1. Configure the PHP environment. The PHP version is preferably greater than 5.5
2. De-aggregate data - train ticket booking interface application key: https://www.juhe.cn/docs/api/id/173
3. The following code is for you to understand the process. Do not copy it directly and do not use it in the production environment. 'The key you applied for', <br> 'url' => array( <br> 'cityCode' => 'http://op.juhe.cn/trainTickets/cityCode', <br> 'ticketsAvailable' => 'http://op.juhe.cn/trainTickets/ticketsAvailable', <br> 'submit' => 'http://op.juhe.cn/trainTickets/submit', <br> 'orderStatus' => 'http://op.juhe.cn/trainTickets/orderStatus', <br> 'pay' => 'http://op.juhe.cn/trainTickets/pay', <br> ), <br> ); <br> #1. Check the site short code <br> echo 'Itinerary planning: July 1, 2015, starting from Suzhou and destination Qingdao <br> [object Object]'; <br> echo 'First check the short codes of Suzhou Station and Qingdao Station <br> '; <br> //Query the short code of Suzhou Station <br> $suzhouCodeResponse = post($config['url']['cityCode'], 'key='.$config['key'].'&stationName=Suzhou'); <br> $suzhouCodeArray = json_decode($suzhouCodeResponse, true); <br> $suzhouCode = $suzhouCodeArray['result']['code']; <br> echo 'The short code of the Suzhou station is: '.$suzhouCode.' <br> '; <br> // Query the short code of Qingdao Station <br> $qingdaoCodeResponse = post($config['url']['cityCode'], 'key='.$config['key'].'&stationName=Qingdao'); <br> $qingdaoCodeArray = json_decode($suzhouCodeResponse, true); <br> $qingdaoCode = $qingdaoCodeArray['result']['code']; <br> echo 'The short code of the Qingdao station is: '.$qingdaoCode.' <br> [object Object]'; <br> #2. Check remaining votes <br> echo 'Then check the remaining ticket information <br> '; <br> $ticketsAvailableResponse = post($config['url']['ticketsAvailable'], <br> '&key='.$config['key']. <br> '&train_date=2015-07-01'. //Pay attention to the date format <br> '&from_station=SZH'. //The short code of Suzhou Station found in the previous step is SZH <br> '&to_station=QDK' //The short code of Qingdao station found in the previous step is QDK <br> ); <br> $ticketsAvailableArray = json_decode($ticketsAvailableResponse, true); <br> echo 'Remaining ticket information queried: <br> '; <br> print_r($ticketsAvailableArray['result']['list']); <br> echo ' <br> [object Object]'; <br> #3. Submit order <br> echo 'Submit order <br> '; <br> echo 'Based on the remaining ticket information, it was found that the G226 train is more suitable <br> '; <br> echo 'Please look at the remaining ticket details of train G226. Some fields need attention: <br> '; <br> echo 'start_station_name: Starting station, Shanghai Hongqiao <br> '; <br> echo 'from_station_name: The station we are about to depart from, Suzhou North, please note it is not Suzhou <br> '; <br> echo 'from_station_code: OHH, please note that this is the short code of Suzhou North Station, not Suzhou Station, and it is also the parameter passed when we submit the order <br> '; <br> $passengersArray = array( <br> array( <br> 'passengerid' => '1123', //The passenger's sequence number. When there are multiple passengers, each person's passenger number must be unique <br> 'Passengersename' => 'Zhang San', //Please replace it with your real name <br> 'piaotype' => '1', //Please carefully check the corresponding relationship between piaotype and piaotypename in the official website document, and make sure there is no mistake <br>'piaotypename' => 'Adult ticket', <br> 'Passporttypeseid' => '1', //Please carefully check the corresponding relationship between passporttypeseid and passporttypeseidname in the official website document to make sure there is no mistake <br> ‘passporttypeseidname’ => ‘Second generation ID card’, <br> 'passportseno' => '420205199207231234', //Please replace it with your real ID number <br> 'price' => '763.5', //Fill in the real price <br> 'zwcode' => 'M', //Please confirm whether there is such a seat in the train you selected <br> 'zwname' => 'First Class', <br> ), <br> array( //Second passenger, up to five passengers <br> 'passengerid' => '2123', <br> 'passengersename' => '李思', <br> 'piaotype' => '1', <br> 'piaotypename' => 'Adult ticket', <br> 'passporttypeseid' => '1', <br> ‘passporttypeseidname’ => ‘Second generation ID card’, <br> 'passportseno' => '23060519930621234', <br> 'price' => '59.5', <br> 'zwcode' => 'M', <br> 'zwname' => 'First class', <br> ) <br> ); <br> $postArray = array( <br> 'key' => $config['key'], <br> 'checi' => 'G226', //From the previous query, it was found that G226 has more votes <br> 'from_station_code' => 'OHH', //The short code of the departure station, please note it is not SZH (Suzhou) <br> 'from_station_name' => 'Suzhou North', //The name of the departure station must correspond to the short code of the departure station <br> 'to_station_code' => 'QDK', //Short code for arriving at the station <br> 'to_station_name' => 'Qingdao', //The name of the arrival station must correspond to the short code of the arrival station <br> 'train_date' => '2015-07-01', //Train date, pay attention to the time format <br> 'passengers' => json_encode($passengersArray, JSON_UNESCAPED_UNICODE), <br> ); <br> $postStr = ''; <br> foreach ($postArray as $key => $value) { <br> $postStr .= '&'.$key.'='.$value; <br> } <br> //echo $postStr;exit; <br> $submit = post($config['url']['submit'], $postStr); <br> //echo $submit;exit; <br> echo '[object Object]'; <br> /* Normal output example <br> { <br> "reason": "Successful return", <br> "result": { <br> "orderid": "1433493562439" //You can check the processing status based on this order number later <br> }, <br> "error_code": 0 <br> } <br> */​<br> #4. Check order status <br> echo 'Check order status <br> '; <br> //Please replace the order number with your own order number <br> $status = post($config['url']['orderStatus'], 'key='.$config['key'].'&orderid=1433493562439'); <br> echo $status; <br>#5. Request a ticket (the money will be deducted from your aggregation account); please make sure your order is an order to be paid before requesting data from this interface <br> echo '[object Object]Request to issue a ticket (the premise is to check the order status and know that the seat occupation is successful) <br> '; <br> $pay = post($config['url']['pay'], 'key='.$config['key'].'&orderid=1433493562439'); <br> echo $pay;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn