<?php
$api_key = 'YOUR_API_KEY';
$lotto_id = '100'; // หวยรัฐบาลไทย
$url = "https://lotto.nuynt.com/?api_key={$api_key}&lotto_id={$lotto_id}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // ในกรณีใช้ SSL แบบ Local
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode == 200) {
$data = json_decode($response, true);
if ($data['code'] == 200) {
echo "ชื่อหวย: " . $data['lotto_name'] . "\n";
echo "ผลรางวัล:\n";
foreach ($data['result'] as $type => $value) {
echo "- {$type}: {$value}\n";
}
} else {
echo "API Error: " . $data['message'];
}
} else {
echo "HTTP Error: {$httpcode}";
}
?>