123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace App\Handlers;
- use GuzzleHttp\Client;
- use http\Env\Request;
- use Illuminate\Support\Collection;
- class ExpressHandler {
- public static function getExpressCode(){
- $arr=[
- 'SF' =>'顺丰速运',
- 'HTKY' =>'百世快递',
- 'ZTO' =>'中通快递',
- 'STO' =>'申通快递',
- 'YTO' =>'圆通速递',
- 'YD' =>'韵达速递',
- 'YZPY' =>'邮政快递包裹',
- 'EMS' =>'EMS',
- 'HHTT' =>'天天快递',
- 'JD' =>'京东快递',
- 'UC' =>'优速快递',
- 'DBL' =>'德邦快递',
- 'ZJS' =>'宅急送',
- 'PJ' =>'品骏快递',
- 'JTSD' =>'极兔速递',
- 'YMDD' =>'壹米滴答',
- ];
- 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='321b74bb-84a3-4b9c-af1d-937583f9a3a0';
- $appid=1640111;
- $url='http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx';
- $array=[
- 'query'=>[
- 'RequestData'=>urlencode($this->requestdata($express_code,$ShipperCode,$OrderCode,$CustomerName)),
- 'EBusinessID'=>$appid,
- 'RequestType'=>'8002',
- '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;
- }
- }
|