/
/
home
/
u523034047
/
domains
/
eipcsindia.com
/
public_html
/
wap
Server: in-mum-web1112.main-hosting.eu (62.72.28.111)
You: 216.73.216.52
PHP 8.3.16
Dir:
/home/u523034047/domains/eipcsindia.com/public_html/wap
Edit:
/home/u523034047/domains/eipcsindia.com/public_html/wap/run_broadcast.php
<?php require 'config.php'; ensureAdmin(); set_time_limit(0); $id = intval($_GET['id']); // mark running $pdo->prepare('UPDATE broadcasts SET status=? WHERE id=?')->execute(['running',$id]); // fetch queued items $items = $pdo->prepare('SELECT bi.*, c.name, c.vars FROM broadcast_items bi LEFT JOIN contacts c ON c.id=bi.contact_id WHERE bi.broadcast_id=? AND bi.status="queued"'); $items->execute([$id]); $rows = $items->fetchAll(); $sent=0;$failed=0; foreach($rows as $r){ // simple payload based on stored JSON - in practice build template API JSON $tpl = json_decode($r['payload'], true); // Example template message body (adjust to your template): $body = [ 'messaging_product' => 'whatsapp', 'to' => $r['to_phone'], 'type' => 'template', 'template' => [ 'name' => $tpl['template_name'], 'language' => ['code' => $tpl['language']], 'components' => $tpl['components'] ] ]; $payload = json_encode($body, JSON_UNESCAPED_UNICODE); $url = 'https://graph.facebook.com/v21.0/'.WA_PHONE_NUMBER_ID.'/messages'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer '.WA_ACCESS_TOKEN, 'Content-Type: application/json' ]); $resp = curl_exec($ch); $err = curl_error($ch); curl_close($ch); // store result $pdo->prepare('UPDATE broadcast_items SET result=?, status=? WHERE id=?') ->execute([$resp, $err? 'failed' : 'sent', $r['id']]); if($err){ $failed++; } else { $sent++; } // small pause to avoid rate limit spikes usleep(200000); // 200ms } // update broadcast counts $pdo->prepare('UPDATE broadcasts SET sent=?, failed=?, status=? WHERE id=?') ->execute([$sent,$failed,'completed',$id]); header('Location: broadcasts.php');exit;
Ukuran: 1.9 KB