'顺丰速运', 'HTKY' =>'百世快递', 'ZTO' =>'中通快递', 'STO' =>'申通快递', 'YTO' =>'圆通速递', 'YD' =>'韵达速递', 'YZPY' =>'邮政快递包裹', 'EMS' =>'EMS', 'HHTT' =>'天天快递', 'JD' =>'京东快递', 'UC' =>'优速快递', 'DBL' =>'德邦快递', 'ZJS' =>'宅急送', 'PJ' =>'品骏快递', ]; return $arr; } public function search($express_code,$ShipperCode=null,$OrderCode=null,$CustomerName=null){ try{ if ($ShipperCode=='ZTO'){ $client=new Client(); $url='http://japi.zto.cn/traceInterfaceNewTraces'; $array=[ 'headers'=>[ 'ContentType'=>'application/x-www-form-urlencoded', 'x-companyid'=>'206f48b6bded4906a06eddd39bf26e7c', 'x-datadigest'=>base64_encode(md5('data=["'.$express_code.'"]&company_id=206f48b6bded4906a06eddd39bf26e7c&msg_type=NEW_TRACES0480ecc2d633',true)) ], 'query'=>[ 'data'=>'["'.$express_code.'"]', 'company_id'=>'206f48b6bded4906a06eddd39bf26e7c', 'msg_type'=>'NEW_TRACES', ] ]; $request=$client->request('POST',$url,$array); $ad=$request->getBody()->getContents(); $re=[]; $state=0; $ads=json_decode($ad); $arr=(array)$ads; if ($arr['data'][0]->traces){ foreach ($arr['data'][0]->traces as $k=>$v){ $re[$k]['AcceptStation']=$v->desc; $re[$k]['AcceptTime']=strtotime($v->scanDate)*1000; if ($v->scanType=='ARRIVAL' || $v->scanType=='SIGNED' || $v->scanType=='5' || $v->scanType=='6' || $v->scanType=='签收'){ $state=3; } } } $a['LogisticCode']=$express_code; $a['ShipperCode']=$ShipperCode; $a['Traces']=$re; $a['State']=$state; return $a; } $client=new Client(); if ($ShipperCode=='DBL'){ $url='https://www.deppon.com/gwapi/trackService/eco/track/searchTrack?billNo='.$express_code; $request=$client->request('get',$url); $ad=$request->getBody()->getContents(); $ads=json_decode($ad); $re=[]; $state=0; if ($ads->status=='success'){ foreach ($ads->result->tracks as $k=>$v){ $re[$k]['AcceptStation']=$v->contentNoLinkLabel; $re[$k]['AcceptTime']=$v->operateTime; } if ($ads->result->billNoState=='已签收'){ $state=3; } } $a['LogisticCode']=$express_code; $a['ShipperCode']=$ShipperCode; $a['Traces']=$re; $a['message']=$ads->message; $a['State']=$state; return $a; } $appkey='5df378bc-fc24-4482-9b30-3fbe99ce609d'; $appid=1731767; $url='http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx'; $array=[ 'query'=>[ 'RequestData'=>urlencode($this->requestdata($express_code,$ShipperCode,$OrderCode,$CustomerName)), 'EBusinessID'=>$appid, 'RequestType'=>'8001', 'DataSign'=>urlencode($this->encrypt($this->requestdata($express_code,$ShipperCode,$OrderCode,$CustomerName),$appkey)), 'DataType'=>'2' ] ]; $re=$client->request('POST',$url,$array); $dd=$re->getBody()->getContents(); $d=json_decode($dd); if ($d->Traces){ foreach ($d->Traces as $k=>$v){ $v->AcceptTime=strtotime($v->AcceptTime)*1000; } } return $d; }catch (\Exception $exception){ $a['LogisticCode']=$express_code; $a['ShipperCode']=$ShipperCode; $a['Traces']=[]; $a['State']=40010; return $a; } } private function requestdata($express_code,$ShipperCode =null,$OrderCode=null,$CustomerName=null){ if ($ShipperCode){ $requestdata['ShipperCode']=$ShipperCode; } if ($OrderCode){ $requestdata['OrderCode']=$OrderCode; } if ($CustomerName){ $requestdata['CustomerName']=$CustomerName; } $requestdata['LogisticCode']=$express_code; return json_encode($requestdata); } public function encrypt($reqiredata,$appkey){ return base64_encode(md5($reqiredata.$appkey)); } public function getExpressCompany($LogisticCode){ $client = new Client(); $appKey = '321b74bb-84a3-4b9c-af1d-937583f9a3a0'; $appId = 1640111; // $url = 'http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json'; $url = 'https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx'; $requestData = $this->requestData($LogisticCode); $array = [ 'query' => [ 'RequestData' => urlencode($requestData), 'EBusinessID' => $appId, 'RequestType' => '2002', 'DataSign' => urlencode($this->encrypt($requestData, $appKey)), 'DataType' => '2' ] ]; $result = $client->request('POST', $url, $array); $res = json_decode($result->getBody()->getContents()); return $res; } }