add new features like realtime 2026-05-29-22

This commit is contained in:
Hamza-Ayed
2026-05-29 22:41:24 +03:00
parent f89b04f614
commit e9be1b6d4a
6 changed files with 240 additions and 193 deletions

View File

@@ -2,8 +2,8 @@
// File: send_otp.php (بديل عن النسخة المعتمدة على RaseelPlus)
require_once __DIR__ . '/../../connect.php';
/* 1) توليد رمز التحقق */
$otp = rand(10000, 99999);
/* 1) توليد رمز التحقق (3 خانات) */
$otp = (string)rand(100, 999);
$receiver = filterRequest("receiver");
if (empty($receiver)) {
@@ -11,24 +11,45 @@ if (empty($receiver)) {
exit();
}
/* 2) نصّ الرسالة وإرسالها عبر دالتك الجديدة */
$messageBody = "Your verification code for Intaleq is: " . $otp;
/* 2) إرسال عبر بوابة الفلاش كول / واتساب */
$nabehUrl = 'https://otp.intaleqapp.com/api/request-otp.php';
$appKey = getenv('NABEH_OTP_APP_KEY');
$raw = sendWhatsAppFromServer($receiver, $messageBody);
$response = is_string($raw) ? json_decode($raw, true) : (array) $raw;
$payload = [
'phone' => $receiver,
'device_type' => 'android',
'method' => 'whatsapp',
'code' => $otp
];
/*
* نتوقع بنية مثل:
* [
* 'success' => true,
* 'details' => ['status' => 'PENDING' | 'SENT' | …]
* ]
*/
$sentOK = $response['success'] ?? false;
$statusOK = in_array($response['details']['status'] ?? '', ['PENDING', 'SENT', 'DELIVERED'], true);
$ch = curl_init($nabehUrl);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
"X-App-Key: $appKey"
],
CURLOPT_TIMEOUT => 15,
CURLOPT_CONNECTTIMEOUT => 5
]);
if ($sentOK ) {
$res = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
error_log("⚠️ [Flash Call OTP Token Passenger] Curl Error: $error");
jsonError('Failed to connect to OTP service');
exit;
}
$decoded = json_decode((string)$res, true);
$sentOK = ($httpCode === 200 && ($decoded['success'] ?? false));
if ($sentOK) {
/* 3) تشفير البيانات وحفظ الرمز في قاعدة البيانات */
$receiver_enc = $encryptionHelper->encryptData($receiver);
$otp_enc = $encryptionHelper->encryptData($otp);
@@ -54,7 +75,7 @@ if ($sentOK ) {
}
} else {
$errMsg = $response['message'] ?? 'Unknown error';
$errMsg = $decoded['message'] ?? 'Unknown error';
jsonError('Failed to send OTP: ' . $errMsg);
}