From a4cff3a0ed5021f4c68315ca15e0269f84d7c44c Mon Sep 17 00:00:00 2001 From: mahdihty Date: Tue, 16 Mar 2021 19:21:08 +0330 Subject: [PATCH] complete (not test) and some change in sms (channel, message, notification) --- app/Channels/Messages/SmsMessage.php | 8 ++++---- app/Channels/SmsChannel.php | 26 +++++++++++++++++++++----- app/Notifications/SmsNotification.php | 6 +++--- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/Channels/Messages/SmsMessage.php b/app/Channels/Messages/SmsMessage.php index 0d8991f..36f5214 100644 --- a/app/Channels/Messages/SmsMessage.php +++ b/app/Channels/Messages/SmsMessage.php @@ -75,12 +75,12 @@ class SmsMessage /** * Set the params of the sms message when we use ultraFastSend method * - * @param array $params + * @param array|mixed $params * @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]; } return $this; @@ -92,7 +92,7 @@ class SmsMessage * @param string $template_id * @return $this */ - public function templateId(string $template_id) + public function templateId($template_id) { $this->template_id = $template_id; diff --git a/app/Channels/SmsChannel.php b/app/Channels/SmsChannel.php index c54e34a..47ef5d4 100644 --- a/app/Channels/SmsChannel.php +++ b/app/Channels/SmsChannel.php @@ -10,12 +10,26 @@ use GuzzleHttp\Client as HttpClient; class SmsChannel { /** - * The API URL for Socket. + * The API URL for sms. * * @var string */ 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. * @@ -29,10 +43,12 @@ class SmsChannel * @param \GuzzleHttp\Client $http * @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->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)); - if (! $message->to || ! ($message->params && $message->template_id) || ! $message->verification_code) { + if (! $message->to || (! ($message->params && $message->template_id) && ! $message->verification_code)) { return; } @@ -75,8 +91,8 @@ class SmsChannel protected function getToken() { $body = [ - 'UserApiKey' => config('smsirlaravel.api-key'), - 'SecretKey' => config('smsirlaravel.secret-key'), + 'UserApiKey' => $this->api_key, + 'SecretKey' => $this->secret_key, 'System' => 'laravel_v_1_4' ]; diff --git a/app/Notifications/SmsNotification.php b/app/Notifications/SmsNotification.php index 44d5852..773b6ae 100644 --- a/app/Notifications/SmsNotification.php +++ b/app/Notifications/SmsNotification.php @@ -28,10 +28,10 @@ class SmsNotification extends Notification * * @return void */ - public function __construct($message, $type = 'sendVerification') + public function __construct($message, $type = null) { $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) { return (new SmsMessage()) - ->params($this->message['params'] ?? null) + ->params($this->message['params'] ?? []) ->templateId($this->message['template_id'] ?? null) ->verificationCode($this->message['verification_code'] ?? null);