add SMSpanel

This commit is contained in:
2026-07-04 11:55:10 +03:30
parent 1ce2e73ea9
commit 163097f42a
22 changed files with 6683 additions and 2214 deletions
@@ -0,0 +1,69 @@
<?php
namespace App\Services\SmsBilling\Providers;
use App\Http\Controllers\Controller;
use App\Services\SmsBilling\Contracts\SmsProviderInterface;
use Illuminate\Support\Facades\Http;
class CentralSmsApiProvider implements SmsProviderInterface
{
public function name(): string
{
return 'rayegansms';
}
public function supports(array $config): bool
{
$meliUser = trim((string) ($config['melipayamak_user'] ?? ''));
return strlen($meliUser) <= 1;
}
public function send(string $to, string $message, array $config): array
{
$http = Http::timeout(15)
->withHeaders([
'Content-Type' => 'application/json',
'secret_key' => 'f21debfb-83ac-4624-a2f4-f08375043181',
]);
$curlOptions = Controller::httpClientOptions();
if ($curlOptions !== []) {
$http = $http->withOptions($curlOptions);
}
$host = trim((string) ($config['name_fa'] ?? ''));
if ($host === '') {
$host = trim((string) ($config['name_en'] ?? ''));
}
if ($host === '') {
$host = gethostname();
}
$response = $http->post('http://185.231.112.101/api/createsms', [
'phone' => $to,
'host' => $host,
'text' => trim($message),
'platform' => 'rayegansms',
]);
$body = $response->json() ?? $response->body();
$success = $response->successful();
if (is_array($body) && $success) {
if (array_key_exists('success', $body) && $body['success'] === false) {
$success = false;
} elseif (array_key_exists('ok', $body) && $body['ok'] === false) {
$success = false;
} elseif (isset($body['status']) && in_array(strtolower((string) $body['status']), ['error', 'failed', 'fail'], true)) {
$success = false;
}
}
return [
'success' => $success,
'raw' => $body,
];
}
}
@@ -0,0 +1,68 @@
<?php
namespace App\Services\SmsBilling\Providers;
use App\Services\SmsBilling\Contracts\SmsProviderInterface;
class MeliPayamakProvider implements SmsProviderInterface
{
public function name(): string
{
return 'melipayamak';
}
public function supports(array $config): bool
{
$meliUser = trim((string) ($config['melipayamak_user'] ?? ''));
return strlen($meliUser) > 1;
}
public function send(string $to, string $message, array $config): array
{
$data = [
'username' => $config['melipayamak_user'],
'password' => $config['melipayamak_password'] ?? '',
'to' => $to,
'from' => $config['melipayamak_from'] ?? '',
'text' => $message,
];
$handle = curl_init('https://rest.payamak-panel.com/api/SendSMS/SendSMS');
curl_setopt_array($handle, [
CURLOPT_HTTPHEADER => ['content-type: application/x-www-form-urlencoded'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_TIMEOUT => 30,
]);
$response = curl_exec($handle);
$error = curl_error($handle);
curl_close($handle);
if ($response === false) {
return ['success' => false, 'raw' => $error];
}
$decoded = json_decode($response, true);
if (is_array($decoded)) {
$status = $decoded['RetStatus'] ?? $decoded['retStatus'] ?? null;
return [
'success' => (int) $status === 1,
'raw' => $decoded,
];
}
$text = trim((string) $response);
return [
'success' => $text !== '' && stripos($text, 'error') === false,
'raw' => $response,
];
}
}