Deploy: 2026-05-23 02:09:23

This commit is contained in:
Hamza-Ayed
2026-05-23 02:09:23 +03:00
parent 7ae5964ce1
commit b5e4f48be5
4 changed files with 27 additions and 26 deletions

View File

@@ -17,14 +17,6 @@ class OTPController extends BaseController
*/
private function generateOtpImage(string $code): string
{
$dir = __DIR__ . '/../../public/otp';
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$filename = 'otp_' . time() . '_' . rand(1000, 9999) . '.png';
$filepath = $dir . '/' . $filename;
if (function_exists('imagecreate')) {
// Base image
$img = imagecreatetruecolor(400, 200);
@@ -74,21 +66,20 @@ class OTPController extends BaseController
// Scale up the text image to the main image using resampled for smooth (non-pixelated) edges
imagecopyresampled($img, $tmp, 0, 0, 0, 0, 400, 200, 100, 40);
imagepng($img, $filepath);
ob_start();
imagepng($img);
$imageData = ob_get_clean();
imagedestroy($img);
imagedestroy($tmp);
return base64_encode($imageData);
} else {
// Fallback to placehold.co if PHP GD extension is missing
$url = "https://placehold.co/400x200/e0f2fe/0f172a/png?text=" . $code . "&font=oswald";
$content = file_get_contents($url);
file_put_contents($filepath, $content);
return base64_encode($content);
}
$appUrl = rtrim(getenv('APP_URL') ?: 'https://nabeh.intaleqapp.com', '/');
if (strpos($appUrl, 'localhost') !== false || strpos($appUrl, '127.0.0.1') !== false) {
$appUrl = 'https://nabeh.intaleqapp.com';
}
return $appUrl . '/otp/' . $filename;
}
/**
@@ -222,9 +213,9 @@ class OTPController extends BaseController
// Send voice note
ConversationFlowEngine::sendReply($session, $phone, '', null, $audioBase64, $mimeType);
} else if ($type === 'image') {
// Generate OTP Image
$imageUrl = $this->generateOtpImage($code);
ConversationFlowEngine::sendReply($session, $phone, '', $imageUrl);
// Generate OTP Image as Base64
$imageBase64 = $this->generateOtpImage($code);
ConversationFlowEngine::sendReply($session, $phone, '', null, null, null, $imageBase64);
} else {
// Send text
$textMsg = "رمز التحقق الخاص بك لمتجر نابه هو: *{$code}* \n الرجاء عدم مشاركته مع أي شخص.";