Php implements more than 12306 ticket query and price query example _ php instance

Source: Internet
Author: User
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 **/

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.