allow vendord
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s

This commit is contained in:
2026-03-30 14:54:57 +07:00
parent 66aed7c4e8
commit b5e3a778ce
21316 changed files with 2777892 additions and 13 deletions

16
vendor/tzsk/sms/CHANGELOG.md vendored Normal file
View File

@@ -0,0 +1,16 @@
# Changelog
All notable changes to `sms` will be documented in this file
## 5.1.0
- Farazsmspattern gateway added.
- Melipayamakpattern gateway added.
## 5.0.0
- Laravel 8 Support
- Removed Nexmo. (Already supported in Laravel)
- Renamed Driver namespace
- New Publish Command
- Github actions

21
vendor/tzsk/sms/LICENSE.md vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Tzsk <mailtokmahmed@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

350
vendor/tzsk/sms/README.md vendored Normal file
View File

@@ -0,0 +1,350 @@
# :gift: Laravel SMS Gateway
![SMS Cover](resources/sms.svg)
![GitHub License](https://img.shields.io/github/license/tzsk/sms?style=for-the-badge)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/tzsk/sms.svg?style=for-the-badge&logo=composer)](https://packagist.org/packages/tzsk/sms)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/tzsk/sms/tests.yml?branch=master&label=tests&style=for-the-badge&logo=github)](https://github.com/tzsk/sms/actions?query=workflow%3ATests+branch%3Amaster)
[![Total Downloads](https://img.shields.io/packagist/dt/tzsk/sms.svg?style=for-the-badge&logo=laravel)](https://packagist.org/packages/tzsk/sms)
This is a Laravel Package for SMS Gateway Integration. Now Sending SMS is easy.
List of supported gateways:
- [AWS SNS](https://aws.amazon.com/sns/)
- [Textlocal](http://textlocal.in)
- [Twilio](https://www.twilio.com)
- [Clockwork](https://www.clockworksms.com/)
- [LINK Mobility](https://www.linkmobility.com)
- [Kavenegar](https://kavenegar.com)
- [Melipayamak](https://www.melipayamak.com)
- [Melipayamakpattern](https://www.melipayamak.com)
- [Smsir](https://www.sms.ir)
- [Tsms](http://www.tsms.ir)
- [Farazsms](https://farazsms.com)
- [Farazsmspattern](https://farazsms.com)
- [SMS Gateway Me](https://smsgateway.me)
- [SmsGateWay24](https://smsgateway24.com/en)
- [Ghasedak](https://ghasedaksms.com/)
- [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/)
- [SMSApi](https://www.smsapi.si/)
- Others are under way.
## :package: Install
Via Composer
```bash
$ composer require tzsk/sms
```
## :zap: Configure
Publish the config file
```bash
$ php artisan sms:publish
```
In the config file you can set the default driver to use for all your SMS. But you can also change the driver at
runtime.
Choose what gateway you would like to use for your application. Then make that as default driver so that you don't have
to specify that everywhere. But, you can also use multiple gateways in a project.
```php
// Eg. if you want to use SNS.
'default' => 'sns',
```
Then fill the credentials for that gateway in the drivers array.
```php
// Eg. for SNS.
'drivers' => [
'sns' => [
// Fill all the credentials here.
'key' => 'Your AWS SNS Access Key',
'secret' => 'Your AWS SNS Secret Key',
'region' => 'Your AWS SNS Region',
'from' => 'Your AWS SNS Sender ID', //sender
'type' => 'Tansactional', // Or: 'Promotional'
],
...
]
```
#### Textlocal Configuration:
Textlocal is added by default. You just have to change the creadentials in the `textlocal` driver section.
#### AWS SNS Configuration:
In case you want to use AWS SNS. Then you have to pull a composer library first.
```bash
composer require aws/aws-sdk-php
```
#### Clockwork Configuration:
In case you want to use Clockwork. Then you have to pull a composer library first.
```bash
composer require mediaburst/clockworksms
```
#### Twilio Configuration:
In case you want to use Twilio. Then you have to pull a composer library first.
```bash
composer require twilio/sdk
```
Then you just have to change the creadentials in the `twilio` driver section.
#### Melipayamak or Melipayamakpattern Configuration:
In case you want to use Melipayamak or Melipayamakpattern, Then you have to pull a composer library first.
```bash
composer require melipayamak/php
```
#### Kavenegar Configuration:
In case you want to use Kavenegar. Then you have to pull a composer library first.
```bash
composer require kavenegar/php
```
#### SMS Gateway Me Configuration:
In case you want to use SMS Gateway Me. Then you have to pull a composer library first.
```bash
composer require smsgatewayme/client
```
## :fire: Usage
In your code just use it like this.
```php
# On the top of the file.
use Tzsk\Sms\Facades\Sms;
////
# In your Controller.
Sms::send("this message", function($sms) {
$sms->to(['Number 1', 'Number 2']); # The numbers to send to.
});
# OR...
Sms::send("this message")->to(['Number 1', 'Number 2'])->dispatch();
# If you want to use a different driver.
Sms::via('gateway')->send("this message", function($sms) {
$sms->to(['Number 1', 'Number 2']);
});
# OR...
Sms::via('gateway')->send("this message")->to(['Number 1', 'Number 2'])->dispatch();
# Here gateway is explicit : 'twilio' or 'textlocal' or any other driver in the config.
# The numbers can be a single string as well.
# If you are not a Laravel's facade fan, you can use sms helper:
sms()->send("this message", function($sms) {
$sms->to(['Number 1', 'Number 2']); # The numbers to send to.
});
sms()->send("this message")->to(['Number 1', 'Number 2'])->dispatch();
sms()->via('gateway')->send("this message", function($sms) {
$sms->to(['Number 1', 'Number 2']);
});
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
First you have to create your notification using `php artisan make:notification` command. then `SmsChannel::class` can
be used as channel like the below:
```php
namespace App\Notifications;
use Tzsk\Sms\Builder;
use Illuminate\Bus\Queueable;
use Tzsk\Sms\Channels\SmsChannel;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
class InvoicePaid extends Notification
{
use Queueable;
/**
* Get the notification channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return [SmsChannel::class];
}
/**
* Get the repicients and body of the notification.
*
* @param mixed $notifiable
* @return Builder
*/
public function toSms($notifiable)
{
return (new Builder)->via('gateway') # via() is Optional
->send('this message')
->to('some number');
}
}
```
> **Tip:** You can use the same Builder Instance in the send method.
```php
$builder = (new Builder)->via('gateway') # via() is Optional
->send('this message')
->to('some number');
Sms::send($builder);
# OR...
$builder = (new Builder)->send('this message')
->to(['some number']);
Sms::via('gateway')->send($builder);
```
#### Custom Made Driver, How To:
First you have to name your driver in the drivers array ,and also specify any config params you want.
```php
'drivers' => [
'textlocal' => [...],
'twilio' => [...],
'my_driver' => [
... # Your Config Params here.
]
]
```
Now you have to create a Driver Map Class that will be used to send the SMS. In your driver, You just have to
extend `Tzsk\Sms\Contracts\Driver`.
Ex. You created a class : `App\Packages\SMSDriver\MyDriver`.
```php
namespace App\Packages\SMSDriver;
use Tzsk\Sms\Contracts\Driver;
class MyDriver extends Driver
{
/**
* You Should implement these methods:
*
* 1. boot() -> (optional) Initialize any variable or configuration that you need.
* 2. send() -> Main method to send messages.
*
* Note: settings array will be automatically assigned in Driver class' constructor.
*
* Example Given below:
*/
/**
* @var mixed
*/
protected $client;
protected function boot() : void
{
$this->client = new Client(); # Guzzle Client for example.
}
/**
* @return object Ex.: (object) ['status' => true, 'data' => 'Client Response Data'];
*/
public function send()
{
$this->recipients; # Array of Recipients.
$this->body; # SMS Body.
# Main logic of Sending SMS.
...
}
}
```
Once you crate that class you have to specify it in the `sms.php` Config file `map` section.
```php
'map' => [
...
'my_driver' => App\Packages\SMSDriver\MyDriver::class,
]
```
**Note:-** You have to make sure that the key of the `map` array is identical to the key of the `drivers` array.
## :microscope: Testing
```bash
composer test
```
## :date: Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## :heart: Contributing
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
## :lock: Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## :crown: Credits
- [Kazi Ahmed](https://github.com/tzsk)
- [All Contributors](../../contributors)
## :policeman: License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

82
vendor/tzsk/sms/composer.json vendored Normal file
View File

@@ -0,0 +1,82 @@
{
"name": "tzsk/sms",
"description": "Laravel SMS Gateway Integration Package",
"keywords": [
"tzsk",
"sms",
"laravel sms gateway",
"laravel textlocal",
"laravel twilio",
"laravel link mobility",
"laravel kavenegar",
"laravel melipayamak",
"laravel smsir",
"laravel tsms",
"laravel farazsms",
"laravel SmsGateWay24",
"laravel SMS gateway me"
],
"homepage": "https://github.com/tzsk/sms",
"license": "MIT",
"authors": [
{
"name": "Kazi Ahmed",
"email": "mailtokmahmed@gmail.com",
"homepage": "https://github.com/tzsk",
"role": "Developer"
}
],
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.0",
"illuminate/http": "^8.0|^9.0|^10.0|^11.0|^12.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0"
},
"require-dev": {
"aws/aws-sdk-php": "^3.87",
"kavenegar/php": "^1.2",
"laravel/legacy-factories": "^1.0",
"laravel/pint": "^1.5",
"mediaburst/clockworksms": "^2.0",
"melipayamak/php": "^1.0.0",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0|^10.0",
"phpunit/phpunit": "^9.3|^10.5|^11.5.3",
"sms77/api": "^v2.4.0",
"smsgatewayme/client": "^0.0.1",
"twilio/sdk": "^7.3|^8.3",
"vimeo/psalm": "^5.0|^6.6"
},
"autoload": {
"psr-4": {
"Tzsk\\Sms\\": "src"
},
"files": [
"src/Helper.php"
]
},
"autoload-dev": {
"psr-4": {
"Tzsk\\Sms\\Tests\\": "tests"
}
},
"scripts": {
"psalm": "vendor/bin/psalm",
"test": "vendor/bin/phpunit --colors=always",
"format": "vendor/bin/pint"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Tzsk\\Sms\\SmsServiceProvider"
],
"aliases": {
"Sms": "Tzsk\\Sms\\Facades\\Sms"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

9833
vendor/tzsk/sms/composer.lock generated vendored Normal file

File diff suppressed because it is too large Load Diff

204
vendor/tzsk/sms/config/sms.php vendored Normal file
View File

@@ -0,0 +1,204 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Driver
|--------------------------------------------------------------------------
|
| This value determines which of the following gateway to use.
| You can switch to a different driver at runtime.
|
*/
'default' => env('SMS_DRIVER', 'textlocal'),
/*
|--------------------------------------------------------------------------
| List of Drivers
|--------------------------------------------------------------------------
|
| These are the list of drivers to use for this package.
| You can change the name. Then you'll have to change
| it in the map array too.
|
*/
'drivers' => [
// Install: composer require aws/aws-sdk-php
'sns' => [
'key' => 'Your AWS SNS Access Key',
'secret' => 'Your AWS SNS Secret Key',
'region' => 'Your AWS SNS Region',
'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',
'from' => 'Sender Name', // sender
],
// Install: composer require twilio/sdk
'twilio' => [
'sid' => 'Your SID',
'token' => 'Your Token',
'from' => 'Your Default From Number',
],
// Install: composer require mediaburst/clockworksms
'clockwork' => [
'key' => 'Your clockwork API Key',
],
'linkmobility' => [
'url' => 'http://simple.pswin.com', // Country Wise this may change.
'username' => 'Your Username',
'password' => 'Your Password',
'from' => 'Sender name', // sender
],
// Install: composer require melipayamak/php
'melipayamak' => [
'username' => 'Your Username',
'password' => 'Your Password',
'from' => 'Your Default From Number',
'flash' => false,
],
'melipayamakpattern' => [
'username' => 'Your Username',
'password' => 'Your Password',
],
// Install: composer require kavenegar/php
'kavenegar' => [
'apiKey' => 'Your Api Key',
'from' => 'Your Default From Number',
],
'smsir' => [
'url' => 'https://ws.sms.ir/',
'apiKey' => 'Your Api Key',
'secretKey' => 'Your Secret Key',
'from' => 'Your Default From Number',
],
'tsms' => [
'url' => 'http://www.tsms.ir/soapWSDL/?wsdl',
'username' => 'Your Username',
'password' => 'Your Password',
'from' => 'Your Default From Number',
],
'farazsms' => [
'url' => '188.0.240.110/services.jspd',
'username' => 'Your Username',
'password' => 'Your Password',
'from' => 'Your Default From Number',
],
'farazsmspattern' => [
'url' => 'http://ippanel.com/patterns/pattern',
'username' => 'Your Username',
'password' => 'Your Password',
'from' => 'Your Default From Number',
],
'smsgatewayme' => [
'apiToken' => 'Your Api Token',
'from' => 'Your Default Device ID',
],
'smsgateway24' => [
'url' => 'https://smsgateway24.com/getdata/addsms',
'token' => 'Your Api Token',
'deviceid' => 'Your Default Device ID',
'from' => 'Device SIM Slot. 0 or 1', // sim
],
'ghasedak' => [
'url' => 'http://api.iransmsservice.com',
'apiKey' => 'Your api key',
'from' => 'Your Default From Number',
],
// Install: composer require sms77/api
'sms77' => [
'apiKey' => 'Your API Key',
'flash' => false,
'from' => 'Sender name',
],
'sabapayamak' => [
'url' => 'https://api.SabaPayamak.com',
'username' => 'Your Sabapayamak Username',
'password' => 'Your Sabapayamak Password',
'from' => 'Your Default From Number',
'token_valid_day' => 30,
],
'lsim' => [
'username' => 'Your LSIM login',
'password' => 'Your LSIM password',
'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,
],
'smsapi' => [
'url' => 'http://www.smsapi.si/poslji-sms',
'username' => 'Your SMSApi Username',
'password' => 'Your SMSApi Password',
'from' => 'Your Default From Number',
'cc' => 'Your Default Country Code',
],
],
/*
|--------------------------------------------------------------------------
| Class Maps
|--------------------------------------------------------------------------
|
| This is the array of Classes that maps to Drivers above.
| You can create your own driver if you like and add the
| config in the drivers array and the class to use for
| here with the same name. You will have to extend
| Tzsk\Sms\Abstracts\Driver in your driver.
|
*/
'map' => [
'sns' => \Tzsk\Sms\Drivers\Sns::class,
'textlocal' => \Tzsk\Sms\Drivers\Textlocal::class,
'twilio' => \Tzsk\Sms\Drivers\Twilio::class,
'smsgateway24' => \Tzsk\Sms\Drivers\SmsGateway24::class,
'clockwork' => \Tzsk\Sms\Drivers\Clockwork::class,
'linkmobility' => \Tzsk\Sms\Drivers\Linkmobility::class,
'melipayamak' => \Tzsk\Sms\Drivers\Melipayamak::class,
'melipayamakpattern' => \Tzsk\Sms\Drivers\Melipayamakpattern::class,
'kavenegar' => \Tzsk\Sms\Drivers\Kavenegar::class,
'smsir' => \Tzsk\Sms\Drivers\Smsir::class,
'tsms' => \Tzsk\Sms\Drivers\Tsms::class,
'farazsms' => \Tzsk\Sms\Drivers\Farazsms::class,
'farazsmspattern' => \Tzsk\Sms\Drivers\Farazsmspattern::class,
'ghasedak' => \Tzsk\Sms\Drivers\Ghasedak::class,
'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,
'smsapi' => \Tzsk\Sms\Drivers\SmsApi::class,
],
];

16
vendor/tzsk/sms/psalm.xml.dist vendored Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
findUnusedVariablesAndParams="true"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
</psalm>

1
vendor/tzsk/sms/resources/sms.svg vendored Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 5.7 KiB

50
vendor/tzsk/sms/src/Builder.php vendored Normal file
View File

@@ -0,0 +1,50 @@
<?php
namespace Tzsk\Sms;
use Illuminate\Support\Arr;
class Builder
{
protected array $recipients = [];
protected string $body;
protected ?string $driver = null;
public function to($recipients): self
{
$this->recipients = Arr::wrap($recipients);
return $this;
}
public function getBody(): string
{
return $this->body;
}
public function send($body): self
{
$this->body = $body;
return $this;
}
public function via($driver): self
{
$this->driver = $driver;
return $this;
}
public function getRecipients(): array
{
return $this->recipients;
}
public function getDriver(): ?string
{
return $this->driver;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Tzsk\Sms\Channels;
use Exception;
use Illuminate\Notifications\Notification;
use Tzsk\Sms\Builder;
class SmsChannel
{
public function send($notifiable, Notification $notification)
{
/**
* @psalm-suppress UndefinedMethod
*/
$message = $notification->toSms($notifiable);
$this->validate($message);
$manager = app()->make('tzsk-sms');
if (! empty($message->getDriver())) {
$manager->via($message->getDriver());
}
return $manager->send($message->getBody(), function ($sms) use ($message) {
$sms->to($message->getRecipients());
});
}
private function validate($message)
{
$conditions = [
'Invalid data for sms notification.' => ! is_a($message, Builder::class),
'Message body could not be empty.' => empty($message->getBody()),
'Message recipient could not be empty.' => empty($message->getRecipients()),
];
foreach ($conditions as $ex => $condition) {
throw_if($condition, new Exception($ex));
}
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Tzsk\Sms\Commands;
use Illuminate\Console\Command;
class SmsPublishCommand extends Command
{
public $signature = 'sms:publish';
public $description = 'Publish sms config file';
public function handle()
{
$this->call('vendor:publish', ['--tag' => 'sms-config']);
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Tzsk\Sms\Contracts;
use Tzsk\Sms\Exceptions\InvalidMessageException;
abstract class Driver
{
protected array $settings = [];
protected array $recipients = [];
protected string $body = '';
protected ?string $sender = '';
public function __construct(array $settings)
{
$this->settings = $settings;
$this->from(data_get($settings, 'from'));
$this->boot();
}
public function to($numbers): self
{
$recipients = is_array($numbers) ? $numbers : [$numbers];
$recipients = array_map(static function ($item) {
return trim($item);
}, array_merge($this->recipients, $recipients));
$this->recipients = array_values(array_filter($recipients));
if (count($this->recipients) < 1) {
throw new InvalidMessageException('Message recipients cannot be empty.');
}
return $this;
}
public function from(?string $sender): self
{
$this->sender = $sender;
return $this;
}
public function message(string $message): self
{
$message = trim($message);
if ($message === '') {
throw new InvalidMessageException('Message text cannot be empty.');
}
$this->body = $message;
return $this;
}
protected function boot(): void
{
//
}
abstract public function send();
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Tzsk\Sms\Drivers;
use mediaburst\ClockworkSMS\Clockwork as ClockworkClient;
use Tzsk\Sms\Contracts\Driver;
class Clockwork extends Driver
{
protected ClockworkClient $client;
protected function boot(): void
{
$this->client = new ClockworkClient(data_get($this->settings, 'key'));
}
public function send()
{
$response = collect();
foreach ($this->recipients as $recipient) {
$response->put($recipient, $this->client->send([
'to' => $recipient,
'message' => $this->body,
]));
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
}

View File

@@ -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';
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Tzsk\Sms\Drivers;
use GuzzleHttp\Client;
use Tzsk\Sms\Contracts\Driver;
class Farazsms extends Driver
{
protected Client $client;
protected function boot(): void
{
$this->client = new Client();
}
public function send()
{
$response = collect();
foreach ($this->recipients as $recipient) {
$result = $this->client->request(
'POST',
data_get($this->settings, 'url'),
$this->payload($recipient)
);
$response->put($recipient, json_decode((string) $result->getBody()));
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
protected function payload($recipient): array
{
return [
'form_params' => [
'uname' => data_get($this->settings, 'username'),
'pass' => data_get($this->settings, 'password'),
'from' => $this->sender,
'message' => $this->body,
'to' => json_encode([$recipient]),
'op' => 'send',
],
];
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace Tzsk\Sms\Drivers;
use GuzzleHttp\Client;
use Illuminate\Support\Arr;
use Tzsk\Sms\Contracts\Driver;
class Farazsmspattern extends Driver
{
protected Client $client;
public function send()
{
/** @var \Illuminate\Support\Collection $response */
$response = collect();
foreach ($this->recipients as $recipient) {
$result = $this->client->request(
'GET',
data_get($this->settings, 'url').'?'.Arr::query($this->payload($recipient)),
);
$response->put($recipient, (string) $result->getBody());
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
protected function payload($recipient): array
{
$body_data = preg_split('/\r\n|[\r\n]/', $this->body);
$input_data = [];
$pattern_code = (explode('=', $body_data[0]))[1];
foreach ($body_data as $key => $datum) {
if ($key === 0) {
continue;
}
$key_value = explode('=', $datum);
$input_data[trim($key_value[0])] = trim($key_value[1]);
}
return [
'username' => data_get($this->settings, 'username'),
'password' => data_get($this->settings, 'password'),
'from' => $this->sender,
'to' => json_encode([$recipient]),
'pattern_code' => $pattern_code,
'input_data' => json_encode($input_data),
];
}
protected function boot(): void
{
$this->client = new Client();
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Tzsk\Sms\Drivers;
use GuzzleHttp\Client;
use Tzsk\Sms\Contracts\Driver;
class Ghasedak extends Driver
{
protected Client $client;
protected function boot(): void
{
$this->client = new Client();
}
public function send()
{
/** @var \Illuminate\Support\Collection $response */
$response = collect();
foreach ($this->recipients as $recipient) {
$result = $this->client->request(
'POST',
$this->settings['url'].'/v2/sms/send/simple',
[
'form_params' => [
'Receptor' => $recipient,
'sender' => $this->sender,
'message' => $this->body,
],
'headers' => [
'apikey' => $this->settings['apiKey'],
],
]
);
$response->put($recipient, $result);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Tzsk\Sms\Drivers;
use Kavenegar\KavenegarApi;
use Tzsk\Sms\Contracts\Driver;
class Kavenegar extends Driver
{
protected KavenegarApi $client;
protected function boot(): void
{
$this->client = new KavenegarApi(data_get($this->settings, 'apiKey'));
}
public function send()
{
$response = collect();
foreach ($this->recipients as $recipient) {
$response->put(
$recipient,
$this->client->Send($this->sender, $recipient, $this->body)
);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
}

42
vendor/tzsk/sms/src/Drivers/LSim.php vendored Normal file
View File

@@ -0,0 +1,42 @@
<?php
namespace Tzsk\Sms\Drivers;
use Illuminate\Support\Facades\Http;
use Tzsk\Sms\Contracts\Driver;
class LSim extends Driver
{
public function send()
{
$responses = [];
foreach ($this->recipients as $recipient) {
$result = Http::withOptions(['verify' => false])
->get('http://apps.lsim.az/quicksms/v1/send', [
'login' => data_get($this->settings, 'username'),
'msisdn' => $recipient,
'text' => $this->body,
'sender' => $this->sender,
'key' => $this->getKey($this->body, $recipient),
]);
$responses[$recipient] = $result;
}
$responses = collect($responses);
return (count($this->recipients) == 1) ? $responses->first() : $responses;
}
private function getKey(string $message, string $number): string
{
return md5(
md5(data_get($this->settings, 'password'))
.data_get($this->settings, 'username')
.$message
.$number
.$this->sender
);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Tzsk\Sms\Drivers;
use GuzzleHttp\Client;
use Tzsk\Sms\Contracts\Driver;
class Linkmobility extends Driver
{
protected Client $client;
protected function boot(): void
{
$this->client = new Client();
}
public function send()
{
/** @var \Illuminate\Support\Collection $response */
$response = collect();
foreach ($this->recipients as $recipient) {
$response->put(
$recipient,
$this->client->request('POST', data_get($this->settings, 'url'), $this->payload($recipient))
);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
protected function payload($recipient): array
{
return [
'form_params' => [
'USER' => data_get($this->settings, 'username'),
'PW' => data_get($this->settings, 'password'),
'RCV' => $recipient,
'SND' => urlencode($this->sender),
'TXT' => $this->body,
],
];
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Tzsk\Sms\Drivers;
use Melipayamak\MelipayamakApi;
use Tzsk\Sms\Contracts\Driver;
class Melipayamak extends Driver
{
protected MelipayamakApi $client;
protected function boot(): void
{
$this->client = new MelipayamakApi(
data_get($this->settings, 'username'),
data_get($this->settings, 'password')
);
}
public function asFlash($flash = true): self
{
$this->settings['flash'] = $flash;
return $this;
}
public function send()
{
$response = collect();
foreach ($this->recipients as $recipient) {
$response->put(
$recipient,
$this->client->sms()->send(
$recipient,
$this->sender,
$this->body,
data_get($this->settings, 'flash')
)
);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Tzsk\Sms\Drivers;
use Melipayamak\MelipayamakApi;
use Tzsk\Sms\Contracts\Driver;
class Melipayamakpattern extends Driver
{
protected MelipayamakApi $client;
protected function boot(): void
{
$this->client = new MelipayamakApi(
data_get($this->settings, 'username'),
data_get($this->settings, 'password')
);
}
public function send()
{
$response = collect();
$body_data = preg_split('/\r\n|[\r\n]/', $this->body);
$input_data = [];
$pattern_code = (explode('=', $body_data[0]))[1];
foreach ($body_data as $key => $datum) {
if ($key === 0) {
continue;
}
$key_value = explode('=', $datum);
$input_data[] = trim($key_value[1]);
}
foreach ($this->recipients as $recipient) {
$response->put($recipient, $this->client->sms('soap')->sendByBaseNumber(
$input_data,
$recipient,
$pattern_code
));
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Tzsk\Sms\Drivers;
use SoapClient;
use Tzsk\Sms\Contracts\Driver;
use Tzsk\Sms\Exceptions\InvalidMessageException;
class Rahyabcp 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'),
'from' => $this->sender,
'to' => $this->recipients,
'text' => $this->body,
'isflash' => data_get($this->settings, 'flash'),
'udh' => '',
'recId' => [0],
'status' => [0],
]);
return $response;
}
}

143
vendor/tzsk/sms/src/Drivers/Rahyabir.php vendored Normal file
View File

@@ -0,0 +1,143 @@
<?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 Rahyabir extends Driver
{
private ?string $baseUrl;
private ?string $username;
private ?string $password;
private ?string $company;
private ?string $number;
private ?string $token;
protected function boot(): void
{
$this->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',
];
}
}

View File

@@ -0,0 +1,142 @@
<?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 SabaPayamak extends Driver
{
private ?string $baseUrl;
private ?string $username;
private ?string $password;
private ?string $virtualNumber;
private ?string $token;
protected function boot(): void
{
$this->baseUrl = trim($this->settings['url'], '/');
$this->username = $this->settings['username'];
$this->password = $this->settings['password'];
$this->virtualNumber = $this->sender;
$this->token = cache('sabapayamak_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(), [
'Text' => $this->body,
'Numbers' => $this->recipients,
]);
$jsonResponse = $response->json();
if (empty($jsonResponse['errors'])) {
return $jsonResponse;
}
$error = $this->getFirstError($jsonResponse['errors']);
if ($error['code'] == 401) {
cache()->forget('sabapayamak_token');
return $this->send();
}
throw new InvalidMessageException($error['message'], $response->status());
}
private function login(): void
{
$this->validateConfiguration();
$response = Http::withHeaders($this->getHttpHeaders())->post($this->getLoginApiUrl(), [
'Username' => $this->username,
'Password' => $this->password,
'VirtualNumber' => $this->virtualNumber,
'TokenValidDay' => $this->getTokenValidDay(),
]);
$response = $response->json();
if (! isset($response['data']['token'])) {
$errors = $response['errors'];
$errorMessage = $this->getErrorMessage($errors);
throw new InvalidMessageException($errorMessage, $response['status']);
}
cache([
'sabapayamak_token' => $response['data']['token'],
], now()->addDays($this->getTokenValidDay()));
$this->token = $response['data']['token'];
}
private function validateConfiguration(): void
{
if (empty($this->baseUrl)) {
throw new InvalidSmsConfigurationException('sabapayamak config not found: api base url');
}
if (empty($this->username)) {
throw new InvalidSmsConfigurationException('sabapayamak config not found: username');
}
if (empty($this->password)) {
throw new InvalidSmsConfigurationException('sabapayamak config not found: password');
}
if (empty($this->virtualNumber)) {
throw new InvalidSmsConfigurationException('sabapayamak config not found: virtual number');
}
}
private function getErrorMessage(array $errors)
{
return array_shift($errors)['message'];
}
private function getFirstError(array $errors)
{
return array_shift($errors);
}
private function getLoginApiUrl(): string
{
return $this->baseUrl.'/api/v1/user/authenticate';
}
private function getSendSmsApiUrl(): string
{
return $this->baseUrl.'/api/v1/message';
}
private function getTokenValidDay()
{
return $this->settings['token_valid_day'];
}
private function getHttpHeaders(): array
{
return [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
];
}
}

44
vendor/tzsk/sms/src/Drivers/Sms77.php vendored Normal file
View File

@@ -0,0 +1,44 @@
<?php
namespace Tzsk\Sms\Drivers;
use Sms77\Api\Client;
use Sms77\Api\Params\SmsParams;
use Tzsk\Sms\Contracts\Driver;
class Sms77 extends Driver
{
protected Client $client;
private string $sourceIdentifier = 'Laravel-SMS-Gateway';
protected function boot(): void
{
$this->client = new Client(data_get($this->settings, 'apiKey'), $this->sourceIdentifier);
}
public function asFlash(bool $flash = true): self
{
$this->settings['flash'] = $flash;
return $this;
}
public function send()
{
/** @var \Illuminate\Support\Collection $response */
$response = collect();
$params = (new SmsParams)
->setFlash(data_get($this->settings, 'flash'))
->setFrom($this->sender)
->setText($this->body);
foreach ($this->recipients as $recipient) {
$result = $this->client->smsJson($params->setTo($recipient));
$response->put($recipient, $result);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
}

69
vendor/tzsk/sms/src/Drivers/SmsApi.php vendored Normal file
View File

@@ -0,0 +1,69 @@
<?php
namespace Tzsk\Sms\Drivers;
use GuzzleHttp\Client;
use Tzsk\Sms\Contracts\Driver;
class SmsApi extends Driver
{
protected Client $client;
private array $options = [];
protected function boot(): void
{
$this->client = new Client();
$this->options['from'] = $this->settings['from'];
}
/**
* Provides a way to pass additional valid parameters or override existing ones
*/
public function with(array $options): self
{
if (! empty(array_diff(array_keys($options), ['from', 'sname', 'cc', 'sid', 'ur', 'dr', 'stime', 'unicode', 'mms', 'mmstype', 'mmsurl']))) {
throw new \Exception(__METHOD__.' contains invalid options');
}
foreach ($options as $option => $value) {
$this->options[$option] = $value;
}
return $this;
}
public function send()
{
/** @var \Illuminate\Support\Collection $response */
$response = collect();
foreach ($this->recipients as $recipient) {
$response->put(
$recipient,
$this->client->post(
data_get($this->settings, 'url'),
[
'form_params' => $this->payload($recipient),
'verify' => false,
]
)
);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
public function payload($recipient): array
{
$payload = [
'un' => data_get($this->settings, 'username'),
'ps' => data_get($this->settings, 'password'),
'from' => $this->options['from'],
'to' => $recipient,
'cc' => data_get($this->settings, 'cc'),
'm' => $this->body,
];
return array_merge($payload, $this->options);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Tzsk\Sms\Drivers;
use GuzzleHttp\Client;
use Tzsk\Sms\Contracts\Driver;
class SmsGateway24 extends Driver
{
protected Client $client;
protected function boot(): void
{
$this->client = new Client();
}
public function send()
{
$response = collect();
foreach ($this->recipients as $recipient) {
$result = $this->client->request(
'POST',
data_get($this->settings, 'url'),
$this->payload($recipient)
);
$response->put($recipient, json_decode((string) $result->getBody()));
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
protected function payload($recipient): array
{
return [
'form_params' => [
'token' => data_get($this->settings, 'token'),
'sendto' => $recipient,
'body' => $this->body,
'device_id' => data_get($this->settings, 'deviceid'),
'sim' => $this->sender,
],
];
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Tzsk\Sms\Drivers;
use SMSGatewayMe\Client\Api\MessageApi;
use SMSGatewayMe\Client\ApiClient;
use SMSGatewayMe\Client\Configuration;
use SMSGatewayMe\Client\Model\SendMessageRequest;
use Tzsk\Sms\Contracts\Driver;
class SmsGatewayMe extends Driver
{
protected MessageApi $client;
protected function boot(): void
{
$config = Configuration::getDefaultConfiguration()->setApiKey(
'Authorization',
data_get($this->settings, 'apiToken')
);
$this->client = new MessageApi(new ApiClient($config));
}
public function send()
{
/** @var \Illuminate\Support\Collection $response */
$response = collect();
foreach ($this->recipients as $recipient) {
$response->put(
$recipient,
$this->client->sendMessages([$this->payload($recipient)])
);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
protected function payload($recipient): SendMessageRequest
{
return new SendMessageRequest([
'phoneNumber' => $recipient,
'message' => $this->body,
'deviceId' => $this->sender,
]);
}
}

75
vendor/tzsk/sms/src/Drivers/Smsir.php vendored Normal file
View File

@@ -0,0 +1,75 @@
<?php
namespace Tzsk\Sms\Drivers;
use GuzzleHttp\Client;
use Tzsk\Sms\Contracts\Driver;
use Tzsk\Sms\Exceptions\InvalidSmsConfigurationException;
class Smsir extends Driver
{
protected Client $client;
protected function boot(): void
{
$this->client = new Client();
}
public function send()
{
$token = $this->getToken();
/** @var \Illuminate\Support\Collection $response */
$response = collect();
foreach ($this->recipients as $recipient) {
$result = $this->client->request(
'POST',
data_get($this->settings, 'url').'/api/MessageSend',
$this->payload($recipient, $token)
);
$response->put($recipient, $result);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
/**
* @param string $recipient
* @param string $token
* @return array
*/
protected function payload($recipient, $token)
{
return [
'json' => [
'Messages' => [$this->body],
'MobileNumbers' => [$recipient],
'LineNumber' => $this->sender,
],
'headers' => [
'x-sms-ir-secure-token' => $token,
],
'connect_timeout' => 30,
];
}
protected function getToken()
{
$body = [
'UserApiKey' => data_get($this->settings, 'apiKey'),
'SecretKey' => data_get($this->settings, 'secretKey'),
];
$response = $this->client->post(
data_get($this->settings, 'url').'/api/Token',
['json' => $body, 'connect_timeout' => 30]
);
$body = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR);
if (empty($body['TokenKey'])) {
throw new InvalidSmsConfigurationException('Smsir token could not be generated.');
}
return $body['TokenKey'];
}
}

56
vendor/tzsk/sms/src/Drivers/Sns.php vendored Normal file
View File

@@ -0,0 +1,56 @@
<?php
namespace Tzsk\Sms\Drivers;
use Aws\Sns\SnsClient;
use Tzsk\Sms\Contracts\Driver;
class Sns extends Driver
{
protected SnsClient $client;
protected function boot(): void
{
$this->client = new SnsClient([
'credentials' => [
'key' => data_get($this->settings, 'key'),
'secret' => data_get($this->settings, 'secret'),
],
'region' => data_get($this->settings, 'region'),
'version' => '2010-03-31',
]);
}
public function send()
{
/** @var \Illuminate\Support\Collection $response */
$response = collect();
foreach ($this->recipients as $recipient) {
$response->put(
$recipient,
$this->client->publish($this->payload($recipient))
);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
protected function payload($recipient): array
{
return [
'Message' => $this->body,
'MessageAttributes' => [
'AWS.SNS.SMS.SenderID' => [
'DataType' => 'String',
'StringValue' => $this->sender,
],
'AWS.SNS.SMS.SMSType' => [
'DataType' => 'String',
'StringValue' => data_get($this->settings, 'type'),
],
],
'PhoneNumber' => $recipient,
];
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Tzsk\Sms\Drivers;
use GuzzleHttp\Client;
use Tzsk\Sms\Contracts\Driver;
class Textlocal extends Driver
{
protected Client $client;
protected function boot(): void
{
$this->client = new Client();
}
public function send()
{
/** @var \Illuminate\Support\Collection $response */
$response = collect();
foreach ($this->recipients as $recipient) {
$response->put(
$recipient,
$this->client->request('POST', data_get($this->settings, 'url'), $this->payload($recipient))
);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
public function payload($recipient): array
{
return [
'form_params' => [
'username' => data_get($this->settings, 'username'),
'hash' => data_get($this->settings, 'hash'),
'numbers' => $recipient,
'sender' => urlencode($this->sender),
'message' => $this->body,
],
];
}
}

37
vendor/tzsk/sms/src/Drivers/Tsms.php vendored Normal file
View File

@@ -0,0 +1,37 @@
<?php
namespace Tzsk\Sms\Drivers;
use SoapClient;
use Tzsk\Sms\Contracts\Driver;
class Tsms extends Driver
{
protected SoapClient $client;
protected function boot(): void
{
$this->client = new SoapClient(data_get($this->settings, 'url'));
}
public function send()
{
$response = collect();
foreach ($this->recipients as $recipient) {
$result = $this->client->sendSms(
data_get($this->settings, 'username'),
data_get($this->settings, 'password'),
[$this->sender],
[$recipient],
[$this->body],
[],
rand()
);
$response->put($recipient, $result);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
}

34
vendor/tzsk/sms/src/Drivers/Twilio.php vendored Normal file
View File

@@ -0,0 +1,34 @@
<?php
namespace Tzsk\Sms\Drivers;
use Twilio\Rest\Client;
use Tzsk\Sms\Contracts\Driver;
class Twilio extends Driver
{
protected Client $client;
protected function boot(): void
{
$this->client = new Client(data_get($this->settings, 'sid'), data_get($this->settings, 'token'));
}
public function send()
{
$response = collect();
foreach ($this->recipients as $recipient) {
/**
* @psalm-suppress UndefinedMagicPropertyFetch
*/
$result = $this->client->account->messages->create(
$recipient,
['from' => $this->sender, 'body' => $this->body]
);
$response->put($recipient, $result);
}
return (count($this->recipients) == 1) ? $response->first() : $response;
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Tzsk\Sms\Exceptions;
use Exception;
class InvalidMessageException extends Exception
{
}

View File

@@ -0,0 +1,9 @@
<?php
namespace Tzsk\Sms\Exceptions;
use Exception;
class InvalidSmsConfigurationException extends Exception
{
}

16
vendor/tzsk/sms/src/Facades/Sms.php vendored Normal file
View File

@@ -0,0 +1,16 @@
<?php
namespace Tzsk\Sms\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @see \Tzsk\Sms\Sms
*/
class Sms extends Facade
{
protected static function getFacadeAccessor()
{
return 'tzsk-sms';
}
}

13
vendor/tzsk/sms/src/Helper.php vendored Normal file
View File

@@ -0,0 +1,13 @@
<?php
if (! function_exists('sms')) {
/**
* Access SmsManager through helper.
*
* @return \Tzsk\Sms\Sms
*/
function sms()
{
return app('tzsk-sms');
}
}

104
vendor/tzsk/sms/src/Sms.php vendored Normal file
View File

@@ -0,0 +1,104 @@
<?php
namespace Tzsk\Sms;
use Exception;
use ReflectionClass;
use Tzsk\Sms\Contracts\Driver;
class Sms
{
protected array $config;
protected array $settings;
protected string $driver;
protected Builder $builder;
public function __construct(array $config)
{
$this->config = $config;
$this->setBuilder(new Builder());
$this->via($this->config['default']);
}
public function to($recipients): self
{
$this->builder->to($recipients);
return $this;
}
public function via($driver): self
{
$this->driver = $driver;
$this->validateDriver();
$this->builder->via($driver);
$this->settings = $this->config['drivers'][$driver];
return $this;
}
public function send($message, $callback = null)
{
if ($message instanceof Builder) {
return $this->setBuilder($message)->dispatch();
}
$this->builder->send($message);
if (! $callback) {
return $this;
}
$driver = $this->getDriverInstance();
$driver->message($message);
call_user_func($callback, $driver);
return $driver->send();
// return $this->setBuilder($this->builder->send($message))->dispatch();
}
public function dispatch()
{
$this->driver = $this->builder->getDriver() ?: $this->driver;
if (empty($this->driver)) {
$this->via($this->config['default']);
}
$driver = $this->getDriverInstance();
$driver->message($this->builder->getBody());
$driver->to($this->builder->getRecipients());
return $driver->send();
}
protected function setBuilder(Builder $builder): self
{
$this->builder = $builder;
return $this;
}
protected function getDriverInstance(): Driver
{
$this->validateDriver();
$class = $this->config['map'][$this->driver];
return new $class($this->settings);
}
protected function validateDriver()
{
$conditions = [
'Driver not selected or default driver does not exist.' => empty($this->driver),
'Driver not found in config file. Try updating the package.' => empty($this->config['drivers'][$this->driver]) || empty($this->config['map'][$this->driver]),
'Driver source not found. Please update the package.' => ! class_exists($this->config['map'][$this->driver]),
'Driver must be an instance of Contracts\Driver.' => ! (new ReflectionClass($this->config['map'][$this->driver]))->isSubclassOf(Driver::class),
];
foreach ($conditions as $ex => $condition) {
throw_if($condition, new Exception($ex));
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Tzsk\Sms;
use Illuminate\Support\ServiceProvider;
use Tzsk\Sms\Commands\SmsPublishCommand;
class SmsServiceProvider extends ServiceProvider
{
public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/sms.php' => config_path('sms.php'),
], 'sms-config');
$this->commands([
SmsPublishCommand::class,
]);
}
$this->app->bind('tzsk-sms', function () {
return new Sms(config('sms'));
});
}
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/sms.php', 'sms');
}
}