servers)) { return ['success' => false, 'error' => 'No servers available.']; } // اختيار سيرفر عشوائي من القائمة المتاحة لتوزيع الحمل $url = $this->servers[array_rand($this->servers)]; $payload = [ "to" => $to, "message" => [ "text" => $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) { return ['success' => false, 'error' => $err, 'url' => $url]; } $responseData = json_decode($response, true); $isSuccess = isset($responseData['success']) && $responseData['success'] === true; return [ 'success' => $isSuccess, 'response' => $responseData, 'raw_response' => $response, 'url' => $url, 'payload' => $payload ]; } }