频道栏目
首页 > 资讯 > php > 正文

12306余票查询、价格查询 php实践

17-11-20        来源:[db:作者]  
收藏   我要投稿
<?php
/**
 * 车票接口类
 *
 * @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 **/

 

相关TAG标签
上一篇:jsp中自定义Taglib详解介绍
下一篇:JAVA三大框架SSH的各自作用分析
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站