add new features like realtime 2026-05-29-22
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
// File: send_otp_driver.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,25 +11,45 @@ if (empty($receiver)) {
|
||||
exit();
|
||||
}
|
||||
|
||||
/* 2) نص الرسالة وإرسالها عبر دالتك الجديدة ------------------------------ */
|
||||
$messageBody = "رمز التحقق الخاص بك لتطبيق انطلق درايفر هو: " . $otp;
|
||||
/* 2) إرسال عبر بوابة الفلاش كول / واتساب ------------------------------ */
|
||||
$nabehUrl = 'https://otp.intaleqapp.com/api/request-otp.php';
|
||||
$appKey = getenv('NABEH_OTP_APP_KEY');
|
||||
|
||||
/**
|
||||
* نفترض أن sendWhatsAppFromServer() تُرجع:
|
||||
* [
|
||||
* 'success' => true/false,
|
||||
* 'message' => 'Message sent successfully!',
|
||||
* 'details' => ['status' => 'PENDING' | 'SENT' | …]
|
||||
* ]
|
||||
*/
|
||||
$raw = sendWhatsAppFromServer($receiver, $messageBody);
|
||||
$response = is_string($raw) ? json_decode($raw, true) : (array) $raw;
|
||||
$payload = [
|
||||
'phone' => $receiver,
|
||||
'device_type' => 'android',
|
||||
'method' => 'whatsapp',
|
||||
'code' => $otp
|
||||
];
|
||||
|
||||
$sentOK = $response['success'] ?? false;
|
||||
$waStatus = $response['details']['status'] ?? '';
|
||||
$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 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 = $encryptionHelper->encryptData($receiver);
|
||||
$otp_enc = $encryptionHelper->encryptData($otp);
|
||||
@@ -56,7 +76,7 @@ if ($sentOK ) {
|
||||
}
|
||||
|
||||
} else {
|
||||
$errMsg = $response['message'] ?? 'Unknown error';
|
||||
$errMsg = $decoded['message'] ?? 'Unknown error';
|
||||
jsonError('Failed to send OTP: ' . $errMsg);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user