77 lines
2.3 KiB
PHP
77 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
/**
|
|
* WhatsApp Proxy Service
|
|
*
|
|
* Used to send WhatsApp messages (like OTPs) via Intaleq proxy bots.
|
|
*/
|
|
class WhatsAppProxyService
|
|
{
|
|
/**
|
|
* قائمة السيرفرات المتاحة
|
|
*/
|
|
private array $servers = [
|
|
//"https://botmasa.intaleq.xyz/send", // mayar
|
|
//"https://botmasa2.intaleq.xyz/send", // shad
|
|
//"https://bootride.intaleq.xyz/send", // ramat bus
|
|
"https://bot5.intaleq.xyz/send", // shahd
|
|
//"https://whatsapp.tripz-egypt.com/send" // tripz
|
|
];
|
|
|
|
/**
|
|
* إرسال رسالة واتساب
|
|
*
|
|
* @param string $to رقم الهاتف
|
|
* @param string $message نص الرسالة
|
|
* @return bool نجاح الإرسال
|
|
*/
|
|
public function sendMessage(string $to, string $message): bool
|
|
{
|
|
if (empty($this->servers)) {
|
|
error_log("[WhatsAppProxyService] No servers available.");
|
|
return false;
|
|
}
|
|
|
|
// اختيار سيرفر عشوائي من القائمة المتاحة لتوزيع الحمل
|
|
$url = $this->servers[array_rand($this->servers)];
|
|
|
|
$payload = [
|
|
"to" => $to,
|
|
"message" => $message
|
|
];
|
|
|
|
$curl = curl_init();
|
|
curl_setopt_array($curl, [
|
|
CURLOPT_URL => $url,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_CUSTOMREQUEST => "POST",
|
|
CURLOPT_POSTFIELDS => json_encode($payload, JSON_UNESCAPED_UNICODE),
|
|
CURLOPT_HTTPHEADER => [
|
|
"Content-Type: application/json"
|
|
],
|
|
CURLOPT_TIMEOUT => 15, // مهلة 15 ثانية للطلب
|
|
]);
|
|
|
|
$response = curl_exec($curl);
|
|
$err = curl_error($curl);
|
|
curl_close($curl);
|
|
|
|
if ($err) {
|
|
error_log("[WhatsAppProxyService] cURL Error on $url: $err");
|
|
return false;
|
|
}
|
|
|
|
$responseData = json_decode($response, true);
|
|
|
|
// التحقق من حالة الرد (يمكنك تخصيصه حسب هيكل رد البوت الخاص بك)
|
|
if (isset($responseData['error']) && $responseData['error']) {
|
|
error_log("[WhatsAppProxyService] API Error on $url: " . json_encode($responseData));
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|