key=Env::get('logistics.kd100_key','fVczXhfg8960'); $this->secret=config('site.kd100_secret')?:'5496a2da1fca49e2acc9283d1f8f32ca'; $this->customer=Env::get('logistics.kd100_customer','B20CCD1C0BAFDD7E69CC986A1A0C57E0'); } public function maptrack() { $param = array ( 'com' => $this->getLogistics('code_kd100'), // 快递公司编码 'num' => $this->getNo(), // 快递单号 'phone' => $this->getPhone(), // 手机号 'from' => $this->extend['from']??'', // 出发地城市 'to' => $this->extend['to']??'', // 目的地城市 'resultv2' => '1', // 开启行政区域解析 'show' => '0', // 返回格式:0:json格式(默认),1:xml,2:html,3:text 'order' => 'desc' // 返回结果排序:desc降序(默认),asc 升序 ); //请求参数 $url = 'https://poll.kuaidi100.com/poll/maptrack.do'; // 实时查询请求地址 $post_data=$this->sign($param); $makeRequest=(new Client)->post($url,[ 'form_params'=>$post_data, ]); $arr=json_decode($makeRequest->getBody()->getContents(),true)?:[]; return Arr::only($arr,[ 'trailUrl', 'message', 'data' ]); } public function query() { //==================================== // 实时查询示例代码 // 授权信息可通过链接查看:https://api.kuaidi100.com/manager/v2/myinfo/enterprise //==================================== //参数设置 $param = array ( 'com' => $this->getLogistics('code_kd100'), // 快递公司编码 'num' => $this->getNo(), // 快递单号 'phone' => $this->getPhone(), // 手机号 'from' => '', // 出发地城市 'to' => '', // 目的地城市 'resultv2' => '1', // 开启行政区域解析 'show' => '0', // 返回格式:0:json格式(默认),1:xml,2:html,3:text 'order' => 'desc' // 返回结果排序:desc降序(默认),asc 升序 ); //请求参数 $url = 'https://poll.kuaidi100.com/poll/query.do'; // 实时查询请求地址 $post_data=$this->sign($param); $makeRequest=(new Client)->post($url,[ 'form_params'=>$post_data, ]); $arr=json_decode($makeRequest->getBody()->getContents(),true); $content=$arr['data']??[]; $flow=[]; foreach ($content as $item){ $flow[]=[ 'time'=>$item['time'], 'content'=>$item['context'], ]; } if(!$flow){ $flow[]=[ 'time'=>date('Y-m-d H:i:s'), 'content'=>'暂无物流信息', ]; } return $flow; } protected function sign($param){ $key = $this->key; // 客户授权key $customer = $this->customer; $post_data = array(); $post_data['customer'] = $customer; $post_data['param'] = json_encode($param, JSON_UNESCAPED_UNICODE); $sign = md5($post_data['param'].$key.$post_data['customer']); $post_data['sign'] = strtoupper($sign); return $post_data; } public function labelOrder(){ $orderNo=$this->orderNo; $dir=RUNTIME_PATH.'/miandan'; if(file_exists($dir."/{$orderNo}")){ } $params=[ 'printType'=>'IMAGE', 'partnerId'=>config('site.kd100_lo_partnerId')?:null, 'partnerKey'=>config('site.kd100_lo_partnerKey')?:null, 'partnerSecret'=>config('site.kd100_lo_partnerSecret')?:null, 'partnerName'=>config('site.kd100_lo_partnerName')?:null, 'net'=>config('site.kd100_lo_net')?:null, 'code'=>config('site.kd100_lo_code')?:null, 'checkMan'=>config('site.kd100_lo_checkMan')?:null, 'tbNet'=>config('site.kd100_lo_tbNet')?:null, 'kuaidicom'=>$this->logistics->code_kd100, 'recMan'=>[ 'name'=>$this->username, 'mobile'=>$this->phone, 'printAddr'=>$this->getToArea(), ], 'sendMan'=>[ 'name'=>$this->getFromUsername(), 'mobile'=>$this->getFromMobile(), 'printAddr'=>$this->getFromArea(), 'count'=>$this->getCount(), ], 'tempId'=>config('site.kd100_lo_tempId')?:'3f733ac0e8ca4ebfaadfc2d9b9ca2519', 'orderId'=>$this->getOrderNo(), 'cargo'=>$this->getCargo(), ]; $body=[ 'method'=>'order', 'key'=>$this->key, 't'=>time()*1000, 'param'=>json_encode($params,256), ]; $body['sign']=strtoupper(md5($body['param'].$body['t'].$body['key'].$this->secret)); $response=(new Client)->post('https://api.kuaidi100.com/label/order',[ 'form_params'=>$body, 'http_errors'=>false, ]); $data=json_decode($response->getBody()->getContents(),true); if(!isset($data['code'])){ return [false,'请求失败']; } if($data['code']!=200){ return [false,$data['message']]; } return [true,$data['data']]; } }