This article mainly introduces related materials for php to query more than 12306 tickets and price examples.
The Code is as follows:
/**
* Ticket Interface
*
* @ Author chepiao100
*
*/
Class chepiao100
{
/**
* Interface address
* @ Var string
*/
Private $ _ apiurl = 'HTTP: // www.chepiao100.com/api /';
/**
* Return interface data
*
* @ Param string $ method Interface method
* @ Param array $ param Request Parameters
* @ Return mixed
*/
Function getData ($ method, $ param)
{
$ Post = http_build_query ($ param );
$ Html = $ this-> fetch_html ($ this-> _ apiurl. $ method, $ post );
$ JsonArr = json_decode ($ html, TRUE );
If ($ jsonArr ['errmsg '] = 'y '){
Return $ jsonArr ['data'];
} Else {
Return $ jsonArr ['errmsg '];
}
}
/**
* Request HTTP
*
* @ Param string $ url
* @ Param string $ post
* @ Return mixed
*/
Function fetch_html ($ url, $ post)
{
$ Ch = curl_init ($ url );
Curl_setopt ($ ch, CURLOPT_TIMEOUT, 60 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_setopt ($ ch, CURLOPT_POST, true );
// Curl_setopt ($ ch, CURLOPT_PROXY, 'HTTP: // 10.100.10.100: 100 ');
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post );
$ Html = curl_exec ($ ch );
Curl_close ($ ch );
Return $ html;
}
}
/** End class of chepiao100 **/