Deploy: 2026-06-24 15:01:02
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* WhatsApp Gateway Webhook Receiver & QR Code Viewer
|
||||
* WhatsApp Gateway Webhook Receiver & QR Code Viewer (6 Slots)
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../includes/Redis.php';
|
||||
@@ -10,7 +10,6 @@ $redis = RedisClient::getInstance();
|
||||
|
||||
// Handle Gateway POST requests (state changes, QR code delivery)
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Authenticate gateway request using webhook secret
|
||||
$secret = $_SERVER['HTTP_X_WEBHOOK_SECRET'] ?? '';
|
||||
$expectedSecret = $_ENV['WHATSAPP_WEBHOOK_SECRET'] ?? $_SERVER['WHATSAPP_WEBHOOK_SECRET'] ?? getenv('WHATSAPP_WEBHOOK_SECRET') ?: 'flash_call_otp_webhook_secret_key';
|
||||
|
||||
@@ -21,21 +20,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
if ($input && isset($input['state'])) {
|
||||
if ($input && isset($input['state']) && isset($input['session_key'])) {
|
||||
$state = $input['state'];
|
||||
$redis->set("whatsapp:status", $state);
|
||||
$sessionKey = $input['session_key'];
|
||||
|
||||
$redis->set("whatsapp:{$sessionKey}:status", $state);
|
||||
|
||||
if ($state === 'waiting_qr' && isset($input['qr_code'])) {
|
||||
// Store QR code for 60 seconds
|
||||
$redis->setex("whatsapp:qr", 60, $input['qr_code']);
|
||||
$redis->setex("whatsapp:{$sessionKey}:qr", 60, $input['qr_code']);
|
||||
} elseif ($state === 'connected') {
|
||||
$redis->del("whatsapp:qr");
|
||||
$redis->del("whatsapp:{$sessionKey}:qr");
|
||||
if (isset($input['phone'])) {
|
||||
$redis->set("whatsapp:phone", $input['phone']);
|
||||
$redis->set("whatsapp:{$sessionKey}:phone", $input['phone']);
|
||||
}
|
||||
} elseif ($state === 'disconnected') {
|
||||
$redis->del("whatsapp:qr");
|
||||
$redis->del("whatsapp:phone");
|
||||
$redis->del("whatsapp:{$sessionKey}:qr");
|
||||
$redis->del("whatsapp:{$sessionKey}:phone");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +43,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Handle GET requests (Human Web Interface to scan QR code)
|
||||
$status = $redis->get("whatsapp:status") ?: 'disconnected';
|
||||
$qrCode = $redis->get("whatsapp:qr");
|
||||
$phone = $redis->get("whatsapp:phone");
|
||||
// Prepare slots data for UI
|
||||
$slots = [];
|
||||
for ($i = 1; $i <= 6; $i++) {
|
||||
$sk = "slot-{$i}";
|
||||
$slots[$sk] = [
|
||||
'status' => $redis->get("whatsapp:{$sk}:status") ?: 'disconnected',
|
||||
'qr' => $redis->get("whatsapp:{$sk}:qr"),
|
||||
'phone' => $redis->get("whatsapp:{$sk}:phone")
|
||||
];
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="ar" dir="rtl">
|
||||
@@ -61,25 +67,32 @@ $phone = $redis->get("whatsapp:phone");
|
||||
font-family: 'Cairo', sans-serif;
|
||||
background-color: #f0f4f8;
|
||||
color: #333;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
.container {
|
||||
background: #fff;
|
||||
padding: 30px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
|
||||
.header {
|
||||
text-align: center;
|
||||
max-width: 400px;
|
||||
width: 100%;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 22px;
|
||||
margin-bottom: 20px;
|
||||
color: #111;
|
||||
.grid-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
|
||||
gap: 20px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.card {
|
||||
background: #fff;
|
||||
padding: 25px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 15px rgba(0,0,0,0.05);
|
||||
text-align: center;
|
||||
}
|
||||
.slot-title {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 15px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
@@ -87,83 +100,45 @@ $phone = $redis->get("whatsapp:phone");
|
||||
border-radius: 20px;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
margin-bottom: 25px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.status-connected {
|
||||
background-color: #d1e7dd;
|
||||
color: #0f5132;
|
||||
}
|
||||
.status-waiting_qr {
|
||||
background-color: #fff3cd;
|
||||
color: #664d03;
|
||||
}
|
||||
.status-disconnected {
|
||||
background-color: #f8d7da;
|
||||
color: #842029;
|
||||
}
|
||||
#qrcode {
|
||||
.status-connected { background-color: #d1e7dd; color: #0f5132; }
|
||||
.status-waiting_qr { background-color: #fff3cd; color: #664d03; }
|
||||
.status-disconnected { background-color: #f8d7da; color: #842029; }
|
||||
|
||||
.qrcode-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 20px 0;
|
||||
padding: 15px;
|
||||
margin: 15px 0;
|
||||
padding: 10px;
|
||||
background: #fff;
|
||||
border: 1px solid #eee;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.instructions {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
margin-top: 20px;
|
||||
min-height: 200px;
|
||||
align-items: center;
|
||||
}
|
||||
.refresh-btn {
|
||||
background-color: #0d6efd;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
padding: 8px 16px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-family: 'Cairo', sans-serif;
|
||||
font-weight: 600;
|
||||
margin-top: 15px;
|
||||
margin-top: 10px;
|
||||
transition: 0.2s;
|
||||
}
|
||||
.refresh-btn:hover {
|
||||
background-color: #0b5ed7;
|
||||
.refresh-btn:hover { background-color: #0b5ed7; }
|
||||
.global-refresh {
|
||||
display: block;
|
||||
margin: 20px auto;
|
||||
font-size: 16px;
|
||||
padding: 12px 24px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>ربط بوابة الواتساب بالخدمة</h1>
|
||||
|
||||
<?php if ($status === 'connected'): ?>
|
||||
<div class="status-badge status-connected">متصل بنجاح ✅</div>
|
||||
<p>البوابة نشطة حالياً ومتصلة بالرقم: <strong>+<?php echo htmlspecialchars($phone); ?></strong></p>
|
||||
<p style="color: green; font-size: 15px;">يمكنك البدء بإرسال الرسائل الآن!</p>
|
||||
<?php elseif ($status === 'waiting_qr' && $qrCode): ?>
|
||||
<div class="status-badge status-waiting_qr">بانتظار المسح (QR) 📲</div>
|
||||
<p>افتح الواتساب على هاتفك -> الأجهزة المرتبطة -> ربط جهاز، ثم امسح الكود أدناه:</p>
|
||||
|
||||
<div id="qrcode"></div>
|
||||
<script>
|
||||
new QRCode(document.getElementById("qrcode"), {
|
||||
text: "<?php echo $qrCode; ?>",
|
||||
width: 250,
|
||||
height: 250
|
||||
});
|
||||
</script>
|
||||
|
||||
<button class="refresh-btn" onclick="window.location.reload();">تحديث الصفحة 🔄</button>
|
||||
<?php else: ?>
|
||||
<div class="status-badge status-disconnected">غير متصل ❌</div>
|
||||
<p class="instructions">
|
||||
الرجاء تشغيل الجلسة أولاً عن طريق إرسال طلب البدء للبوابة من بوستمان أو سكريبت التشغيل.
|
||||
</p>
|
||||
<button class="refresh-btn" onclick="window.location.reload();">تحديث حالة الاتصال 🔄</button>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="instructions" style="border-top: 1px solid #eee; padding-top: 15px;">
|
||||
<p>حالة النظام الحالية: <strong><?php echo htmlspecialchars($status); ?></strong></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user