-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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 2eaea22 Author: Laravel Shift <[email protected]> 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 <[email protected]> commit 4533f04 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](symfony/http-kernel@v6.0.6...v6.0.20) --- updated-dependencies: - dependency-name: symfony/http-kernel dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> commit 363c72f 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](PHP-CS-Fixer/PHP-CS-Fixer@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] <[email protected]> * Apply Pint Fixes * Rename commit message --------- Co-authored-by: tzsk <[email protected]>
- Loading branch information
Showing
33 changed files
with
577 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
|
||
namespace Tzsk\Sms\Drivers; | ||
|
||
use Illuminate\Support\Facades\Http; | ||
use Tzsk\Sms\Contracts\Driver; | ||
use Tzsk\Sms\Exceptions\InvalidMessageException; | ||
use Tzsk\Sms\Exceptions\InvalidSmsConfigurationException; | ||
|
||
class D7networks extends Driver | ||
{ | ||
private ?string $baseUrl; | ||
|
||
private ?string $username; | ||
|
||
private ?string $password; | ||
|
||
private ?string $token; | ||
|
||
protected function boot(): void | ||
{ | ||
$this->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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Tzsk\Sms\Drivers; | ||
|
||
use SoapClient; | ||
use Tzsk\Sms\Contracts\Driver; | ||
use Tzsk\Sms\Exceptions\InvalidMessageException; | ||
|
||
class Hamyarsms extends Driver | ||
{ | ||
protected SoapClient $client; | ||
|
||
protected function boot(): void | ||
{ | ||
$this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.