From b51545840d366846bb3a4498d557d385a96e6a76 Mon Sep 17 00:00:00 2001 From: Hessam Taghvaei Date: Wed, 15 Feb 2023 20:11:39 +0330 Subject: [PATCH] Add new drivers (#920) * feat: add rahyabcp driver * style: fix code style * feat: add rahyabir driver * feat: add d7networks driver * refactor: change rahyabcp driver send method * feat: add from option * feat: add hamyarsms driver * Squashed commit of the following: commit 2eaea22d186a2eea47ea70a4ae273277b27a3884 Author: Laravel Shift Date: Wed Feb 15 11:32:22 2023 -0500 Laravel 10.x Compatibility (#922) * Bump dependencies for Laravel 10 * Update GitHub Actions for Laravel 10 * Drop PHP 8.0 and Use Pint * Remove php8.0 from test workflow --------- Co-authored-by: tzsk commit 4533f046726aef78d76fc8cdd4342aca235f47ff Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed Feb 1 19:34:38 2023 +0000 chore(deps): bump symfony/http-kernel from 6.0.6 to 6.0.20 Bumps [symfony/http-kernel](https://github.com/symfony/http-kernel) from 6.0.6 to 6.0.20. - [Release notes](https://github.com/symfony/http-kernel/releases) - [Changelog](https://github.com/symfony/http-kernel/blob/6.2/CHANGELOG.md) - [Commits](https://github.com/symfony/http-kernel/compare/v6.0.6...v6.0.20) --- updated-dependencies: - dependency-name: symfony/http-kernel dependency-type: indirect ... Signed-off-by: dependabot[bot] commit 363c72f13d6851d73661fbb72dc8032461783286 Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon Jan 30 23:01:47 2023 +0000 chore(deps-dev): bump friendsofphp/php-cs-fixer from 3.13.2 to 3.14.1 Bumps [friendsofphp/php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) from 3.13.2 to 3.14.1. - [Release notes](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases) - [Changelog](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/CHANGELOG.md) - [Commits](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/compare/v3.13.2...v3.14.1) --- updated-dependencies: - dependency-name: friendsofphp/php-cs-fixer dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Apply Pint Fixes * Rename commit message --------- Co-authored-by: tzsk --- .github/workflows/pint.yml | 2 +- README.md | 16 ++- config/sms.php | 44 +++++++- src/Contracts/Driver.php | 10 ++ src/Drivers/D7networks.php | 145 +++++++++++++++++++++++++ src/Drivers/Farazsms.php | 2 +- src/Drivers/Farazsmspattern.php | 2 +- src/Drivers/Ghasedak.php | 2 +- src/Drivers/Hamyarsms.php | 37 +++++++ src/Drivers/Kavenegar.php | 2 +- src/Drivers/LSim.php | 4 +- src/Drivers/Linkmobility.php | 2 +- src/Drivers/Melipayamak.php | 13 ++- src/Drivers/Rahyabcp.php | 38 +++++++ src/Drivers/Rahyabir.php | 143 ++++++++++++++++++++++++ src/Drivers/SabaPayamak.php | 2 +- src/Drivers/Sms77.php | 2 +- src/Drivers/SmsGateway24.php | 2 +- src/Drivers/SmsGatewayMe.php | 2 +- src/Drivers/Smsir.php | 2 +- src/Drivers/Sns.php | 2 +- src/Drivers/Textlocal.php | 2 +- src/Drivers/Tsms.php | 2 +- src/Drivers/Twilio.php | 2 +- src/Helper.php | 1 + tests/Drivers/D7networksTest.php | 16 +++ tests/Drivers/HamyarsmsTest.php | 16 +++ tests/Drivers/RahyabcpTest.php | 16 +++ tests/Drivers/RahyabirTest.php | 16 +++ tests/Mocks/Drivers/MockD7networks.php | 15 +++ tests/Mocks/Drivers/MockHamyarsms.php | 15 +++ tests/Mocks/Drivers/MockRahyabcp.php | 15 +++ tests/Mocks/Drivers/MockRahyabir.php | 15 +++ 33 files changed, 577 insertions(+), 28 deletions(-) create mode 100644 src/Drivers/D7networks.php create mode 100644 src/Drivers/Hamyarsms.php create mode 100644 src/Drivers/Rahyabcp.php create mode 100644 src/Drivers/Rahyabir.php create mode 100644 tests/Drivers/D7networksTest.php create mode 100644 tests/Drivers/HamyarsmsTest.php create mode 100644 tests/Drivers/RahyabcpTest.php create mode 100644 tests/Drivers/RahyabirTest.php create mode 100644 tests/Mocks/Drivers/MockD7networks.php create mode 100644 tests/Mocks/Drivers/MockHamyarsms.php create mode 100644 tests/Mocks/Drivers/MockRahyabcp.php create mode 100644 tests/Mocks/Drivers/MockRahyabir.php diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 6e400ab7..9913cede 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -29,5 +29,5 @@ jobs: - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 with: - commit_message: Apply php-cs Fixes + commit_message: Apply Pint Fixes commit_author: Kazi Ahmed diff --git a/README.md b/README.md index 42f109c8..8b61b6c7 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ List of supported gateways: - [Sms77](https://www.sms77.io) - [SabaPayamak](https://sabapayamak.com) - [LSim](https://sendsms.az/) +- [Rahyabcp](https://rahyabcp.ir/) +- [Rahyabir](https://sms.rahyab.ir/) +- [D7networks](https://d7networks.com/) +- [Hamyarsms](https://hamyarsms.com/) - Others are under way. @@ -69,7 +73,7 @@ Then fill the credentials for that gateway in the drivers array. 'key' => 'Your AWS SNS Access Key', 'secret' => 'Your AWS SNS Secret Key', 'region' => 'Your AWS SNS Region', - 'sender' => 'Your AWS SNS Sender ID', + 'from' => 'Your AWS SNS Sender ID', //sender 'type' => 'Tansactional', // Or: 'Promotional' ], ... @@ -171,6 +175,16 @@ sms()->via('gateway')->send("this message", function($sms) { sms()->via('gateway')->send("this message")->to(['Number 1', 'Number 2'])->dispatch(); +# Change the from|sender|sim value with from() option: + +sms()->via('gateway')->send("this message")->from('Your From Number | Sender Value | Sim Value ')->to(['Number 1', 'Number 2'])->dispatch(); + +# Sending argument and pattern code in pattern drivers such as melipayamakpattern and farazsmspattern. + +#Note: The first argument is always known as the pattern code. + +sms()->via('melipayamakpattern')->send("patterncode=123 \n arg1=name \n arg2=family")->to(['Number 1', 'Number 2'])->dispatch(); + ``` ## :heart_eyes: Channel Usage diff --git a/config/sms.php b/config/sms.php index adcd4f06..cff80447 100644 --- a/config/sms.php +++ b/config/sms.php @@ -28,14 +28,14 @@ 'key' => 'Your AWS SNS Access Key', 'secret' => 'Your AWS SNS Secret Key', 'region' => 'Your AWS SNS Region', - 'sender' => 'Your AWS SNS Sender ID', + 'from' => 'Your AWS SNS Sender ID', // sender 'type' => 'Transactional', // Or: 'Promotional' ], 'textlocal' => [ 'url' => 'http://api.textlocal.in/send/', // Country Wise this may change. 'username' => 'Your Username', 'hash' => 'Your Hash', - 'sender' => 'Sender Name', + 'from' => 'Sender Name', // sender ], // Install: composer require twilio/sdk 'twilio' => [ @@ -51,7 +51,7 @@ 'url' => 'http://simple.pswin.com', // Country Wise this may change. 'username' => 'Your Username', 'password' => 'Your Password', - 'sender' => 'Sender name', + 'from' => 'Sender name', // sender ], // Install: composer require melipayamak/php 'melipayamak' => [ @@ -101,7 +101,7 @@ 'url' => 'https://smsgateway24.com/getdata/addsms', 'token' => 'Your Api Token', 'deviceid' => 'Your Default Device ID', - 'sim' => 'Device SIM Slot. 0 or 1', + 'from' => 'Device SIM Slot. 0 or 1', // sim ], 'ghasedak' => [ 'url' => 'http://api.iransmsservice.com', @@ -124,7 +124,37 @@ 'lsim' => [ 'username' => 'Your LSIM login', 'password' => 'Your LSIM password', - 'sender' => 'Your LSIM Sender ID', + 'from' => 'Your LSIM Sender ID', // sender + ], + 'rahyabcp' => [ + 'url' => 'https://p.1000sms.ir/Post/Send.asmx?wsdl', + 'username' => 'Your Rahyabcp login', + 'password' => 'Your Rahyabcp password', + 'from' => 'Your Default From Number', + 'flash' => false, + ], + 'rahyabir' => [ + 'url' => 'https://api.rahyab.ir', + 'username' => 'Your Rahyabir Username', + 'password' => 'Your Rahyabir Password', + 'company' => 'Your Rahyabir Company', + 'from' => 'Your Default From Number', + 'token_valid_day' => 1, + ], + 'd7networks' => [ + 'url' => 'https://api.d7networks.com', + 'username' => 'Your D7networks ClientId', + 'password' => 'Your D7networks clientSecret', + 'originator' => 'SignOTP', + 'report_url' => '', + 'token_valid_day' => 1, + ], + 'hamyarsms' => [ + 'url' => 'http://payamakapi.ir/SendService.svc?singleWsdl', + 'username' => 'Your Hamyarsms Username', + 'password' => 'Your Hamyarsms Password', + 'from' => 'Your Default From Number', + 'flash' => false, ], ], @@ -158,5 +188,9 @@ 'sms77' => \Tzsk\Sms\Drivers\Sms77::class, 'sabapayamak' => \Tzsk\Sms\Drivers\SabaPayamak::class, 'lsim' => \Tzsk\Sms\Drivers\LSim::class, + 'rahyabcp' => \Tzsk\Sms\Drivers\Rahyabcp::class, + 'rahyabir' => \Tzsk\Sms\Drivers\Rahyabir::class, + 'd7networks' => \Tzsk\Sms\Drivers\D7networks::class, + 'hamyarsms' => \Tzsk\Sms\Drivers\Hamyarsms::class, ], ]; diff --git a/src/Contracts/Driver.php b/src/Contracts/Driver.php index 7f928747..4d8741e7 100644 --- a/src/Contracts/Driver.php +++ b/src/Contracts/Driver.php @@ -12,9 +12,12 @@ abstract class Driver protected string $body = ''; + protected ?string $sender = ''; + public function __construct(array $settings) { $this->settings = $settings; + $this->from(data_get($settings, 'from')); $this->boot(); } @@ -35,6 +38,13 @@ public function to($numbers): self return $this; } + public function from(?string $sender): self + { + $this->sender = $sender; + + return $this; + } + public function message(string $message): self { $message = trim($message); diff --git a/src/Drivers/D7networks.php b/src/Drivers/D7networks.php new file mode 100644 index 00000000..248b3ec7 --- /dev/null +++ b/src/Drivers/D7networks.php @@ -0,0 +1,145 @@ +baseUrl = trim($this->settings['url'], '/'); + $this->username = $this->settings['username']; + $this->password = $this->settings['password']; + $this->token = cache('d7networks_token'); + } + + public function send() + { + if (empty($this->token)) { + $this->login(); + } + + if (count($this->recipients) > 200) { + throw new InvalidMessageException('Recipients cannot be more than 100 numbers.'); + } + + $response = Http::withToken($this->token)->withHeaders($this->getHttpHeaders()) + ->post($this->getSendSmsApiUrl(), [ + 'messages' => [ + 'channel' => 'sms', + 'recipients' => $this->recipients, + 'content' => $this->body, + 'msg_type' => 'text', + 'data_coding' => $this->getDataCoding($this->body), + ], + 'message_globals' => [ + 'originator' => data_get($this->settings, 'originator'), + 'report_url' => data_get($this->settings, 'report_url'), + ], + ]); + + $response = $response->json(); + + if (isset($response['detail']['code'])) { + cache()->forget('rahyabir_token'); + + return $this->send(); + } + + if (! isset($response['detail'])) { + return $response; + } + + throw new InvalidMessageException(json_encode($response)); + } + + private function login(): void + { + $this->validateConfiguration(); + + $response = Http::post($this->getLoginApiUrl(), [ + 'client_id' => $this->username, + 'client_secret' => $this->password, + ]); + + $response = $response->json(); + + if (isset($response['detail'])) { + $error = $response['detail']; + + throw new InvalidMessageException($error['message'], $error['code']); + } + + $token = $response['access_token']; + + cache([ + 'd7networks_token' => $token, + ], now()->addDays($this->getTokenValidDay())); + + $this->token = $token; + } + + private function validateConfiguration(): void + { + if (empty($this->baseUrl)) { + throw new InvalidSmsConfigurationException('d7networks config not found: api base url'); + } + + if (empty($this->username)) { + throw new InvalidSmsConfigurationException('d7networks config not found: username'); + } + + if (empty($this->password)) { + throw new InvalidSmsConfigurationException('d7networks config not found: password'); + } + + if (empty($this->number)) { + throw new InvalidSmsConfigurationException('d7networks config not found: from number'); + } + } + + private function getErrorMessage(array $errors) + { + return array_shift($errors)['message']; + } + + private function getLoginApiUrl(): string + { + return $this->baseUrl.'/auth/v1/login/application'; + } + + private function getSendSmsApiUrl(): string + { + return $this->baseUrl.'/messages/v1/send'; + } + + private function getTokenValidDay() + { + return $this->settings['token_valid_day']; + } + + private function getHttpHeaders(): array + { + return [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + } + + private function getDataCoding(string $string): string + { + return strlen($string) != strlen(utf8_decode($string)) ? 'text' : 'auto'; + } +} diff --git a/src/Drivers/Farazsms.php b/src/Drivers/Farazsms.php index 402100a3..df279ab0 100644 --- a/src/Drivers/Farazsms.php +++ b/src/Drivers/Farazsms.php @@ -36,7 +36,7 @@ protected function payload($recipient): array 'form_params' => [ 'uname' => data_get($this->settings, 'username'), 'pass' => data_get($this->settings, 'password'), - 'from' => data_get($this->settings, 'from'), + 'from' => $this->sender, 'message' => $this->body, 'to' => json_encode([$recipient]), 'op' => 'send', diff --git a/src/Drivers/Farazsmspattern.php b/src/Drivers/Farazsmspattern.php index 4ae19732..1e040205 100644 --- a/src/Drivers/Farazsmspattern.php +++ b/src/Drivers/Farazsmspattern.php @@ -42,7 +42,7 @@ protected function payload($recipient): array return [ 'username' => data_get($this->settings, 'username'), 'password' => data_get($this->settings, 'password'), - 'from' => data_get($this->settings, 'from'), + 'from' => $this->sender, 'to' => json_encode([$recipient]), 'pattern_code' => $pattern_code, 'input_data' => json_encode($input_data), diff --git a/src/Drivers/Ghasedak.php b/src/Drivers/Ghasedak.php index 98d80a91..9a96511d 100644 --- a/src/Drivers/Ghasedak.php +++ b/src/Drivers/Ghasedak.php @@ -26,7 +26,7 @@ public function send() [ 'form_params' => [ 'Receptor' => $recipient, - 'sender' => $this->settings['from'], + 'sender' => $this->sender, 'message' => $this->body, ], 'headers' => [ diff --git a/src/Drivers/Hamyarsms.php b/src/Drivers/Hamyarsms.php new file mode 100644 index 00000000..c04954da --- /dev/null +++ b/src/Drivers/Hamyarsms.php @@ -0,0 +1,37 @@ +client = new SoapClient(data_get($this->settings, 'url')); + } + + public function send() + { + if (count($this->recipients) > 100) { + throw new InvalidMessageException('Recipients cannot be more than 100 numbers.'); + } + + $response = $this->client->SendSMS([ + 'userName' => data_get($this->settings, 'username'), + 'password' => data_get($this->settings, 'password'), + 'fromNumber' => $this->sender, + 'toNumbers' => $this->recipients, + 'messageContent' => $this->body, + 'isFlash' => data_get($this->settings, 'flash'), + 'recId' => [0], + 'status' => 0x0, + ]); + + return $response; + } +} diff --git a/src/Drivers/Kavenegar.php b/src/Drivers/Kavenegar.php index dac8d154..85fc01b0 100644 --- a/src/Drivers/Kavenegar.php +++ b/src/Drivers/Kavenegar.php @@ -21,7 +21,7 @@ public function send() foreach ($this->recipients as $recipient) { $response->put( $recipient, - $this->client->Send(data_get($this->settings, 'from'), $recipient, $this->body) + $this->client->Send($this->sender, $recipient, $this->body) ); } diff --git a/src/Drivers/LSim.php b/src/Drivers/LSim.php index 9af9cc60..5eb8ab79 100644 --- a/src/Drivers/LSim.php +++ b/src/Drivers/LSim.php @@ -17,7 +17,7 @@ public function send() 'login' => data_get($this->settings, 'username'), 'msisdn' => $recipient, 'text' => $this->body, - 'sender' => data_get($this->settings, 'sender'), + 'sender' => $this->sender, 'key' => $this->getKey($this->body, $recipient), ]); @@ -36,7 +36,7 @@ private function getKey(string $message, string $number): string .data_get($this->settings, 'username') .$message .$number - .data_get($this->settings, 'sender') + .$this->sender ); } } diff --git a/src/Drivers/Linkmobility.php b/src/Drivers/Linkmobility.php index 71fa8719..2dca5cdd 100644 --- a/src/Drivers/Linkmobility.php +++ b/src/Drivers/Linkmobility.php @@ -36,7 +36,7 @@ protected function payload($recipient): array 'USER' => data_get($this->settings, 'username'), 'PW' => data_get($this->settings, 'password'), 'RCV' => $recipient, - 'SND' => urlencode(data_get($this->settings, 'sender')), + 'SND' => urlencode($this->sender), 'TXT' => $this->body, ], ]; diff --git a/src/Drivers/Melipayamak.php b/src/Drivers/Melipayamak.php index a8ee9a95..935f9d89 100644 --- a/src/Drivers/Melipayamak.php +++ b/src/Drivers/Melipayamak.php @@ -28,12 +28,15 @@ public function send() { $response = collect(); foreach ($this->recipients as $recipient) { - $response->put($recipient, $this->client->sms()->send( + $response->put( $recipient, - data_get($this->settings, 'from'), - $this->body, - data_get($this->settings, 'flash') - )); + $this->client->sms()->send( + $recipient, + $this->sender, + $this->body, + data_get($this->settings, 'flash') + ) + ); } return (count($this->recipients) == 1) ? $response->first() : $response; diff --git a/src/Drivers/Rahyabcp.php b/src/Drivers/Rahyabcp.php new file mode 100644 index 00000000..bf83983d --- /dev/null +++ b/src/Drivers/Rahyabcp.php @@ -0,0 +1,38 @@ +client = new SoapClient(data_get($this->settings, 'url')); + } + + public function send() + { + if (count($this->recipients) > 100) { + throw new InvalidMessageException('Recipients cannot be more than 100 numbers.'); + } + + $response = $this->client->SendSms([ + 'username' => data_get($this->settings, 'username'), + 'password' => data_get($this->settings, 'password'), + 'from' => $this->sender, + 'to' => $this->recipients, + 'text' => $this->body, + 'isflash' => data_get($this->settings, 'flash'), + 'udh' => '', + 'recId' => [0], + 'status' => [0], + ]); + + return $response; + } +} diff --git a/src/Drivers/Rahyabir.php b/src/Drivers/Rahyabir.php new file mode 100644 index 00000000..0836cdcd --- /dev/null +++ b/src/Drivers/Rahyabir.php @@ -0,0 +1,143 @@ +baseUrl = trim($this->settings['url'], '/'); + $this->username = $this->settings['username']; + $this->password = $this->settings['password']; + $this->number = $this->sender; + $this->company = $this->settings['company']; + $this->token = cache('rahyabir_token'); + } + + public function send() + { + if (empty($this->token)) { + $this->login(); + } + + if (count($this->recipients) > 100) { + throw new InvalidMessageException('Recipients cannot be more than 100 numbers.'); + } + + $response = Http::withToken($this->token)->withHeaders($this->getHttpHeaders()) + ->post($this->getSendSmsApiUrl(), [ + 'message' => $this->body, + 'destinationAddress' => $this->recipients, + 'number' => $this->number, + 'userName' => $this->username, + 'password' => $this->password, + 'company' => $this->company, + ]); + + $jsonResponse = $response->json(); + + if ($response->status() == 401) { + cache()->forget('rahyabir_token'); + + return $this->send(); + } + + if ($this->isResponseValid($jsonResponse)) { + return $jsonResponse; + } + + throw new InvalidMessageException(json_encode($jsonResponse), $response->status()); + } + + private function login(): void + { + $this->validateConfiguration(); + + $response = Http::post($this->getLoginApiUrl(), [ + 'userName' => "{$this->username}@{$this->company}", + 'password' => $this->password, + 'company' => $this->company, + ]); + + $responseBody = $response->body(); + $responsejson = $response->json(); + + if (isset($responsejson['status'])) { + throw new InvalidMessageException($responsejson['title'], $responsejson['status']); + } + + cache([ + 'rahyabir_token' => $responseBody, + ], now()->addDays($this->getTokenValidDay())); + + $this->token = $responseBody; + } + + private function validateConfiguration(): void + { + if (empty($this->baseUrl)) { + throw new InvalidSmsConfigurationException('rahyabir config not found: api base url'); + } + + if (empty($this->username)) { + throw new InvalidSmsConfigurationException('rahyabir config not found: username'); + } + + if (empty($this->password)) { + throw new InvalidSmsConfigurationException('rahyabir config not found: password'); + } + + if (empty($this->company)) { + throw new InvalidSmsConfigurationException('rahyabir config not found: company'); + } + + if (empty($this->number)) { + throw new InvalidSmsConfigurationException('rahyabir config not found: from number'); + } + } + + private function isResponseValid(array $response): bool + { + return isset($response[0]['submitResponse']) && isset($response[0]['submitResponse']); + } + + private function getLoginApiUrl(): string + { + return $this->baseUrl.'/api/Auth/getToken'; + } + + private function getSendSmsApiUrl(): string + { + return $this->baseUrl.'/api/v1/SendSMS_Batch'; + } + + private function getTokenValidDay() + { + return $this->settings['token_valid_day']; + } + + private function getHttpHeaders(): array + { + return [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + } +} diff --git a/src/Drivers/SabaPayamak.php b/src/Drivers/SabaPayamak.php index 0e5e7793..938397fe 100644 --- a/src/Drivers/SabaPayamak.php +++ b/src/Drivers/SabaPayamak.php @@ -24,7 +24,7 @@ protected function boot(): void $this->baseUrl = trim($this->settings['url'], '/'); $this->username = $this->settings['username']; $this->password = $this->settings['password']; - $this->virtualNumber = $this->settings['from']; + $this->virtualNumber = $this->sender; $this->token = cache('sabapayamak_token'); } diff --git a/src/Drivers/Sms77.php b/src/Drivers/Sms77.php index 029e0f35..1e29158a 100644 --- a/src/Drivers/Sms77.php +++ b/src/Drivers/Sms77.php @@ -30,7 +30,7 @@ public function send() $response = collect(); $params = (new SmsParams) ->setFlash(data_get($this->settings, 'flash')) - ->setFrom(data_get($this->settings, 'from')) + ->setFrom($this->sender) ->setText($this->body); foreach ($this->recipients as $recipient) { diff --git a/src/Drivers/SmsGateway24.php b/src/Drivers/SmsGateway24.php index f7ce1cfd..7f4b3a55 100644 --- a/src/Drivers/SmsGateway24.php +++ b/src/Drivers/SmsGateway24.php @@ -38,7 +38,7 @@ protected function payload($recipient): array 'sendto' => $recipient, 'body' => $this->body, 'device_id' => data_get($this->settings, 'deviceid'), - 'sim' => data_get($this->settings, 'sim'), + 'sim' => $this->sender, ], ]; } diff --git a/src/Drivers/SmsGatewayMe.php b/src/Drivers/SmsGatewayMe.php index 95639361..5d4fef60 100644 --- a/src/Drivers/SmsGatewayMe.php +++ b/src/Drivers/SmsGatewayMe.php @@ -42,7 +42,7 @@ protected function payload($recipient): SendMessageRequest return new SendMessageRequest([ 'phoneNumber' => $recipient, 'message' => $this->body, - 'deviceId' => data_get($this->settings, 'from'), + 'deviceId' => $this->sender, ]); } } diff --git a/src/Drivers/Smsir.php b/src/Drivers/Smsir.php index 565a3f97..51e8dd53 100644 --- a/src/Drivers/Smsir.php +++ b/src/Drivers/Smsir.php @@ -44,7 +44,7 @@ protected function payload($recipient, $token) 'json' => [ 'Messages' => [$this->body], 'MobileNumbers' => [$recipient], - 'LineNumber' => data_get($this->settings, 'from'), + 'LineNumber' => $this->sender, ], 'headers' => [ 'x-sms-ir-secure-token' => $token, diff --git a/src/Drivers/Sns.php b/src/Drivers/Sns.php index bcc0c8b3..1fad8cc5 100644 --- a/src/Drivers/Sns.php +++ b/src/Drivers/Sns.php @@ -43,7 +43,7 @@ protected function payload($recipient): array 'MessageAttributes' => [ 'AWS.SNS.SMS.SenderID' => [ 'DataType' => 'String', - 'StringValue' => data_get($this->settings, 'sender'), + 'StringValue' => $this->sender, ], 'AWS.SNS.SMS.SMSType' => [ 'DataType' => 'String', diff --git a/src/Drivers/Textlocal.php b/src/Drivers/Textlocal.php index 1485e039..ecd20656 100644 --- a/src/Drivers/Textlocal.php +++ b/src/Drivers/Textlocal.php @@ -36,7 +36,7 @@ public function payload($recipient): array 'username' => data_get($this->settings, 'username'), 'hash' => data_get($this->settings, 'hash'), 'numbers' => $recipient, - 'sender' => urlencode(data_get($this->settings, 'sender')), + 'sender' => urlencode($this->sender), 'message' => $this->body, ], ]; diff --git a/src/Drivers/Tsms.php b/src/Drivers/Tsms.php index 03af5d4f..75fc905d 100644 --- a/src/Drivers/Tsms.php +++ b/src/Drivers/Tsms.php @@ -22,7 +22,7 @@ public function send() $result = $this->client->sendSms( data_get($this->settings, 'username'), data_get($this->settings, 'password'), - [data_get($this->settings, 'from')], + [$this->sender], [$recipient], [$this->body], [], diff --git a/src/Drivers/Twilio.php b/src/Drivers/Twilio.php index 801dd7c7..571ae5e8 100644 --- a/src/Drivers/Twilio.php +++ b/src/Drivers/Twilio.php @@ -23,7 +23,7 @@ public function send() */ $result = $this->client->account->messages->create( $recipient, - ['from' => data_get($this->settings, 'from'), 'body' => $this->body] + ['from' => $this->sender, 'body' => $this->body] ); $response->put($recipient, $result); diff --git a/src/Helper.php b/src/Helper.php index 48d9930a..c0389ec5 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -3,6 +3,7 @@ if (! function_exists('sms')) { /** * Access SmsManager through helper. + * * @return \Tzsk\Sms\Sms */ function sms() diff --git a/tests/Drivers/D7networksTest.php b/tests/Drivers/D7networksTest.php new file mode 100644 index 00000000..20d32460 --- /dev/null +++ b/tests/Drivers/D7networksTest.php @@ -0,0 +1,16 @@ +