Initial commit with updated Auth and media ignored
This commit is contained in:
65
auth/token_passenger/send_otp.php
Executable file
65
auth/token_passenger/send_otp.php
Executable file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// File: send_otp.php (بديل عن النسخة المعتمدة على RaseelPlus)
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
/* 1) توليد رمز التحقق */
|
||||
$otp = rand(10000, 99999);
|
||||
$receiver = filterRequest("receiver");
|
||||
|
||||
if (empty($receiver)) {
|
||||
jsonError('Phone number is required.');
|
||||
exit();
|
||||
}
|
||||
|
||||
/* 2) نصّ الرسالة وإرسالها عبر دالتك الجديدة */
|
||||
$messageBody = "Your verification code for Intaleq is: " . $otp;
|
||||
|
||||
$raw = sendWhatsAppFromServer($receiver, $messageBody);
|
||||
$response = is_string($raw) ? json_decode($raw, true) : (array) $raw;
|
||||
|
||||
/*
|
||||
* نتوقع بنية مثل:
|
||||
* [
|
||||
* 'success' => true,
|
||||
* 'details' => ['status' => 'PENDING' | 'SENT' | …]
|
||||
* ]
|
||||
*/
|
||||
$sentOK = $response['success'] ?? false;
|
||||
$statusOK = in_array($response['details']['status'] ?? '', ['PENDING', 'SENT', 'DELIVERED'], true);
|
||||
|
||||
if ($sentOK ) {
|
||||
|
||||
/* 3) تشفير البيانات وحفظ الرمز في قاعدة البيانات */
|
||||
$receiver_enc = $encryptionHelper->encryptData($receiver);
|
||||
$otp_enc = $encryptionHelper->encryptData($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 WHERE phone_number = ?")
|
||||
->execute([$receiver_enc]);
|
||||
|
||||
$stmt = $con->prepare("
|
||||
INSERT INTO token_verification
|
||||
(phone_number, token, expiration_time, verified, created_at)
|
||||
VALUES (?, ?, ?, 0, ?)
|
||||
");
|
||||
$stmt->execute([$receiver_enc, $otp_enc, $exp, $now]);
|
||||
|
||||
jsonSuccess(null, 'OTP sent and saved successfully');
|
||||
|
||||
} catch (PDOException $e) {
|
||||
jsonError('OTP sent but failed to save to database');
|
||||
}
|
||||
|
||||
} else {
|
||||
$errMsg = $response['message'] ?? 'Unknown error';
|
||||
jsonError('Failed to send OTP: ' . $errMsg);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------
|
||||
* يمكن حذف callAPI() تمامًا إن لم يعد مستخدمًا في أي ملف آخر.
|
||||
* ---------------------------------------------------------------- */
|
||||
function callAPI($method, $url, $data) { /* … (أبقِها أو احذفها) */ }
|
||||
?>
|
||||
Reference in New Issue
Block a user