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

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