Update: 2026-06-24 16:04:53

This commit is contained in:
Hamza-Ayed
2026-06-24 16:04:53 +03:00
parent 3b2c2a86c6
commit 4894d566a0
3 changed files with 37 additions and 8 deletions

View File

@@ -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), [