Browse Source

complete (not test) and some change in sms (channel, message, notification)

mahdi
mahdihty 4 years ago
parent
commit
a4cff3a0ed
  1. 8
      app/Channels/Messages/SmsMessage.php
  2. 26
      app/Channels/SmsChannel.php
  3. 6
      app/Notifications/SmsNotification.php

8
app/Channels/Messages/SmsMessage.php

@ -75,12 +75,12 @@ class SmsMessage
/** /**
* Set the params of the sms message when we use ultraFastSend method * Set the params of the sms message when we use ultraFastSend method
* *
* @param array $params
* @param array|mixed $params
* @return $this * @return $this
*/ */
public function params(array $params)
public function params($params)
{ {
foreach ($parameters as $key => $value) {
foreach ($params as $key => $value) {
$this->params[] = ['Parameter' => $key, 'ParameterValue' => $value]; $this->params[] = ['Parameter' => $key, 'ParameterValue' => $value];
} }
return $this; return $this;
@ -92,7 +92,7 @@ class SmsMessage
* @param string $template_id * @param string $template_id
* @return $this * @return $this
*/ */
public function templateId(string $template_id)
public function templateId($template_id)
{ {
$this->template_id = $template_id; $this->template_id = $template_id;

26
app/Channels/SmsChannel.php

@ -10,12 +10,26 @@ use GuzzleHttp\Client as HttpClient;
class SmsChannel class SmsChannel
{ {
/** /**
* The API URL for Socket.
* The API URL for sms.
* *
* @var string * @var string
*/ */
protected $sms_url; protected $sms_url;
/**
* The api key for sms inside sms.ir panel.
*
* @var string
*/
protected $api_key;
/**
* The secret key for sms inside sms.ir panel.
*
* @var string
*/
protected $secret_key;
/** /**
* The HTTP client instance. * The HTTP client instance.
* *
@ -29,10 +43,12 @@ class SmsChannel
* @param \GuzzleHttp\Client $http * @param \GuzzleHttp\Client $http
* @return void * @return void
*/ */
public function __construct(HttpClient $http, string $sms_url)
public function __construct(HttpClient $http, string $sms_url, string $api_key, string $secret_key)
{ {
$this->http = $http; $this->http = $http;
$this->sms_url = $sms_url; $this->sms_url = $sms_url;
$this->api_key = $api_key;
$this->secret_key = $secret_key;
} }
/** /**
@ -49,7 +65,7 @@ class SmsChannel
$message->to($notifiable->routeNotificationFor('sms', $notification)); $message->to($notifiable->routeNotificationFor('sms', $notification));
if (! $message->to || ! ($message->params && $message->template_id) || ! $message->verification_code) {
if (! $message->to || (! ($message->params && $message->template_id) && ! $message->verification_code)) {
return; return;
} }
@ -75,8 +91,8 @@ class SmsChannel
protected function getToken() protected function getToken()
{ {
$body = [ $body = [
'UserApiKey' => config('smsirlaravel.api-key'),
'SecretKey' => config('smsirlaravel.secret-key'),
'UserApiKey' => $this->api_key,
'SecretKey' => $this->secret_key,
'System' => 'laravel_v_1_4' 'System' => 'laravel_v_1_4'
]; ];

6
app/Notifications/SmsNotification.php

@ -28,10 +28,10 @@ class SmsNotification extends Notification
* *
* @return void * @return void
*/ */
public function __construct($message, $type = 'sendVerification')
public function __construct($message, $type = null)
{ {
$this->message = $message; $this->message = $message;
$this->type = $type;
$this->type = $type ?? enum('sms.types.verification_code.name');
} }
/** /**
@ -54,7 +54,7 @@ class SmsNotification extends Notification
public function toSms($notifiable) public function toSms($notifiable)
{ {
return (new SmsMessage()) return (new SmsMessage())
->params($this->message['params'] ?? null)
->params($this->message['params'] ?? [])
->templateId($this->message['template_id'] ?? null) ->templateId($this->message['template_id'] ?? null)
->verificationCode($this->message['verification_code'] ?? null); ->verificationCode($this->message['verification_code'] ?? null);

Loading…
Cancel
Save