~~~
<?php
/*
* tracking_number 快遞單號
* carrier_code 運輸商簡碼(查詢鏈接 https://www.trackingmore.com/help_article-16-30-cn.html)
* Trackingmore-Api-Key: 后臺生成API key
*/
$url = "http://api.trackingmore.com/v2/trackings/realtime";
$header = array(
'Content-Type:application/json',
'Trackingmore-Api-Key:b7a0009f-6cd2-43ee-9d1d-ed7135ad460f'
);
$postData = array(
'tracking_number'=>'LK664578623CN',
'carrier_code'=>'china-ems'
);
$res = curl_post($url,json_encode($postData),$header);
print_r($res);
function curl_post($url, $postData,$header=array(),$cookie_file='',$isheader=0,$proxy='',$debug=0,$autoRedirect=0,$time=89){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(!empty($isheader)){
curl_setopt($ch, CURLOPT_HEADER, $isheader);
}
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT,$time);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:44.0) Gecko/20100101 Firefox/44.0');
if(!empty($header)){
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
}
if(!empty($autoRedirect)){
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
}
if(!empty($cookie_file)){
// 讀取文件所儲存的Cookie信息
curl_setopt ( $ch, CURLOPT_COOKIEFILE, $cookie_file );
}
if(!empty($proxy)){
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
//curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
if(!empty($debug)){
curl_setopt($ch,CURLOPT_VERBOSE,1);
curl_setopt($ch,CURLOPT_FAILONERROR,TRUE);
print_r(curl_error($ch));
print_r(curl_getinfo($ch));
}
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
~~~
## 第二個類
~~~
<?php
/**
* Express.class.php 快遞查詢類
*
* @copyright widuu
* @license http://www.widuu.com
* @lastmodify 2013-6-19
*/
class Express {
private $expressname =array(); //封裝了快遞名稱
function __construct(){
$this->expressname = $this->expressname();
}
/*
* 采集網頁內容的方法
*/
private function getcontent($url){
if(function_exists("file_get_contents")){
$file_contents = file_get_contents($url);
}else{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
return $file_contents;
}
/*
* 獲取對應名稱和對應傳值的方法
*/
private function expressname(){
$result = $this->getcontent("http://www.kuaidi100.com/");
preg_match_all("/data\-code\=\"(?P<name>\w+)\"\>\<span\>(?P<title>.*)\<\/span>/iU",$result,$data);
$name = array();
foreach($data['title'] as $k=>$v){
$name[$v] =$data['name'][$k];
}
return $name;
}
/*
* 解析object成數組的方法
* @param $json 輸入的object數組
* return $data 數組
*/
private function json_array($json){
if($json){
foreach ((array)$json as $k=>$v){
$data[$k] = !is_string($v)?$this->json_array($v):$v;
}
return $data;
}
}
/*
* 返回$data array 快遞數組
* @param $name 快遞名稱
* 支持輸入的快遞名稱如下
* (申通-EMS-順豐-圓通-中通-如風達-韻達-天天-匯通-全峰-德邦-宅急送-安信達-包裹平郵-邦送物流
* DHL快遞-大田物流-德邦物流-EMS國內-EMS國際-E郵寶-凡客配送-國通快遞-掛號信-共速達-國際小包
* 匯通快遞-華宇物流-匯強快遞-佳吉快運-佳怡物流-加拿大郵政-快捷速遞-龍邦速遞-聯邦快遞-聯昊通
* 能達速遞-如風達-瑞典郵政-全一快遞-全峰快遞-全日通-申通快遞-順豐快遞-速爾快遞-TNT快遞-天天快遞
* 天地華宇-UPS快遞-新邦物流-新蛋物流-香港郵政-圓通快遞-韻達快遞-郵政包裹-優速快遞-中通快遞)
* 中鐵快運-宅急送-中郵物流
* @param $order 快遞的單號
* $data['ischeck'] ==1 已經簽收
* $data['data'] 快遞實時查詢的狀態 array
*/
public function getorder($name,$order){
$keywords = $this->expressname[$name];
$result = $this->getcontent("http://www.kuaidi100.com/query?type={$keywords}&postid={$order}");
$result = json_decode($result);
$data = $this->json_array($result);
return $data;
}
}
$a = new Express();
$result = $a->getorder("全一快遞",111309582915);
var_dump($result);
?>
php快遞查詢API類
####demo
require("Express.class.php");
$a = new Express();
$result = $a->getorder("全一快遞",111309582915);
var_dump($result);
~~~
- PHP新特性
- 一些常識
- PHP常見header頭
- Nginx配置文件
- 常用工具類
- PHP實現的一個時間幫助類
- PHP原生生成EXCEL
- PHP地理位置計算
- PHP獲取服務器狀態
- 駝峰轉下劃線
- 百度地圖兩點坐標距離計算
- 判斷是否是url
- 郵件發送類
- 阿拉伯數字轉化為大寫
- 獲取漢字首個拼音
- 根據身份證號獲取星座
- 生成驗證碼類
- 生成唯一ID
- 身份證驗證類
- PHP中文轉拼音
- curl獲取網頁內容
- 快遞查詢api
- 快遞API類
- 上傳圖片類
- 股票類
- 找回密碼類
- 校驗數據規則
- PHP獲取收集相關信息
- 字符串截取助手函數
- 網頁中提取關鍵字
- 檢測瀏覽器語言
- PHP實現微信紅包拆分算法
- 常用函數
- 微信相關
- 網絡知識
- LX1 Laravel / PHP 擴展包視頻教程
- THINKPHP5學習
- 高級查詢
- Vue學習
- Vue全家桶
- Vue-CLI 3.x 自動部署項目至服務器
- Vue2全家桶
- Vue2全家桶之一:vue-cli(vue腳手架)超詳細教程
- Vue2全家桶之二:vue-router(路由)詳細教程,看這個就夠了
- Vue2全家桶之三:vue-resource(不推薦)----axios(推薦)
- 前端相關
- sublime text3 配置less編譯環境
- 服務器搭建相關
- supervisor
- Supervisor 安裝與配置 Linux進程管理
- supervisor 永不掛掉的進程 安裝以及使用
- Supervisor進程管理&開機自啟
- php實現定時任務
- 使用sublime text3 連接sftp/ftp(遠程服務器)
- Redis相關
- linux服務器重啟后導致redis數據丟失
- 搜索引擎SEO
- 百度收錄權威鏈接,指向真正需要收錄的地址rel
- 軟件相關
- sublime
- sublime Text3修改側邊欄的主題
- sublime和vscode比較
- Acrylic DNS Proxy 使用方法
- 技術類網址收藏