Update: 2026-06-24 16:04:53
This commit is contained in:
@@ -117,9 +117,10 @@ function getNabehBearerToken(): ?string {
|
|||||||
* @param string $receiver Recipient phone number
|
* @param string $receiver Recipient phone number
|
||||||
* @param string $otp 3-digit verification code
|
* @param string $otp 3-digit verification code
|
||||||
* @param string $method text | voice | image | whatsapp
|
* @param string $method text | voice | image | whatsapp
|
||||||
|
* @param string $user_type passenger | driver | admin | service
|
||||||
* @return bool True if OTP was sent successfully
|
* @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();
|
$bearerToken = getNabehBearerToken();
|
||||||
if (!$bearerToken) {
|
if (!$bearerToken) {
|
||||||
$msg = "⚠️ [Nabeh OTP] Failed to obtain dynamic JWT Bearer token.";
|
$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';
|
$type = 'voice';
|
||||||
} elseif ($method === 'image') {
|
} elseif ($method === 'image') {
|
||||||
$type = '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';
|
$apiUrl = 'https://nabeh.intaleqapp.com/api/otp/send';
|
||||||
$payload = [
|
$payload = [
|
||||||
'phone' => $phoneRaw,
|
'phone' => $phoneRaw,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'code' => $otp
|
'code' => $otp,
|
||||||
|
'message' => "رمز التحقق الخاص بك لتطبيق {$appName} هو: *{code}* \n الرجاء عدم مشاركته مع أي شخص."
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = curlCall("POST", $apiUrl, json_encode($payload), [
|
$response = curlCall("POST", $apiUrl, json_encode($payload), [
|
||||||
|
|||||||
@@ -92,19 +92,19 @@ switch (strtolower($country)) {
|
|||||||
case 'egypt':
|
case 'egypt':
|
||||||
$sentSuccessfully = sendKazumiSms($receiver, $otp);
|
$sentSuccessfully = sendKazumiSms($receiver, $otp);
|
||||||
if (!$sentSuccessfully) {
|
if (!$sentSuccessfully) {
|
||||||
error_log("⚠️ [Egypt OTP Failover] Kazumi SMS failed. Falling back to Nabeh OTP.");
|
error_log("⚠️ [Egypt OTP Failover] Kazumi SMS failed. Falling back to Intaleq OTP WhatsApp.");
|
||||||
$sentSuccessfully = sendNabehOtp($receiver, $otp, 'text');
|
$sentSuccessfully = sendIntaleqOtp($receiver, $otp, 'whatsapp');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'syria':
|
case 'syria':
|
||||||
// Syria uses Nabeh
|
// Syria uses Nabeh
|
||||||
$sentSuccessfully = sendNabehOtp($receiver, $otp, 'text');
|
$sentSuccessfully = sendNabehOtp($receiver, $otp, $method, $user_type);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'jordan':
|
case 'jordan':
|
||||||
// Jordan uses Nabeh
|
// Jordan uses Nabeh
|
||||||
$sentSuccessfully = sendNabehOtp($receiver, $otp, 'text');
|
$sentSuccessfully = sendNabehOtp($receiver, $otp, $method, $user_type);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -112,7 +112,7 @@ switch (strtolower($country)) {
|
|||||||
$sentSuccessfully = sendKazumiSms($receiver, $otp);
|
$sentSuccessfully = sendKazumiSms($receiver, $otp);
|
||||||
if (!$sentSuccessfully) {
|
if (!$sentSuccessfully) {
|
||||||
error_log("⚠️ [Default OTP Failover] Kazumi SMS failed. Falling back to Nabeh OTP.");
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user