diff --git a/backend/auth/driver/register.php b/backend/auth/driver/register.php index cb7b134b..1e44eaa6 100644 --- a/backend/auth/driver/register.php +++ b/backend/auth/driver/register.php @@ -552,7 +552,7 @@ Therefore, do NOT assume a specific field is on the front or the back of a card. /* ================== 11) Notification ================== */ try { - $fcmSendUrl = 'https://api.intaleq.xyz/siro/ride/firebase/send_fcm.php'; + $fcmSendUrl = getenv('FCM_ENDPOINT_URL') ?: 'http://nginx/backend/ride/firebase/send_fcm.php'; $driverFullName = $raw_first_name . ' ' . $raw_last_name; $notificationTitle = 'تسجيل سائق جديد'; diff --git a/backend/bot/cron_silent_push_inactive.php b/backend/bot/cron_silent_push_inactive.php index 03c9b7c7..bafa5f61 100644 --- a/backend/bot/cron_silent_push_inactive.php +++ b/backend/bot/cron_silent_push_inactive.php @@ -62,36 +62,13 @@ echo "Silent Push triggered for $sentCount inactive users.\n"; * Helper to send Silent FCM */ function sendSilentFcmNotification($token, $data) { - // Basic curl request to FCM API for silent push - $url = 'https://fcm.googleapis.com/fcm/send'; - - // Replace with your actual server key - $serverKey = getenv('FCM_SERVER_KEY') ?: 'YOUR_LEGACY_SERVER_KEY'; - - $fields = [ - 'to' => $token, - 'data' => $data, - 'content_available' => true, // Required for iOS to wake up in background - 'priority' => 'high' // Sometimes required to wake up Android - ]; - - $headers = [ - 'Authorization: key=' . $serverKey, - 'Content-Type: application/json' - ]; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); - - $result = curl_exec($ch); - curl_close($ch); - - return $result; + if (function_exists('sendFCM_Internal')) { + return sendFCM_Internal($token, '', '', $data, 'SilentPush', false, 'silent'); + } + if (!class_exists('FcmService')) { + require_once __DIR__ . '/../core/Services/FcmService.php'; + } + $fcm = new FcmService(); + return $fcm->send($token, '', '', $data, 'SilentPush', 'silent'); } ?> diff --git a/backend/core/Services/FcmService.php b/backend/core/Services/FcmService.php index f21922d8..5be2e69f 100644 --- a/backend/core/Services/FcmService.php +++ b/backend/core/Services/FcmService.php @@ -11,9 +11,15 @@ class FcmService public function __construct(?Redis $redis = null) { - $this->redis = $redis; - // المسار بناء على بنية المشروع - $this->serviceAccountFile = getenv('FIREBASE_SERVICE_ACCOUNT_PATH'); + $this->redis = $redis; + $envPath = getenv('FIREBASE_SERVICE_ACCOUNT_PATH') ?: ''; + if (!empty($envPath) && file_exists($envPath)) { + $this->serviceAccountFile = $envPath; + } elseif (file_exists('/keys/firebase_service_account.json')) { + $this->serviceAccountFile = '/keys/firebase_service_account.json'; + } else { + $this->serviceAccountFile = __DIR__ . '/../../keys/firebase_service_account.json'; + } } // ── إرسال إشعار ──────────────────────────────────────── diff --git a/backend/ride/firebase/fcm_fun.php b/backend/ride/firebase/fcm_fun.php index 1ef9b528..ba1332b1 100644 --- a/backend/ride/firebase/fcm_fun.php +++ b/backend/ride/firebase/fcm_fun.php @@ -12,10 +12,22 @@ function base64UrlEncode($data) { // ============================================================================ // دالة الحصول على Access Token من Google OAuth2 // ============================================================================ -function getFCMAccessToken($serviceAccountPath = null) { - if (!$serviceAccountPath) { - $serviceAccountPath = __DIR__ . '/service-account.json'; +function resolveFCMServiceAccountPath($serviceAccountPath = null) { + if (!empty($serviceAccountPath) && file_exists($serviceAccountPath)) { + return $serviceAccountPath; } + $envPath = getenv('FIREBASE_SERVICE_ACCOUNT_PATH') ?: ''; + if (!empty($envPath) && file_exists($envPath)) { + return $envPath; + } + if (file_exists('/keys/firebase_service_account.json')) { + return '/keys/firebase_service_account.json'; + } + return __DIR__ . '/service-account.json'; +} + +function getFCMAccessToken($serviceAccountPath = null) { + $serviceAccountPath = resolveFCMServiceAccountPath($serviceAccountPath); if (!file_exists($serviceAccountPath)) { error_log("❌ FCM: service-account.json not found at: $serviceAccountPath"); @@ -73,7 +85,7 @@ function sendFCMNotification($params) { $data = $params['data'] ?? []; $tone = $params['tone'] ?? 'default'; $isTopic = $params['isTopic'] ?? false; - $serviceAccountPath = $params['service_account_path'] ?? __DIR__ . '/service-account.json'; + $serviceAccountPath = resolveFCMServiceAccountPath($params['service_account_path'] ?? null); // التحقق من البيانات الأساسية if (empty($token) || empty($title) || empty($body)) { diff --git a/backend/ride/firebase/send_fcm.php b/backend/ride/firebase/send_fcm.php index 0880e134..5a730472 100644 --- a/backend/ride/firebase/send_fcm.php +++ b/backend/ride/firebase/send_fcm.php @@ -2,16 +2,27 @@ // send_fcm.php - FCM HTTP v1 Sender (Internal use only) header('Content-Type: application/json; charset=utf-8'); -// 🔐 Require internal API key for authentication +// 🔐 Require internal API key for authentication if set $apiKey = $_SERVER['HTTP_X_API_KEY'] ?? ''; $expectedKey = getenv('FCM_INTERNAL_API_KEY'); -if (empty($expectedKey) || !hash_equals($expectedKey, $apiKey)) { +if (!empty($expectedKey) && !hash_equals($expectedKey, $apiKey)) { http_response_code(403); echo json_encode(['status' => 'error', 'message' => 'Unauthorized']); exit; } -$serviceAccountFile = __DIR__ . '/service-account.json'; +function resolveServiceAccountPath(): string { + $envPath = getenv('FIREBASE_SERVICE_ACCOUNT_PATH') ?: ''; + if (!empty($envPath) && file_exists($envPath)) { + return $envPath; + } + if (file_exists('/keys/firebase_service_account.json')) { + return '/keys/firebase_service_account.json'; + } + return __DIR__ . '/service-account.json'; +} + +$serviceAccountFile = resolveServiceAccountPath(); // السماح فقط بـ POST if ($_SERVER['REQUEST_METHOD'] !== 'POST') { diff --git a/backend/ride/rides/getRideStatusFromStartApp.php b/backend/ride/rides/getRideStatusFromStartApp.php index 3039d067..0fe6c5b6 100644 --- a/backend/ride/rides/getRideStatusFromStartApp.php +++ b/backend/ride/rides/getRideStatusFromStartApp.php @@ -21,8 +21,8 @@ try { FROM ride WHERE passenger_id = ? AND ( - status IN ('Apply', 'Applied', 'accepted', 'arrived', 'Arrived', 'Begin') AND created_at >= NOW() - INTERVAL 24 HOUR - OR (status = 'Finished' AND created_at >= NOW() - INTERVAL 24 HOUR) + status IN ('Apply', 'Applied', 'accepted', 'arrived', 'Arrived', 'Begin') AND created_at >= NOW() - INTERVAL 1 HOUR + OR (status = 'Finished' AND created_at >= NOW() - INTERVAL 1 HOUR) ) ORDER BY created_at DESC LIMIT 1 diff --git a/loction_server/driver_socket.php b/loction_server/driver_socket.php index ab81be63..23acf4fc 100755 --- a/loction_server/driver_socket.php +++ b/loction_server/driver_socket.php @@ -272,7 +272,7 @@ function sendFCM_Async(string $token, string $title, string $body, array $rideDa $http = new AsyncHttp(); $http->request( - 'https://api.intaleq.xyz/intaleq/ride/firebase/send_fcm.php', + getenv('FCM_ENDPOINT_URL') ?: 'http://nginx/backend/ride/firebase/send_fcm.php', [ 'method' => 'POST', 'data' => json_encode([ diff --git a/siro_driver/lib/constant/links.dart b/siro_driver/lib/constant/links.dart index 10c9af1f..57b4f932 100755 --- a/siro_driver/lib/constant/links.dart +++ b/siro_driver/lib/constant/links.dart @@ -63,9 +63,9 @@ class AppLink { case 'Egypt': return 'https://location-egypt.siromove.com'; case 'Jordan': - return 'https://jordan-siro.intaleqapp.com'; + return 'https://jordan-siro.intaleqapp.com:2020'; default: - return 'https://location-jordan.siromove.com'; + return 'https://jordan-siro.intaleqapp.com:2020'; } } diff --git a/siro_rider/lib/constant/links.dart b/siro_rider/lib/constant/links.dart index a6b18b93..5582d097 100644 --- a/siro_rider/lib/constant/links.dart +++ b/siro_rider/lib/constant/links.dart @@ -152,9 +152,9 @@ class AppLink { case 'Egypt': return 'https://api-egypt.siromove.com'; case 'Jordan': - return 'https://jordan-siro.intaleqapp.com'; + return 'https://jordan-siro.intaleqapp.com:3030'; default: - return 'https://api.siromove.com'; + return 'https://jordan-siro.intaleqapp.com:3030'; } }