PHP code implements 12306 remaining ticket query and price query functions

jacklove
Release: 2023-03-30 18:22:02
Original
2101 people have browsed it

12306 The implementation of the remaining ticket query and price query functions will be introduced in this article.

<?php
/**
 * 车票接口类
 *
 * @author chepiao100
 *
 */
class chepiao100
{
 /**
  * 接口地址
  * @var string
  */
 private $_apiurl = &#39;https://www.chepiao100.com/api/&#39;;
  /**
   * 返回接口数据
   *
   * @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[&#39;errMsg&#39;] == &#39;Y&#39;) {
      return $jsonArr[&#39;data&#39;];
    } else {
      return $jsonArr[&#39;errMsg&#39;];
    }
  }
  /**
   * 请求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, &#39;https://10.100.10.100:3128&#39;);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
   $html = curl_exec($ch);
   curl_close($ch);
   return $html;
  }
}
/** End class of chepiao100 **/
Copy after login

This article introduces the 12306 remaining ticket query and price query functions, and uses code to implement related functions. For more related content, please pay attention to the PHP Chinese website.

Related recommendations:

Introduction to PHP related tutorials for quickly exporting Table data

Explain the use of ArrayAccess, the PHP predefined interface Method

Introduces PHP file naming, class and method naming, variable naming and other specifications

The above is the detailed content of PHP code implements 12306 remaining ticket query and price query functions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!