123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace App\Jobs;
- use App\Models\Order;
- use App\Models\OrderSendLog;
- use App\Models\UrlList;
- use GuzzleHttp\Client;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Support\Facades\Log;
- class TongBuStatusJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- protected $data;
- public function __construct($data)
- {
- $this->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;
- }
- }
- }
|