12306余票查询、价格查询功能的实现,本篇将做出相关的介绍。
<?php
/**
 * 车票接口类
 *
 * @author chepiao100
 *
 */
class chepiao100
{
 /**
  * 接口地址
  * @var string
  */
 private $_apiurl = 'https://www.chepiao100.com/api/';
  /**
   * 返回接口数据
   *
   * @param string $method 接口方法
   * @param array $param 请求参数
   * @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, 'https://10.100.10.100:3128');
   curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
   $html = curl_exec($ch);
   curl_close($ch);
   return $html;
  }
}
/** End class of chepiao100 **/本篇文章介绍了12306余票查询、价格查询功能,并且使用代码实现了相关的功能,更多相关内容请关注php中文网。
相关推荐:
立即学习“PHP免费学习笔记(深入)”;
以上就是php代码实现12306余票查询、价格查询功能的详细内容,更多请关注php中文网其它相关文章!
                        
                        铁路12306是一款由中铁程科技有限责任公司官方发行推出的购票订票软件。这款软件能够帮助用户随时随地查询火车高铁的信息,不管是想要购票还是退票改签都可以在这里进行操作,有需要的小伙伴快来保存下载体验吧!
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号