龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

12306火车票余票查询、价格查询最新api(PHP)

时间:2014-07-22 14:48来源: 作者: 点击:
分享到:
提供最新的火车票余票查询API 有需要的朋友可以看看欢迎加入交流Q群 102612968
 提供最新的火车票余票查询API   有需要的朋友可以看看
欢迎加入交流Q群 102612968
<?php
/**
 * 车票100 接口类
 * 
 * @author chepiao100
 *
 */
class chepiao100
{	
	/**
	 * 接口地址
	 * @var string
	 */
	private $_apiurl = 'http://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, '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 **/

2. [文件] PHP_SDK_V0.1.rar ~ 6KB     下载(99)     [全屏预览]

精彩图集

赞助商链接