search
Homephp教程php手册Train ticket booking interface completes the train ticket booking process

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor