From fd806df893a1d38925bf72707ef4a85e52720d7d Mon Sep 17 00:00:00 2001 From: Ariful Date: Wed, 18 Sep 2024 16:30:21 +0600 Subject: [PATCH] SmsBangladesh Gateway Added --- readme.md | 3 ++ src/Config/sms.php | 6 +++ src/Provider/SmartLabSms.php | 25 ++++++--- src/Provider/SmsBangladesh.php | 94 ++++++++++++++++++++++++++++++++++ src/Sender.php | 2 - 5 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 src/Provider/SmsBangladesh.php diff --git a/readme.md b/readme.md index b665f34..3c8f6d8 100644 --- a/readme.md +++ b/readme.md @@ -210,7 +210,10 @@ echo $status = $sender->send(); | OnnoRokomSMS | userName, userPassword, type, maskName, campaignName | - | Done | not tested yet in live | - | | QuickSms | api_key, senderid, type,scheduledDateTime | - | Done | not tested yet in live | - | | RedmoITSms | api_token, sender_id | - | Support closed | - | +| RedmoITSms | api_token, sender_id | - | Support closed | - | | SmartLabSMS | user, password, sender | - | Done | - | - | +| Sms4BD | publickey, privatekey, type,sender, delay | - | Done | - | - | +| SmsBangladesh | user, password, from | - | Done | - | - | | SmsinBD | api_token, senderid | - | Done | | - | | SMS.net.bd | api_key | - | Done | | - | | SmsQ | sender_id, client_id, api_key | - | Done | | - | diff --git a/src/Config/sms.php b/src/Config/sms.php index c6d7b29..824d3dd 100644 --- a/src/Config/sms.php +++ b/src/Config/sms.php @@ -46,6 +46,7 @@ use Xenon\LaravelBDSms\Provider\RedmoItSms; use Xenon\LaravelBDSms\Provider\SmartLabSms; use Xenon\LaravelBDSms\Provider\Sms4BD; +use Xenon\LaravelBDSms\Provider\SmsBangladesh; use Xenon\LaravelBDSms\Provider\SmsinBD; use Xenon\LaravelBDSms\Provider\SmsNet24; use Xenon\LaravelBDSms\Provider\SmsNetBD; @@ -246,6 +247,11 @@ 'sender' => env('SMS_SMS4BD_SENDER', ''), 'delay' => env('SMS_SMS4BD_DELAY', ''), ], + SmsBangladesh::class => [ + 'user' => env('SMS_BANGLADESH_USER', ''), + 'password' => env('SMS_BANGLADESH_PASSWORD', ''), + 'from' => env('SMS_BANGLADESH_FROM', ''), + ], SmsNet24::class => [ 'user_id' => env('SMS_SMSNET24_USER_ID', ''), 'user_password' => env('SMS_SMSNET24_USER_PASSWORD', ''), diff --git a/src/Provider/SmartLabSms.php b/src/Provider/SmartLabSms.php index f3a5a85..d0511d2 100644 --- a/src/Provider/SmartLabSms.php +++ b/src/Provider/SmartLabSms.php @@ -14,12 +14,13 @@ use GuzzleHttp\Exception\GuzzleException; use Xenon\LaravelBDSms\Handler\ParameterException; use Xenon\LaravelBDSms\Handler\RenderException; +use Xenon\LaravelBDSms\Helper\Helper; use Xenon\LaravelBDSms\Request; use Xenon\LaravelBDSms\Sender; class SmartLabSms extends AbstractProvider { - private string $apiEndpoint = 'https://labapi.smartlabsms.com/smsapi'; + private string $apiEndpoint = 'https://labapi.smartlabsms.com'; /** * SmartLabSMS constructor. @@ -36,23 +37,33 @@ public function __construct(Sender $sender) */ public function sendRequest() { - $number = $this->senderObject->getMobile(); + $mobile = $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(); + $tries = $this->senderObject->getTries(); + $backoff = $this->senderObject->getBackoff(); $query = [ 'user' => $config['user'], 'password' => $config['password'], 'sender' => $config['sender'], - 'msisdn' => $number, 'smstext' => $text, ]; - $requestObject = new Request($this->apiEndpoint, $query, $queue, [], $queueName,$tries,$backoff); + if (!is_array($mobile)) { + $this->apiEndpoint .= '/smsapi'; + $query['msisdn'] = Helper::ensureNumberStartsWith88($mobile); + } else { + $this->apiEndpoint .= '/smsapiv2'; + foreach ($mobile as $element) { + $tempMobile[] = Helper::ensureNumberStartsWith88($element); + } + $query['msisdn'] = implode(',', $tempMobile); + } + + $requestObject = new Request($this->apiEndpoint, $query, $queue, [], $queueName, $tries, $backoff); $response = $requestObject->get(); if ($queue) { return true; @@ -61,7 +72,7 @@ public function sendRequest() $body = $response->getBody(); $smsResult = $body->getContents(); - $data['number'] = $number; + $data['number'] = $mobile; $data['message'] = $text; return $this->generateReport($smsResult, $data)->getContent(); } diff --git a/src/Provider/SmsBangladesh.php b/src/Provider/SmsBangladesh.php new file mode 100644 index 0000000..822914c --- /dev/null +++ b/src/Provider/SmsBangladesh.php @@ -0,0 +1,94 @@ +senderObject = $sender; + } + + /** + * @return false|string + * @throws RenderException + * @version v1.0.32 + * @since v1.0.31 + */ + public function sendRequest() + { + $mobile = $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(); + + $formParams = [ + "user" => $config['user'], + "password" => $config['password'], + "from" => $config['from'], + "text" => urlencode($text), + ]; + + if (!is_array($mobile)) { + $formParams['to'] = Helper::ensureNumberStartsWith88($mobile); + } else { + foreach ($mobile as $element) { + $tempMobile[] = Helper::ensureNumberStartsWith88($element); + } + $formParams['to'] = implode(',', $tempMobile); + } + + $requestObject = new Request($this->apiEndpoint, [], $queue, [], $queueName, $tries, $backoff); + $requestObject->setFormParams($formParams); + $response = $requestObject->post(false, 60); + if ($queue) { + return true; + } + + + $body = $response->getBody(); + $smsResult = $body->getContents(); + + $data['number'] = $mobile; + $data['message'] = $text; + return $this->generateReport($smsResult, $data)->getContent(); + } + + /** + * @throws RenderException + * @version v1.0.32 + * @since v1.0.31 + */ + public function errorException() + { + $config = $this->senderObject->getConfig(); + + if (!array_key_exists('user', $config)) { + throw new RenderException('user key is absent in configuration'); + } + + if (!array_key_exists('password', $config)) { + throw new RenderException('password key is absent in configuration'); + } + + if (!array_key_exists('from', $config)) { + throw new RenderException('from key is absent in configuration'); + } + } +} diff --git a/src/Sender.php b/src/Sender.php index 3949a7f..d82457d 100644 --- a/src/Sender.php +++ b/src/Sender.php @@ -244,7 +244,6 @@ public function send() } } - $this->provider->errorException(); $config = Config::get('sms'); @@ -329,7 +328,6 @@ public function getProvider() */ public function setProvider($providerClass): Sender { - try { if (!class_exists($providerClass)) {