78 lines
2.4 KiB
PHP
78 lines
2.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use App\Http\Controllers\UploadController;
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
use Illuminate\Support\Facades\Log;
|
||
|
|
use Illuminate\Support\Facades\Redis;
|
||
|
|
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||
|
|
use App\Models\Server\QrCode as QrCodeModel;
|
||
|
|
class MakeQrcode implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
|
||
|
|
protected $type, $type_id, $m_id;
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($type, $type_id, $m_id)
|
||
|
|
{
|
||
|
|
$this->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;
|
||
|
|
}
|
||
|
|
}
|