From 4894d566a008b586a38023545a4e1e9a45d51358 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Wed, 24 Jun 2026 16:04:53 +0300 Subject: [PATCH] Update: 2026-06-24 16:04:53 --- .DS_Store | Bin 10244 -> 10244 bytes backend/auth/otp/providers.php | 35 ++++++++++++++++++++++++++++++--- backend/auth/otp/request.php | 10 +++++----- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/.DS_Store b/.DS_Store index 98f598b83e1fd6ba415081b225bacd7ff0998cdf..756740b49c529c6e0084b1a8e010e29c2c4a8f1a 100644 GIT binary patch delta 46 zcmZn(XbG6$&uF|cU^hRb@njx>>dB3Q!keW8gP1pGiO%KPSWw5fnO)%*%jSA9W@Z3t Ccnd>UvfNJ%((COokkW{G4>d;N<+=0tO)9kV@?ZQb@A7 z`7SO=Ir&K-$%K1rqqcrH?uf1;g@B5J3?v(73jnoG5)|1yOCX53o}VF?A(5d7=$2H5 z5}@&d5=F?V>ey8r+H diff --git a/backend/auth/otp/providers.php b/backend/auth/otp/providers.php index 263ba0d..c16340b 100644 --- a/backend/auth/otp/providers.php +++ b/backend/auth/otp/providers.php @@ -117,9 +117,10 @@ function getNabehBearerToken(): ?string { * @param string $receiver Recipient phone number * @param string $otp 3-digit verification code * @param string $method text | voice | image | whatsapp + * @param string $user_type passenger | driver | admin | service * @return bool True if OTP was sent successfully */ -function sendNabehOtp(string $receiver, string $otp, string $method = 'text'): bool { +function sendNabehOtp(string $receiver, string $otp, string $method = '', string $user_type = 'passenger'): bool { $bearerToken = getNabehBearerToken(); if (!$bearerToken) { $msg = "⚠️ [Nabeh OTP] Failed to obtain dynamic JWT Bearer token."; @@ -136,13 +137,41 @@ function sendNabehOtp(string $receiver, string $otp, string $method = 'text'): b $type = 'voice'; } elseif ($method === 'image') { $type = 'image'; - } + } elseif ($method === 'text') { + $type = 'text'; + } else { + // Strict alternating using Redis + global $redis; + $type = 'image'; // default + if ($redis) { + try { + $lastType = $redis->get('nabeh_last_type'); + $type = ($lastType === 'image') ? 'voice' : 'image'; + $redis->set('nabeh_last_type', $type); + } catch (Exception $e) { + error_log("⚠️ [Nabeh OTP Redis alternate] Error toggling type: " . $e->getMessage()); + } + } else { + // Fallback to random if Redis is not connected + $type = (random_int(0, 1) === 0) ? 'image' : 'voice'; + } + } + + $appName = 'سيرو رايدر'; + if ($user_type === 'driver') { + $appName = 'سيرو درايفر'; + } elseif ($user_type === 'admin') { + $appName = 'سيرو الأدمن'; + } elseif ($user_type === 'service') { + $appName = 'سيرو للخدمات'; + } $apiUrl = 'https://nabeh.intaleqapp.com/api/otp/send'; $payload = [ 'phone' => $phoneRaw, 'type' => $type, - 'code' => $otp + 'code' => $otp, + 'message' => "رمز التحقق الخاص بك لتطبيق {$appName} هو: *{code}* \n الرجاء عدم مشاركته مع أي شخص." ]; $response = curlCall("POST", $apiUrl, json_encode($payload), [ diff --git a/backend/auth/otp/request.php b/backend/auth/otp/request.php index 3d62889..d212686 100644 --- a/backend/auth/otp/request.php +++ b/backend/auth/otp/request.php @@ -92,19 +92,19 @@ switch (strtolower($country)) { case 'egypt': $sentSuccessfully = sendKazumiSms($receiver, $otp); if (!$sentSuccessfully) { - error_log("⚠️ [Egypt OTP Failover] Kazumi SMS failed. Falling back to Nabeh OTP."); - $sentSuccessfully = sendNabehOtp($receiver, $otp, 'text'); + error_log("⚠️ [Egypt OTP Failover] Kazumi SMS failed. Falling back to Intaleq OTP WhatsApp."); + $sentSuccessfully = sendIntaleqOtp($receiver, $otp, 'whatsapp'); } break; case 'syria': // Syria uses Nabeh - $sentSuccessfully = sendNabehOtp($receiver, $otp, 'text'); + $sentSuccessfully = sendNabehOtp($receiver, $otp, $method, $user_type); break; case 'jordan': // Jordan uses Nabeh - $sentSuccessfully = sendNabehOtp($receiver, $otp, 'text'); + $sentSuccessfully = sendNabehOtp($receiver, $otp, $method, $user_type); break; default: @@ -112,7 +112,7 @@ switch (strtolower($country)) { $sentSuccessfully = sendKazumiSms($receiver, $otp); if (!$sentSuccessfully) { error_log("⚠️ [Default OTP Failover] Kazumi SMS failed. Falling back to Nabeh OTP."); - $sentSuccessfully = sendNabehOtp($receiver, $otp, 'text'); + $sentSuccessfully = sendNabehOtp($receiver, $otp, $method, $user_type); } break; }