mahdihty
4 years ago
2 changed files with 81 additions and 18 deletions
@ -0,0 +1,68 @@ |
|||
<?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); |
|||
} |
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue