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)文章
thinkPHP5實現(xiàn)數(shù)據(jù)庫添加內(nèi)容的方法
這篇文章主要介紹了thinkPHP5實現(xiàn)數(shù)據(jù)庫添加內(nèi)容的方法,結(jié)合實例形式較為詳細的分析了thinkPHP5數(shù)據(jù)庫的配置、模型、控制器的使用及數(shù)據(jù)插入相關(guān)操作技巧,需要的朋友可以參考下2017-10-10基于ubuntu下nginx+php+mysql安裝配置的具體操作步驟
本篇文章介紹了,基于ubuntu下nginx+php+mysql安裝配置的具體操作步驟。需要的朋友參考下2013-04-04laravel 解決Eloquent ORM的save方法無法插入數(shù)據(jù)的問題
今天小編就為大家分享一篇laravel 解決Eloquent ORM的save方法無法插入數(shù)據(jù)的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10laravel-admin解決表單select聯(lián)動時,編輯默認沒選上的問題
今天小編就為大家分享一篇laravel-admin解決表單select聯(lián)動時,編輯默認沒選上的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09