You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace App\Channels;
use Illuminate\Notifications\Notification; use GuzzleHttp\Client as HttpClient;
class SmsChannel { /** * The API URL for Socket. * * @var string */ protected $sms_url;
/** * The HTTP client instance. * * @var \GuzzleHttp\Client */ protected $http;
/** * Create a new Socket channel instance. * * @param \GuzzleHttp\Client $http * @return void */ public function __construct(HttpClient $http, string $sms_url) { $this->http = $http; $this->sms_url = $sms_url; }
/** * Send the given notification. * * @param mixed $notifiable * @param \Illuminate\Notifications\Notification $notification * @return void */ public function send($notifiable, Notification $notification) { $message = $notification->toSms($notifiable); $type = $notification->getType();
$message->to($notifiable->routeNotificationFor('sms', $notification));
if (! $message->to) { return; }
try { $this->http->post($this->sms_url . 'api/' . $type , [ 'headers' => [ 'x-sms-ir-secure-token'=>self::getToken() ], 'connect_timeout' => 30, 'json' => ['data' => $message->data], ]); } catch (\GuzzleHttp\Exception\ConnectException $e) { report($e); }
} }
|