Files
boursecu_server/app/Services/SmsBilling/Providers/MeliPayamakProvider.php
T
2026-08-26 21:47:09 +03:30

78 lines
2.3 KiB
PHP

<?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');
$opts = [
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,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_PROXY => '',
];
if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
$opts[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
}
if (defined('CURLOPT_HTTP_VERSION') && defined('CURL_HTTP_VERSION_1_1')) {
$opts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
}
curl_setopt_array($handle, $opts);
$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,
];
}
}