data=$data; } /** * Execute the job. * * @return void */ public function handle() { $data=$this->data; foreach ($data as $k=>$v){ $order=Order::where('id',$v)->first(); try { $url_info=UrlList::where('url',$order->url)->first(); if ($url_info->time<(time()+30)){ $token=$this->getToekn($order->url,$url_info->id); }else{ $token=$url_info->token; } $client=new Client(); $url = $order->url.'/api/Admin/CompanyCustomerOrderSubmit/OrderReviewSuccess'; $data=['ID'=>$order->ZDL_id]; $re=$client->post($url,[ 'headers' => [ 'Content-Type' => 'application/json', // 设置请求头 'Auth-AdminToken' => $token, // 如果需要身份验证令牌 ], 'json'=>$data ]); $res=$re->getBody()->getContents(); $info=json_decode($res,true); if (isset($info['success'])){ if (!$info['success']){ $log=new OrderSendLog(); $log->log=$order->order_num.'同步订单出错'; $log->order_id=$order->id; $log->save(); } } // Log::error($res); }catch (\Exception $exception){ Log::info($exception->getMessage()); $log=new OrderSendLog(); $log->log=$order->order_num.'同步订单出错'; $log->order_id=$order->id; $log->info=$exception->getMessage(); $log->save(); } } } protected function getToekn($url,$id){ $client=new Client(); $re=$client->post($url.'/api/Admin/System/MainSubLogin',[ 'headers' => [ 'Content-Type' => 'application/json', // 设置请求头 // 'Auth-AdminToken' => 'SjI5Ym5US0xZVzZjSVd4V1FheHg4VG5hL1dpWDJwVi82RDdMY09WU3NTeENIdmJUdmxxTEFVOHZSZkRiaXM1c3RuYUlZTGVIcmI2NGlUdXJ4MXZ6dkREWmRoY283UG5TclQ2RnI5amV3UGYzYjBjNkZ0RTFzUElzRzRhV2F1d0M=', // 如果需要身份验证令牌 ], 'json'=>['UserName'=>'dwadmin','Password'=>'zS76UMV9'] ]); $res=$re->getBody()->getContents(); $info=json_decode($res,true); $urlinfo=UrlList::find($id); // Log::error($res); // Log::error($info); if (!$info['errcode']){ $token=$info['data']['accessToken']; $urlinfo->token=$token; $urlinfo->time=time()+9*60; $urlinfo->save(); return $token; }else{ Log::error($urlinfo->name.'生成token出错===='.$info['errcode']); return 0; } } }