نسخة كاملة من مستودع سيرو عند ecfe7568 لتكون أساس تطبيق «انطلق». نُسخ المتعقَّب في git فقط (12,509 ملفاً / 302 م.ب) بـ git archive، لا `cp -r` — فاستُثنيت تلقائياً مخلفات البناء (build · node_modules · .dart_tool · .gradle · Pods ≈ 10.7 غ.ب) وكل ما يستثنيه .gitignore. هذا الكوميت **بلا أي تعديل عمداً** حتى يكون كل ما يليه فرقاً مقروءاً مقابل سيرو الأصلي. سيرو نفسه لم يُمسّ. ⚠️ لا يبني بعد: `.env` و`lib/env/env.g.dart` غير متعقَّبين في سيرو (وهذا صحيح — أسرار لكل مستأجر). كل تطبيق فلاتر هنا يحتاج .env خاصاً بانطلق ثم توليد env.g.dart عبر build_runner. لا تُنسخ أسرار سيرو. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
87 lines
2.6 KiB
PHP
87 lines
2.6 KiB
PHP
<?php
|
|
// File: send_otp_driver.php (إصدار بدون RaseelPlus)
|
|
require_once __DIR__ . '/../../../connect.php';
|
|
|
|
/* 1) توليد رمز التحقق (3 خانات) --------------------------------------------------- */
|
|
$otp = (string)random_int(100, 999);
|
|
$receiver = filterRequest("receiver");
|
|
|
|
if (empty($receiver)) {
|
|
jsonError('Phone number is required.');
|
|
exit();
|
|
}
|
|
|
|
/* 2) إرسال عبر بوابة الفلاش كول / واتساب ------------------------------ */
|
|
$nabehUrl = 'https://otp.intaleqapp.com/api/request-otp.php';
|
|
$appKey = getenv('NABEH_OTP_APP_KEY');
|
|
|
|
$payload = [
|
|
'phone' => $receiver,
|
|
'device_type' => 'android',
|
|
'method' => 'whatsapp',
|
|
'code' => $otp
|
|
];
|
|
|
|
$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
|
|
]);
|
|
|
|
$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 Driver] 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) تشفير البيانات وحفظها في DB ----------------------------------- */
|
|
$receiver_enc = otpPhoneKey($receiver);
|
|
$otp_enc = otpPhoneKey($otp); // يجب أن يطابق صيغة المقارنة في verify_otp
|
|
|
|
$exp = date('Y-m-d H:i:s', strtotime('+5 minutes'));
|
|
$now = date('Y-m-d H:i:s');
|
|
|
|
try {
|
|
// حذف رموز قديمة
|
|
$con->prepare("DELETE FROM token_verification_driver WHERE phone_number = ?")
|
|
->execute([$receiver_enc]);
|
|
|
|
$stmt = $con->prepare("
|
|
INSERT INTO token_verification_driver
|
|
(phone_number, token, expiration_time, verified, created_at)
|
|
VALUES (?, ?, ?, 0, ?)
|
|
");
|
|
$stmt->execute([$receiver_enc, $otp_enc, $exp, $now]);
|
|
|
|
// Also save to Redis for verify_otp compatibility
|
|
if ($redis) {
|
|
$redis->setex("otp:driver:$receiver", 300, $otp);
|
|
}
|
|
|
|
jsonSuccess(null, 'OTP sent and saved successfully');
|
|
|
|
} catch (PDOException $e) {
|
|
error_log("[send_otp_driver.php] " . $e->getMessage());
|
|
jsonError('OTP sent but failed to save to database');
|
|
}
|
|
|
|
} else {
|
|
jsonError('Failed to send OTP');
|
|
}
|
|
?>
|