一、功能代碼函數實現
//查找快遞,$keyword輸入格式例如為【申通.快遞單號】,例如:申通.768422403144 private function _checkExpress($keyword) { include 'Kd_id.php'; $str = explode('.', $keyword); //按照要求截取字符串成一個數組,具有兩個字符串 $order = $str[1]; $id = $Kd_id[$str[0]]; $apiurl = "http://www.aikuaidi.cn/rest/?key=ff4735a30a7a4e5a8637146fd0e7cec9&order={$order}&id={$id}&show=xml"; //api接口地址 $trans = file_get_contents($apiurl); $data = simplexml_load_string($trans); $Kd_status = $arr_status[strval($data->Status)]; //strval函數將對象轉化為字符串 foreach ($data->Data->Order as $a) { foreach ($a->Time as $b) { foreach ($a->Content as $c) { $m.= "{$b}{$c}"."\n"; } } } $contentStr = "你的快遞單號{$order}{$Kd_status}\n{$m}"; return $contentStr; }
"Kd_id.php"代碼如下:
<?php $Kd_id = array( '京東'=>'jingdong', 'Aramex'=>'aramex', 'EMS'=>'ems', 'FEDEX'=>'fedex', '申通'=>'shentong', '順豐'=>'shunfeng', '速爾'=>'suer', '天天'=>'tiantian', 'UPS'=>'ups', '偉邦'=>'weibang', '微特派'=>'weitepai', '萬象'=>'wxwl', '信豐'=>'xfwl', '新邦'=>'xinbang', '圓通'=>'yuantong', '韻達'=>'yunda', '運通'=>'yuntong', '中通'=>'zhongtong', '宅急送'=>'zjs', '中鐵'=>'zhongtie', '中郵'=>'zhongyou', '中天萬運'=>'ztwy', '平安達'=>'pinganda', '全一'=>'quanyi', '全晨'=>'quanchen', '全日通'=>'quanritong', '如風達'=>'rufengda' ); $arr_status = array( '0'=>'查詢出錯', '1'=>'暫無記錄', '2'=>'在途中', '3'=>'派送中', '4'=>'已簽收', '5'=>'拒收', '6'=>'疑難件', '7'=>'退回' ); ?>
二、運行測試結果

三、支持關注
請關注 金融知識平臺 微信公眾帳號,金融知識平臺 基于SAE 平臺開發,針對于主流的微信功能進行開發測試。
您可以關注 金融知識平臺 公眾帳號進行功能測試,以及獲取新的應用開發。
1. 登錄微信客戶端,通訊錄 -> 添加朋友 -> 查找公眾號 -> f_jinrong,查找并關注。
2. 掃描二維碼:

浙公網安備 33010602011771號