下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
TrackingmorePHPClassExample安装:
1.复制TrackingmoreAPI类的代码到你需要的位置(具体API类的代码放在本文档的后半部分)
2.在这一行填写你自己在后台生成的apikey,protected$apiKey='YOURAPIKEY';
3.在程序中包含这个类.列出所有运输商$track=newTrackingmore;$track=$track->getCarrierList();通过单号自动识别运输商$track=newTrackingmore;$trackingNumber='RM121546236CN';$track=detectCarrier($trackingNumber);列出所有的跟踪$track=newTrackingmore;$page=1;$limit=50;$createdAtMin=time()-7*24*60*60;$createdAtMax=time();$track=$track->getTrackingsList($page,$limit,$createdAtMin,$createdAtMax);创建一个跟踪项目$track=newTrackingmore;$extraInfo['title']='iphone6';$extraInfo['customer_name']='charsechen';$extraInfo['customer_email']='chasechen@';$extraInfo['order_id']='8988787987';$track=$track->createTracking('china-post','RM121516216CN',$extraInfo);创建多个跟踪$track=newTrackingmore;$items=array(array( 'tracking_number'=>'RM131516216CN', 'carrier_code'=>'china-post', 'title'=>'iphone6', 'customer_name'=>'charsechen', 'customer_email'=>'chasechen@', 'order_id'=>'8988787987' ), array( 'tracking_number'=>'RM111516216CN', 'carrier_code'=>'china-post', 'title'=>'iphone6s', 'customer_name'=>'clooneychen', 'customer_email'=>'clooneychen@', 'order_id'=>'898874587' ),);$track=$track->createMultipleTracking($items);获取跟踪单个跟踪结果$track=newTrackingmore;$track=$track->getSingleTrackingResult('china-post','RM131516216CN');更新跟踪项目$track=newTrackingmore;$extraInfo['title']='iphone6';$extraInfo['customer_name']='charsechen';$extraInfo['customer_email']='chasechen@';$extraInfo['order_id']='8988787987';$track=$track->updateTrackingItem('china-post','RM131516216CN',$extraInfo);删除跟踪项目$track=newTrackingmore;$track=$track->deleteTrackingItem('china-post','RM131516216CN');获取单次跟踪的实时跟踪结果$track=newTrackingmore;$track=$track->getRealtimeTrackingResults('china-post','RM131516216CN');PHPClassExampleAPI类的代码如下(你可以将下列代码复制到代码编辑器中,这样会看起来整齐一些):classTrackingmore{constAPI_BASE_URL='/v2/';constROUTE_CARRIERS='carriers/';constROUTE_CARRIERS_DETECT='carriers/detect';constROUTE_TRACKINGS='trackings'; constROUTE_LIST_ALL_TRACKINGS='trackings/get'; constROUTE_CREATE_TRACKING='trackings/post';constROUTE_TRACKINGS_BATCH='trackings/batch'; constROUTE_TRACKINGS_REALTIME='trackings/realtime';protected$apiKey='yourapikey';protectedfunction_getApiData($route,$method='GET',$sendData=array()){ $method=strtoupper($method);$requestUrl=self::API_BASE_URL.$route;$curlObj=curl_init();curl_setopt($curlObj,CURLOPT_URL,$requestUrl); if($method=='GET'){curl_setopt($curlObj,CURLOPT_HTTPGET,true);}elseif($method=='POST'){curl_setopt($curlObj,CURLOPT_POST,true);}elseif($method=='PUT'){curl_setopt($curlObj,CURLOPT_PUT,true);}else{ curl_setopt($curlObj,CURLOPT_CUSTOMREQUEST,$method); } curl_setopt($curlObj,CURLOPT_CONNECTTIMEOUT,10);curl_setopt($curlObj,CURLOPT_TIMEOUT,90);curl_setopt($curlObj,CURLOPT_RETURNTRANSFER,true);curl_setopt($curlObj,CURLOPT_HEADER,0);$headers=array('Trackingmore-Api-Key:'.$this->apiKey,'Content-Type:application/json',);if($sendData){$dataString=json_encode($sendData);curl_setopt($curlObj,CURLOPT_POSTFIELDS,$dataString);$headers[]='Content-Length:'.strlen($dataString);}curl_setopt($curlObj,CURLOPT_HTTPHEADER,$headers);$response=curl_exec($curlObj);curl_close($curlObj);unset($curlObj);return$response;} //ListallcarrierspublicfunctiongetCarrierList(){$returnData=array();$requestUrl=self::ROUTE_CARRIERS;$result=$this->_getApiData($requestUrl,'GET');if($result){$returnData=json_decode($result,true);}return$returnData;} /*Detectacarrierbytrackingcode *@paramstring$trackingNumberTrackingnumber*@returnarray */ publicfunctiondetectCarrier($trackingNumber){$returnData=array();$requestUrl=self::ROUTE_CARRIERS_DETECT; $sendData['tracking_number']=$trackingNumber;$result=$this->_getApiData($requestUrl,'POST',$sendData);if($result){$returnData=json_decode($result,true);}return$returnData;} /** *Listalltrackings *@accesspublic *@paramint$pagePagetodisplay(optional) *@paramint$limitItemsperpage(optional) *@paramint$createdAtMinStartdateandtimeoftrackingscreated(optional) *@paramint$createdAtMax *@returnarray */ publicfunctiongetTrackingsList($page=1,$limit=100,$createdAtMin=0,$createdAtMax=0){$returnData=array(); $sendData=array();$requestUrl=self::ROUTE_LIST_ALL_TRACKINGS; $createdAtMax=!empty($createdAtMax)?$createdAtMax:time(); $sendData['page']=$page; $sendData['limit']=$limit; $sendData['created_at_min']=$createdAtMin; $sendData['created_at_max']=$createdAtMax;$result=$this->_getApiData($requestUrl,'GET',$sendData);if($result){$returnData=$result;}return$returnData;} /** *Createatrackingitem *@accesspublic *@paramstring$trackingNumberTrackingnumber *@paramstring$carrierCodeCarriercode *@paramarray$extraInfoTitle,Customername,email,orderID(optional) *@returnarray */ publicfunctioncreateTracking($carrierCode,$trackingNumber,$extraInfo=array()){$returnData=array(); $sendData=array();$requestUrl=self::ROUTE_CREATE_TRACKING; $sendData['tracking_number']=$trackingNumber; $sendData['carrier_code']=$carrierCode; $sendData['title']=!empty($extraInfo['title'])?$extraInfo['title']:null; $sendData['customer_name']=!empty($extraInfo['customer_name'])?$extraInfo['customer_name']:null; $sendData['customer_email']=!empty($extraInfo['customer_email'])?$extraInfo['customer_email']:null; $sendData['order_id']=!empty($extraInfo['order_id'])?$extraInfo['order_id']:null; $result=$this->_getApiData($requestUrl,'POST',$sendData);if($result){$returnData=json_decode($result,true);}return$returnData;} /** *Createmultipletrackings. *@accesspublic *@paramarray$multipleDataMultipletrackingnumber,carriercode,title,customername,customeremail,orderid *@returnarray */ publicfunctioncreateMultipleTracking($multipleData){$returnData=array(); $sendData=array();$requestUrl=self::ROUTE_TRACKINGS_BATCH; if(!empty($multipleData)){ foreach($multipleDataas$val){ $items=array(); $items['tracking_number']=!empty($val['tracking_number'])?$val['tracking_number']:null; $items['carrier_code']=!empty($val['carrier_code'])?$val['carrier_code']:null; $items['title']=!empty($val['title'])?$val['title']:null; $items['customer_name']=!empty($val['customer_name'])?$val['customer_name']:null; $items['customer_email']=!empty($val['customer_email'])?$val['customer_email']:null; $items['order_id']=!empty($val['order_id'])?$val['order_id']:null;$sendData[]=$items; } } $result=$this->_getApiData($requestUrl,'POST',$sendData);if($result){$returnData=json_decode($result,true);}return$returnData;} /** *Gettrackingresultsofasingletracking *@accesspublic *@paramstring$trackingNumberTrackingnumber *@paramstring$carrierCodeCarriercode *@returnarray */ publicfunctiongetSingleTrackingResult($carrierCode,$trackingNumber){$returnData=array();$requestUrl=self::ROUTE_TRACKINGS.'/'.$carrierCode.'/'.$trackingNumber;$result=$this->_getApiData($requestUrl,'GET');if($result){$returnData=json_decode($result,true);}return$returnData;} /** *UpdateTrackingitem *@accesspublic *@paramstring$trackingNumberTrackingnumber *@paramstring$carrierCodeCarriercode *@paramarray$extraInfoTitle,Customername,email,orderID(optional) *@returnarray */ publicfunctionupdateTrackingItem($carrierCode,$trackingNumber,$extraInfo){$returnData=array();$requestUrl=self::ROUTE_TRACKINGS.'/'.$carrierCode.'/'.$trackingNumber; $sendData['title']=!empty($extraInfo['title'])?$extraInfo['title']:null; $sendData['customer_name']=!empty($extraInfo['customer_name'])?$extraInfo['customer_name']:null; $sendData['customer_email']=!empty($extraInfo['customer_email'])?$extraInfo['customer_email']:null; $sendData['order_id']=!empty($extraInfo['order_id'])?$extraInfo['order_id']:null;$result=$this->_getApiData($requestUrl,'PUT',$sendData);if($result){$returnData=json_decode($result,true);}return$returnData;}/** *Deleteatrackingitem *@accesspublic *@paramstring$trackingNumberTrackingnumber *@paramstring$carri
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 五年级数学(小数除法)计算题专项练习及答案
- 电冰箱、空调器安装与维护电子教案 4.3 运行并调试
- 湘教版九年级美术上册说课稿
- 江西省上饶市广丰中学2024-2025学年高三上学期11月化学测试卷(含答案)
- 福建省龙岩市一级校联盟2024-2025学年高三上学期11月期中考试 英语(含答案无听力音频有听力原文)
- 头发造型用发胶产业规划专项研究报告
- 医用人体成分分析仪产业规划专项研究报告
- 挖泥机市场发展预测和趋势分析
- 医用消毒器市场需求与消费特点分析
- 湖北省荆州市监利市多校2024-2025学年二年级上学期期中数学试题
- 基于社会效益与经济效益的大型医疗设备成本效益分析
- 国家开放大学《护理科研方法》形考任务1-4参考答案
- 走近湖湘红色人物智慧树知到课后章节答案2023年下湖南工商大学
- 软件项目提成方案
- 医院服务礼仪培训课件
- 低年级绘本 校本课程纲要
- 推拉门安装技术交底
- 装配式建筑设计研究与总结课件
- 一年级上册全册道德与法治教案全
- 中班健康《身体上的洞洞》课件
- GB/T 9452-2023热处理炉有效加热区测定方法
评论
0/150
提交评论