/** * Execute the job. * * @param JPushClient $client */ public function handle(JPushClient $client) { $error = ''; try { if ($this->download($this->url)) { $package = Package::createFromFile($this->tmpFile, basename($this->url), $this->user->id); $result = Push::send($this->devices, $package, $this->user->id); try { if ($this->devices->count() > 1) { $msg = "已在向{$this->devices->count()}台设备发出推送..."; } else { $msg = "已向{$this->devices->first()->alias}发出推送..."; } Log::info($msg); } catch (\Exception $e) { Log::error('[PushApk Job]推送失败' . $e->getMessage()); return; } } else { $error = trans('errors.download_failed'); Log::error('[PushApk Job]下载文件失败: ' . $this->url); } } catch (Exception $e) { $error = $e->getMessage(); Log::error('[PushApk]' . $e->getMessage() . ' ' . $this->url); } $installIds = $this->devices->pluck('install_id')->toArray(); try { $result = $client->push()->setPlatform(M\all)->setAudience(M\registration_id($installIds))->setNotification(M\notification('出现错误,请检查URL是否正确'))->send(); } catch (Exception $ignored) { } }