Autosave: 20260215-064658
This commit is contained in:
parent
e7ab037971
commit
edbd851f2b
@ -62,14 +62,20 @@ class WablasService {
|
||||
$data = [
|
||||
'phone' => $to,
|
||||
'image' => $imageUrl,
|
||||
'caption' => $caption
|
||||
'caption' => rawurlencode($caption)
|
||||
];
|
||||
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, ["Authorization: $token"]);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: $token",
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($jsonData)
|
||||
]);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonData);
|
||||
curl_setopt($curl, CURLOPT_URL, rtrim($serverUrl, '/') . "/api/send-image");
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
@ -98,7 +104,7 @@ class WablasService {
|
||||
return ($lang === 'ar') ? ($org['name_ar'] ?? 'المنظمة') : ($org['name_en'] ?? 'Organization');
|
||||
}
|
||||
|
||||
private static function sendTemplatedMessage($to, $templateName, $vars, $lang = 'en', $useImage = true) {
|
||||
private static function sendTemplatedMessage($to, $templateName, $vars, $lang = 'en') {
|
||||
if (empty($to)) {
|
||||
return ['success' => false, 'error' => 'Recipient phone number is missing.'];
|
||||
}
|
||||
@ -112,6 +118,10 @@ class WablasService {
|
||||
error_log("WhatsApp template '$templateName' not found or is disabled.");
|
||||
return ['success' => false, 'error' => "Template '$templateName' not found or disabled."];
|
||||
}
|
||||
|
||||
$settings_stmt = $pdo->query("SELECT setting_key, setting_value FROM settings WHERE setting_key = 'whatsapp_send_cards'");
|
||||
$settings = $settings_stmt->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||
$useImage = isset($settings['whatsapp_send_cards']) && $settings['whatsapp_send_cards'] == '1';
|
||||
|
||||
$messageBody = ($lang === 'ar' && !empty($template['template_body_ar'])) ? $template['template_body_ar'] : $template['template_body_en'];
|
||||
|
||||
@ -120,8 +130,14 @@ class WablasService {
|
||||
}
|
||||
|
||||
if ($useImage) {
|
||||
// ToDo: Find a way to get the base URL
|
||||
$siteUrl = 'http://' . $_SERVER['HTTP_HOST'];
|
||||
if (getenv('FULL_DOMAIN')) {
|
||||
$siteUrl = 'https://' . getenv('FULL_DOMAIN');
|
||||
} elseif (php_sapi_name() === 'cli') {
|
||||
$siteUrl = getenv('APP_URL') ?: 'http://localhost';
|
||||
} else {
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
|
||||
$siteUrl = "$protocol://" . $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
$imageUrl = $siteUrl . '/admin/generate_card.php?' . http_build_query([
|
||||
'text' => $messageBody,
|
||||
'lang' => $lang,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user