6
0
Fork 0
jiqu-library-server/app/Notifications/Channels/SmsChannel.php

43 lines
1.0 KiB
PHP

<?php
namespace App\Notifications\Channels;
use Illuminate\Notifications\Notification;
use Overtrue\EasySms\EasySms;
use Overtrue\EasySms\Exceptions\NoGatewayAvailableException;
use Overtrue\EasySms\Message;
class SmsChannel
{
/**
* @param \Overtrue\EasySms\EasySms $easySms
*/
public function __construct(
protected EasySms $easySms
) {
}
/**
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return void
*/
public function send($notifiable, Notification $notification): void
{
$message = $notification->toSms($notifiable);
$phone = $notifiable->routeNotificationFor('sms', $notification);
if (! $phone && ! $message instanceof Message) {
return;
}
try {
$this->easySms->send($phone, $message);
} catch (NoGatewayAvailableException $e) {
foreach ($e->getExceptions() as $exception) {
report($exception);
}
}
}
}