diff --git a/readme.md b/readme.md index c32d98e..a5969fb 100644 --- a/readme.md +++ b/readme.md @@ -222,6 +222,7 @@ echo $status = $sender->send(); | TwentyFourBulkSmsBD | customer_id, api_key | - | Done | - | - | | Trubosms | api_token, sender_id | - | Done | - | - | | Viatech | api_key, mask | - | Done | - | - | +| ZamanIT | api_key, senderid,type | - | Done | - | - | diff --git a/src/Config/sms.php b/src/Config/sms.php index f2a33f2..29f7d64 100644 --- a/src/Config/sms.php +++ b/src/Config/sms.php @@ -57,6 +57,7 @@ use Xenon\LaravelBDSms\Provider\Twenty4BulkSms; use Xenon\LaravelBDSms\Provider\TwentyFourBulkSmsBD; use Xenon\LaravelBDSms\Provider\Viatech; +use Xenon\LaravelBDSms\Provider\ZamanIt; return [ /* @@ -297,6 +298,11 @@ 'user_email' => env('SMS_TWENTYFOUR_BULKSMS_USER_EMAIL', ''), 'api_key' => env('SMS_TWENTYFOUR_BULKSMS_APP_KEY', ''), ], + ZamanIt::class => [ + 'api_key' => env('SMS_ZAMANIT_API_KEY', ''), + 'type' => env('SMS_ZAMANIT_TYPE', ''), + 'senderid' => env('SMS_ZAMANIT_SENDER_ID', ''), + ], ] ]; diff --git a/src/Facades/SMS.php b/src/Facades/SMS.php index 9a837d1..b3dd8eb 100644 --- a/src/Facades/SMS.php +++ b/src/Facades/SMS.php @@ -5,7 +5,7 @@ /** * @method static \Xenon\LaravelBDSms\SMS via(string $provider) * @method static mixed shoot(string $mobile, string $text) - * @method static mixed shootWithQueue(string $number, string $text) + * @method static mixed shootWithQueue(string $number, string $text, string $queueName, int $tries, int $backoff) * * @see \Xenon\LaravelBDSms\SMS */ diff --git a/src/Provider/ZamanIt.php b/src/Provider/ZamanIt.php new file mode 100644 index 0000000..eabb9d5 --- /dev/null +++ b/src/Provider/ZamanIt.php @@ -0,0 +1,90 @@ +senderObject = $sender; + } + + /** + * Send Request To Api and Send Message + * @throws RenderException + */ + public function sendRequest() + { + + + $number = $this->senderObject->getMobile(); + $text = $this->senderObject->getMessage(); + $config = $this->senderObject->getConfig(); + $queue = $this->senderObject->getQueue(); + $queueName = $this->senderObject->getQueueName(); + $tries = $this->senderObject->getTries(); + $backoff = $this->senderObject->getBackoff(); + + $query = [ + 'api_key' => $config['api_key'], + 'type' => $config['type'], + 'senderid' => $config['senderid'], + 'phone' => $number, + 'message' => $text, + ]; + + $requestObject = new Request($this->apiEndpoint, $query, $queue, [], $queueName, $tries, $backoff); + + $response = $requestObject->post(); + if ($queue) { + return true; + } + + $body = $response->getBody(); + $smsResult = $body->getContents(); + + $data['phone'] = $number; + $data['message'] = $text; + return $this->generateReport($smsResult, $data)->getContent(); + } + + /** + * @throws ParameterException + */ + public function errorException() + { + if (!array_key_exists('api_key', $this->senderObject->getConfig())) { + throw new ParameterException('api_key is absent in configuration'); + } + + if (!array_key_exists('type', $this->senderObject->getConfig())) { + throw new ParameterException('type key is absent in configuration'); + } + + if (!array_key_exists('senderid', $this->senderObject->getConfig())) { + throw new ParameterException('senderid key is absent in configuration'); + } + + } + +} diff --git a/src/Request.php b/src/Request.php index 4bdee51..4ad96ee 100644 --- a/src/Request.php +++ b/src/Request.php @@ -15,7 +15,7 @@ class Request extends Controller { private bool $queue; - private bool $queueName; + private string $queueName; private string $requestUrl; @@ -29,11 +29,11 @@ class Request extends Controller /** * @var int */ - private int $tries = 3; + private int $tries; /** * @var int */ - private $backoff = 60; + private int $backoff; /** @@ -133,7 +133,7 @@ public function setQueue(bool $queue) /** * @return string */ - public function getRequestUrl() + public function getRequestUrl(): string { return $this->requestUrl; } @@ -149,7 +149,7 @@ public function setRequestUrl($requestUrl): void /** * @return array */ - public function getQuery() + public function getQuery(): array { return $this->query; } diff --git a/src/SMS.php b/src/SMS.php index 16e7d29..2d57cc3 100644 --- a/src/SMS.php +++ b/src/SMS.php @@ -50,18 +50,17 @@ public function shoot(string $number, string $text) * @version v1.0.46-dev * @since v1.0.46-dev */ - public function shootWithQueue(string $number, string $text, ?string $queue, ?int $tries, ?int $backoff) + public function shootWithQueue(string $number, string $text, string $queueName = 'default', int $tries = 3, int $backoff = 60) { $this->sender->setMobile($number); $this->sender->setMessage($text); $this->sender->setQueue(true); - if (isset($queue)){ - $this->sender->setQueueName($queue); - } - if (isset($tries)){ + $this->sender->setQueueName($queueName); + + if (isset($tries)) { $this->sender->setTries($tries); } - if (isset($backoff)){ + if (isset($backoff)) { $this->sender->setBackoff($backoff); } return $this->sender->send();