Files
Siro/backend/auth/sms/sms_to_user_change_fingerprint.php
2026-06-09 08:40:31 +03:00

68 lines
2.0 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/../../connect.php';
// استقبال رقم الهاتف
$phone = filterRequest('phone');
$language = filterRequest('lang') ?? 'r';
// 1⃣ جلب بيانات API من البيئة
$username = "Sefer";
$password = getenv("SMS_PASSWORD_EGYPT");
$apiEndpoint = getenv("SMS_API_ENDPOINT");
$sender = "SEFER";
$appName = "Tripz";
if (!$password || !$apiEndpoint) {
jsonError("API configuration is missing");
exit;
}
// 2⃣ توليد كود OTP من السيرفر
$otp = rand(100000, 999999);
// 3⃣ تشفير البيانات قبل تخزينها
$phoneEncrypted = $encryptionHelper->encryptData($phone);
$otpEncrypted = $encryptionHelper->encryptData($otp);
// 4⃣ تخزين OTP في قاعدة البيانات
try {
$insertOtp = "INSERT INTO otp_verification_fingerPrint (phone, otp) VALUES (?, ?)";
$stmt = $con->prepare($insertOtp);
$stmt->execute([$phoneEncrypted, $otpEncrypted]);
} catch (PDOException $e) {
error_log("DB Insert Error: " . $e->getMessage());
jsonError("Failed to save OTP to the database");
exit;
}
// 5⃣ إرسال الرسالة عبر API
$message = "$appName app code is $otp\ncopy it to app";
$payload = json_encode([
"username" => $username,
"password" => $password,
"message" => $message,
"language" => $language,
"sender" => $sender,
"receiver" => $phone
]);
$ch = curl_init($apiEndpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// 6⃣ التحقق من نجاح الإرسال
if ($httpCode != 200) {
error_log("SMS API Failed. HTTP Code: $httpCode. Response: " . $response);
jsonError("Failed to send OTP SMS");
exit;
}
// 7⃣ إرجاع النتيجة
jsonSuccess(["message" => "OTP sent successfully"]);
?>