Initial commit with updated Auth and media ignored
This commit is contained in:
0
auth/sms_new_backend/error_log
Normal file
0
auth/sms_new_backend/error_log
Normal file
134
auth/sms_new_backend/rasel_whatsapp.php
Executable file
134
auth/sms_new_backend/rasel_whatsapp.php
Executable file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
// تضمين ملف الاتصال بقاعدة البيانات والدوال المساعدة
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
// include "functions.php"; // افترض أن دالة filterRequest موجودة هنا
|
||||
|
||||
|
||||
// --- بداية التعديل: استخدام واجهة RaseelPlus API ---
|
||||
|
||||
// توليد رمز تحقق عشوائي مكون من 5 أرقام
|
||||
$otp = rand(10000, 99999);
|
||||
|
||||
// استقبال رقم الهاتف من الطلب
|
||||
// تأكد من أن دالة filterRequest تقوم بتنقية المدخلات بشكل آمن
|
||||
$receiver = filterRequest("receiver");
|
||||
|
||||
// رسالة الـ OTP. يمكنك تخصيصها حسب الحاجة
|
||||
// تذكر أن التطبيق اسمه Tripz-egypt.com
|
||||
$messageBody = "Your verification code for Tripz is: " . $otp;
|
||||
|
||||
// عنوان API الجديد
|
||||
$apiUrl = 'https://raseelplus.com/api/send';
|
||||
|
||||
// بيانات الطلب (Payload) الجديدة لتتوافق مع RaseelPlus
|
||||
$payload = [
|
||||
"number" => $receiver, // رقم المستلم
|
||||
"type" => "text",
|
||||
"message" => $messageBody,
|
||||
"instance_id" => "6863C59A7AFBD", // المعرف المأخوذ من مثال cURL
|
||||
"access_token"=> "68617b9b8fe53" // مفتاح الوصول المأخوذ من مثال cURL
|
||||
];
|
||||
|
||||
error_log("Sending OTP to $receiver via RaseelPlus. Message: $messageBody");
|
||||
|
||||
// استدعاء الـ API
|
||||
$response = callAPI("POST", $apiUrl, json_encode($payload));
|
||||
|
||||
error_log("RaseelPlus API Response: " . print_r($response, true));
|
||||
|
||||
// --- نهاية التعديل ---
|
||||
|
||||
|
||||
// التحقق من الاستجابة من الـ API
|
||||
// ملاحظة: قد تحتاج إلى تعديل هذا الشرط بناءً على شكل الاستجابة الفعلي من RaseelPlus
|
||||
// نفترض هنا أن الاستجابة الناجحة تحتوي على "status":"success" أو شيء مشابه
|
||||
if ($response && !isset($response->error) && (isset($response->status) && $response->status == 'success' || isset($response->message))) {
|
||||
|
||||
// تحديد وقت انتهاء صلاحية الرمز (بعد 5 دقائق)
|
||||
$expiration_time = date('Y-m-d H:i:s', strtotime('+5 minutes'));
|
||||
$created_at = date('Y-m-d H:i:s');
|
||||
|
||||
error_log("API call successful. Saving to DB: phone=$receiver, token=$otp, expires=$expiration_time");
|
||||
|
||||
try {
|
||||
// تشفير البيانات قبل حفظها (ممارسة أمنية جيدة)
|
||||
// $receiver_encrypted = $encryptionHelper->encryptData($receiver);
|
||||
// $otp_encrypted = $encryptionHelper->encryptData($otp);
|
||||
|
||||
// استخدام البيانات غير المشفرة مؤقتاً إذا لم تكن تستخدم التشفير حالياً
|
||||
$receiver_to_db = $receiver;
|
||||
$otp_to_db = $otp;
|
||||
|
||||
$stmt = $con->prepare("
|
||||
INSERT INTO phone_verification_passenger
|
||||
(phone_number, token, expiration_time, verified, created_at)
|
||||
VALUES (?, ?, ?, 0, ?)
|
||||
");
|
||||
$success = $stmt->execute([$receiver_to_db, $otp_to_db, $expiration_time, $created_at]);
|
||||
|
||||
if ($success) {
|
||||
error_log("OTP saved successfully to DB.");
|
||||
// jsonSuccess() هي دالة مخصصة لديك لطباعة استجابة نجاح
|
||||
jsonSuccess(null, 'OTP sent and saved successfully');
|
||||
} else {
|
||||
error_log("SQL execution failed.");
|
||||
// jsonError() هي دالة مخصصة لديك لطباعة استجابة فشل
|
||||
jsonError('OTP sent but failed to save to database');
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log("Database Error: " . $e->getMessage());
|
||||
jsonError('Database error occurred');
|
||||
}
|
||||
|
||||
} else {
|
||||
// فشل إرسال الـ OTP
|
||||
$errorMessage = isset($response->message) ? $response->message : "Unknown error";
|
||||
error_log("Failed to send OTP. API response: " . $errorMessage);
|
||||
jsonError('Failed to send OTP: ' . $errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* دالة لإجراء استدعاءات API باستخدام cURL
|
||||
* @param string $method نوع الطلب (e.g., "POST", "GET")
|
||||
* @param string $url عنوان URL للـ API
|
||||
* @param mixed $data البيانات المراد إرسالها
|
||||
* @return mixed الاستجابة من الـ API بعد فك تشفير JSON
|
||||
*/
|
||||
function callAPI($method, $url, $data)
|
||||
{
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true, // إرجاع الاستجابة كنص بدلاً من طباعتها
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30, // مهلة زمنية للطلب
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => $method,
|
||||
CURLOPT_POSTFIELDS => $data,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"Content-Type: application/json",
|
||||
"Accept: application/json"
|
||||
],
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($err) {
|
||||
error_log("cURL Error #: " . $err);
|
||||
return null; // إرجاع null في حالة وجود خطأ في cURL
|
||||
} else {
|
||||
return json_decode($response); // فك تشفير استجابة JSON
|
||||
}
|
||||
}
|
||||
|
||||
// مثال على دالة طباعة النجاح (ضعها في ملف functions.php)
|
||||
|
||||
|
||||
?>
|
||||
97
auth/sms_new_backend/sendOtpPassenger.php
Normal file
97
auth/sms_new_backend/sendOtpPassenger.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
|
||||
$text='444';
|
||||
|
||||
$encryptedText = $encryptionHelper->encryptData($text);
|
||||
|
||||
$username = getenv('SMS_USERNAME');
|
||||
$password = getenv('SMS_PASSWORD_EGYPT');
|
||||
$sender = getenv('SMS_SENDER');
|
||||
|
||||
$language = filterRequest("language");
|
||||
$receiver = filterRequest("receiver");
|
||||
|
||||
$otp = rand(10000, 99999);
|
||||
$message0 = "Tripz app code is " . $otp;
|
||||
|
||||
$apiUrl = 'https://sms.kazumi.me/api/sms/send-sms';
|
||||
|
||||
$payload = [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'language' => $language,
|
||||
'sender' => $sender,
|
||||
'receiver' => $receiver,
|
||||
'message' => $message0
|
||||
];
|
||||
|
||||
error_log("Sending SMS to $receiver with OTP: $otp");
|
||||
|
||||
$response = callAPI("POST", $apiUrl, json_encode($payload));
|
||||
|
||||
error_log("API Response: " . print_r($response, true));
|
||||
|
||||
// التحقق من رسالة الاستجابة
|
||||
if ($response && isset($response->message) && $response->message == "Success") {
|
||||
$expiration_time = date('Y-m-d H:i:s', strtotime('+5 minutes'));
|
||||
$created_at = date('Y-m-d H:i:s');
|
||||
|
||||
error_log("Saving to DB: phone=$receiver, token=$otp, expires=$expiration_time");
|
||||
|
||||
try {
|
||||
$receiver1=$encryptionHelper->encryptData($receiver);
|
||||
$otp1=$encryptionHelper->encryptData($otp);
|
||||
|
||||
$stmt = $con->prepare("
|
||||
INSERT INTO phone_verification_passenger
|
||||
(phone_number, token, expiration_time, verified, created_at)
|
||||
VALUES (?, ?, ?, 0, ?)
|
||||
");
|
||||
$success = $stmt->execute([$receiver1, $otp1, $expiration_time, $created_at]);
|
||||
|
||||
if ($success) {
|
||||
error_log("OTP saved successfully to DB.");
|
||||
jsonSuccess(null, 'OTP sent and saved successfully');
|
||||
} else {
|
||||
error_log("SQL execution failed.");
|
||||
jsonError('OTP sent but not saved to database');
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log("Database Error: " . $e->getMessage());
|
||||
jsonError('Database error');
|
||||
}
|
||||
|
||||
} else {
|
||||
error_log("OTP not sent. API response did not indicate success. Response: " . print_r($response, true));
|
||||
jsonError('OTP not sent');
|
||||
}
|
||||
|
||||
// دالة التعامل مع API
|
||||
function callAPI($method, $url, $data)
|
||||
{
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_CUSTOMREQUEST => $method,
|
||||
CURLOPT_POSTFIELDS => $data,
|
||||
CURLOPT_HTTPHEADER => ["Content-Type: application/json"]
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
if (curl_errno($curl)) {
|
||||
error_log("cURL Error: " . curl_error($curl));
|
||||
}
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
return json_decode($response);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user