Update: 2026-07-21 19:28:08

This commit is contained in:
Hamza-Ayed
2026-07-21 19:28:08 +03:00
parent f3905bcb2c
commit 4f47c0ad1d
+26 -4
View File
@@ -155,9 +155,31 @@ function sendNabehOtp(string $receiver, string $otp, string $method = '', string
$appName = 'سيرو للخدمات'; $appName = 'سيرو للخدمات';
} }
// First attempt with the chosen type
$result = _nabehOtpAttempt($phoneRaw, $type, $otp, $appName, $bearerToken);
if ($result) {
return true;
}
// Fallback: if image failed, retry with text
if ($type === 'image') {
error_log("ℹ️ [Nabeh OTP Fallback] Image failed, retrying with text type...");
$result = _nabehOtpAttempt($phoneRaw, 'text', $otp, $appName, $bearerToken);
if ($result) {
return true;
}
}
return false;
}
/**
* Internal helper: single OTP send attempt to Nabeh
*/
function _nabehOtpAttempt(string $phone, string $type, string $otp, string $appName, string $bearerToken): bool {
$apiUrl = 'https://nabeh.intaleqapp.com/api/otp/send'; $apiUrl = 'https://nabeh.intaleqapp.com/api/otp/send';
$payload = [ $payload = [
'phone' => $phoneRaw, 'phone' => $phone,
'type' => $type, 'type' => $type,
'code' => $otp, 'code' => $otp,
'message' => "رمز التحقق الخاص بك لتطبيق {$appName} هو: *{code}* \n الرجاء عدم مشاركته مع أي شخص." 'message' => "رمز التحقق الخاص بك لتطبيق {$appName} هو: *{code}* \n الرجاء عدم مشاركته مع أي شخص."
@@ -170,7 +192,7 @@ function sendNabehOtp(string $receiver, string $otp, string $method = '', string
if ($response) { if ($response) {
$decoded = json_decode($response, true); $decoded = json_decode($response, true);
error_log("ℹ️ [Nabeh OTP Response] " . $response); error_log("ℹ️ [Nabeh OTP Response type=$type] " . $response);
if ($decoded) { if ($decoded) {
$statusStr = strtolower((string)($decoded['status'] ?? '')); $statusStr = strtolower((string)($decoded['status'] ?? ''));
$msgStr = strtolower((string)($decoded['message'] ?? '')); $msgStr = strtolower((string)($decoded['message'] ?? ''));
@@ -189,11 +211,11 @@ function sendNabehOtp(string $receiver, string $otp, string $method = '', string
return true; return true;
} }
} }
$msg = "❌ [Nabeh OTP Response Failed] Raw: " . $response; $msg = "❌ [Nabeh OTP type=$type] Response: " . $response;
$GLOBALS['last_otp_error'] = $msg; $GLOBALS['last_otp_error'] = $msg;
error_log($msg); error_log($msg);
} else { } else {
$msg = "❌ [Nabeh OTP cURL Failed] Empty response from cURL."; $msg = "❌ [Nabeh OTP type=$type] Empty cURL response.";
$GLOBALS['last_otp_error'] = $msg; $GLOBALS['last_otp_error'] = $msg;
error_log($msg); error_log($msg);
} }