51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Minishlink\WebPush\Subscription;
|
|
use Minishlink\WebPush\WebPush;
|
|
|
|
class StorePushNotification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*/
|
|
public function __construct(
|
|
public $notificationQuery,
|
|
public array $payload
|
|
) {
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$auth = [
|
|
'VAPID' => [
|
|
'subject' => config('app.url'),
|
|
'publicKey' => config('services.vapid.public_key'),
|
|
'privateKey' => config('services.vapid.private_key'),
|
|
],
|
|
|
|
];
|
|
|
|
$webPush = new WebPush($auth);
|
|
|
|
$payload = json_encode($this->payload);
|
|
|
|
foreach ($this->notificationQuery as $notification) {
|
|
$webPush->sendOneNotification(
|
|
Subscription::create(is_array($notification->subscriptions) ? $notification->subscriptions : json_decode($notification->subscriptions, true)),
|
|
$payload,
|
|
['TTL' => 86400, 'urgency' => 'high'],
|
|
);
|
|
}
|
|
}
|
|
}
|