php實現(xiàn)12306余票查詢、價格查詢示例
更新時間:2014年04月17日 10:00:22 作者:
這篇文章主要介紹了php實現(xiàn)12306余票查詢、價格查詢示例的相關(guān)資料
復(fù)制代碼 代碼如下:
<?php
/**
* 車票接口類
*
* @author chepiao100
*
*/
class chepiao100
{
/**
* 接口地址
* @var string
*/
private $_apiurl = 'http://www.chepiao100.com/api/';
/**
* 返回接口數(shù)據(jù)
*
* @param string $method 接口方法
* @param array $param 請求參數(shù)
* @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 **/
相關(guān)文章
php使用file_get_contents(‘php://input‘)和$_POST的區(qū)別實例對比
這篇文章主要介紹了php使用file_get_contents(‘php://input‘)和$_POST的區(qū)別實例對比,這個知識點是比較常用的,有需要的可以參考下2021-03-03
php 將bmp圖片轉(zhuǎn)為jpg等其他任意格式的圖片
有時候我們需要將bmp格式的圖片轉(zhuǎn)換為jpg或gif等格式,大家就可以參考下下面的代碼。2009-06-06
NativePHP使用PHP創(chuàng)建桌面應(yīng)用程序
這篇文章主要為大家介紹了NativePHP使用PHP創(chuàng)建桌面應(yīng)用程序,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-12-12
PHP基礎(chǔ)學(xué)習(xí)之流程控制的實現(xiàn)分析
本篇文章介紹了,PHP基礎(chǔ)學(xué)習(xí)之流程控制的實現(xiàn)分析。需要的朋友參考下2013-04-04

