Home  >  Article  >  Backend Development  >  PHP implementation of 12306 remaining ticket query and price query examples_PHP tutorial

PHP implementation of 12306 remaining ticket query and price query examples_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:32:10865browse

复制代码 代码如下:

/**
* Ticket interface class
*
* @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'];
    }
  }

  /**
   * 请求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:3128');
   curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
   $html = curl_exec($ch);
   curl_close($ch);
   return $html;
  }
}
/**End class of chepiao100 **/

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/755843.htmlTechArticle复制代码 代码如下: ?php /*** Ticket interface class * * @author chepiao100 **/ class chepiao100 { /*** Interface address * @var string*/ private $_apiurl = 'http://www.chepiao100.c...
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