type = $type; $this->type_id = $type_id; $this->m_id = $m_id; } /** * Execute the job. * * @return void */ public function handle() { switch ($this->type) { case "test": $base_url = env('APP_URL')."/pu/#/questionnaire/".$this->type_id."?status=1&merchant_id=".$this->m_id; } $base_url = urlencode($base_url); $url = env('APP_URL')."/api/official/live/wechat/FamilyAuth?merchant_id=".$this->m_id."&url=".$base_url; $pic_path = storage_path('qrcode/'.$this->m_id.'_test_'.$this->type_id.'_sharer_qrcode.png'); //二维码图片 QrCode::format('png')->margin(1)->size(300)->generate($url, $pic_path); $qrcode = ''; if(file_exists($pic_path)){ $qrcode = $this->uploadFile($pic_path); try{ unlink($pic_path); }catch(\Exception $e) { throw new \Exception("删除图片路径失败"); } } if ($qrcode) { QrCodeModel::updateOrCreate(['merchant_id'=>$this->m_id, 'type'=>$this->type, 'type_id'=>$this->type_id], ['url'=>$qrcode, 'jump_url'=>$url]); } } public function uploadFile($file) { $ossClient = UploadController::getOssClient(); //生成file $object = date('Y').date('m')."/".date('d')."/".basename($file); $url = 'https://'.config('alioss.picture_domain').'/'.$object; try { $ossClient->uploadFile(config('alioss.buckets.picture'), $object, $file); } catch(\OSS\Core\OssException $e) { Log::info($e->getMessage()); return false; } return $url; } }