Php implements more than 12306 ticket queries and price query examples _ PHP Tutorial

Source: Internet
Author: User
Php provides more than 12306 ticket queries and price query examples. Copy the code as follows :? Php *** ticket interface class ** @ authorchepiao100 ** classchepiao100 {*** interface address * @ varstring * private $ _ apiurlwww. chepiao100.c 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 **/

The http://www.bkjia.com/PHPjc/755843.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/755843.htmlTechArticle code is as follows :? Php/*** ticket interface class ** @ author chepiao100 **/class chepiao100 {/*** interface address * @ var string */private $ _ apiurl = 'http: // www. chepiao100.c...

Related Article

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.