<?php
// API credentials
$user = '4w9aAzzbvM';
$pass = 'vHH3NlIMtymQb5MPi0CSUeJxjERdnkNNJkpPu39X';
$to = '60164131320';
$from = 'TLS2U';
//$text = 'Hello, this is a test message from yeye';
$text = $from . PHP_EOL ."Tahniah! Pendaftaran anda berjaya. ".PHP_EOL."ID: ".PHP_EOL."Password: ";

// API URL
$url = 'https://sms.360.my/gw/bulk360/v3_0/send.php';

// Prepare data
$data = [
    'user' => $user,
    'pass' => $pass,
    'to' => $to,
    'from' => $from,
    'text' => $text,
    'detail' => 1
];

// Initialize cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

// Execute and get response
$response = curl_exec($ch);
curl_close($ch);

// Output response
echo 'API Response: ' . $response;

// Decode JSON
$result = json_decode($response, true);

// Output response
if ($result) {
    echo "API Code: " . $result['code'] . PHP_EOL;
    echo "Description: " . $result['desc'] . PHP_EOL;
    echo "Balance: " . ($result['balance'] ?? 'N/A') . " " . ($result['currency'] ?? '') . PHP_EOL;
} else {
    echo "Raw Response: " . $response;
}
?>
