<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Altın Fiyatları</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
            overflow: hidden;
        }
        .header {
            background: linear-gradient(45deg, #FFD700, #FFA500);
            color: white;
            padding: 20px;
            text-align: center;
        }
        .header h1 {
            margin: 0;
            font-size: 2.5em;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }
        .table-container {
            padding: 20px;
            overflow-x: auto;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 0;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
        th {
            background: linear-gradient(45deg, #2c3e50, #3498db);
            color: white;
            padding: 15px 10px;
            text-align: center;
            font-weight: bold;
            font-size: 14px;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        td {
            padding: 12px 10px;
            text-align: center;
            border-bottom: 1px solid #eee;
            transition: background-color 0.3s ease;
        }
        tr:hover {
            background-color: #f8f9fa;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        .price {
            font-weight: bold;
            font-size: 16px;
        }
        .satis { color: #e74c3c; }
        .geri-alis { color: #27ae60; }
        .takas { color: #f39c12; }
        .symbol-name {
            font-weight: bold;
            color: #2c3e50;
            text-align: left;
            padding-left: 15px;
        }
        .last-update {
            color: #7f8c8d;
            font-size: 12px;
        }
        .refresh-btn {
            background: linear-gradient(45deg, #3498db, #2ecc71);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            margin: 20px;
            font-size: 16px;
            transition: all 0.3s ease;
        }
        .refresh-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }
        @media (max-width: 768px) {
            .header h1 {
                font-size: 1.8em;
            }
            th, td {
                padding: 8px 5px;
                font-size: 12px;
            }
        }
    </style>
</head>
<body>
<?php
date_default_timezone_set('Europe/Istanbul');
class GenesisPanoAPI {
private $baseURL = "https://genesispano.com/servis/";
private $authCodeName;
private $authCode;
public function __construct($authCodeName, $authCode) {
$this->authCodeName = $authCodeName;
$this->authCode = $authCode;
}
private function makeRequest($action, $extraParams = []) {
$postData = array_merge([
'AuthCodeName' => $this->authCodeName,
'AuthCode' => $this->authCode,
'Action' => $action
], $extraParams);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->baseURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($postData),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
CURLOPT_TIMEOUT => 30
));
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($httpCode === 200) {
return json_decode($response, true);
} else {
throw new Exception("API İsteği başarısız: HTTP $httpCode");
}
}
public function getLastPrices() {
return $this->makeRequest('GetLastPrices');
}
public function getProductList($category = null, $limit = null) {
$params = [];
if ($category) $params['category'] = $category;
if ($limit) $params['limit'] = $limit;
return $this->makeRequest('GetProductList', $params);
}
public function getStock($productId) {
return $this->makeRequest('GetStock', ['product_id' => $productId]);
}
public function updateStock($productId, $quantity) {
return $this->makeRequest('UpdateStock', [
'product_id' => $productId,
'quantity' => $quantity
]);
}
// Fiyat tablosunu HTML olarak oluşturan fonksiyon
public function generatePriceTable($prices) {
if (!isset($prices['Result']) || !is_array($prices['Result'])) {
return '<div class="error">Veri bulunamadı veya hatalı format.</div>';
}
$html = '<div class="container">';
$html .= '<div class="header">';
$html .= '<h1>💰 Güncel Altın Fiyatları</h1>';
$html .= '<p>Son güncelleme: ' . date('d.m.Y H:i:s') . '</p>';
$html .= '</div>';
$html .= '<div class="table-container">';
$html .= '<table>';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>Ürün Adı</th>';
$html .= '<th>Satış Fiyatı</th>';
$html .= '<th>Geri Alış</th>';
$html .= '<th>Takas</th>';
$html .= '<th>Son Güncelleme</th>';
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
foreach ($prices['Result'] as $item) {
$html .= '<tr>';
$html .= '<td class="symbol-name">' . htmlspecialchars($item['SembolAdi']) . '</td>';
$html .= '<td class="price satis">' . number_format($item['Satis'], 0, ',', '.') . ' ₺</td>';
$html .= '<td class="price geri-alis">' . number_format($item['GeriAlis'], 0, ',', '.') . ' ₺</td>';
$html .= '<td class="price takas">' . number_format($item['Takas'], 0, ',', '.') . ' ₺</td>';
$html .= '<td class="last-update">' . date('d.m.Y H:i', strtotime($item['LastUpdate'])) . '</td>';
$html .= '</tr>';
}
$html .= '</tbody>';
$html .= '</table>';
$html .= '</div>';
$html .= '<center><button class="refresh-btn" onclick="location.reload()">🔄 Yenile</button></center>';
$html .= '</div>';
return $html;
}
}
// Kullanım örneği
try {
$api = new GenesisPanoAPI('Ayn', 'RAK');
// Güncel fiyatları al
$prices = $api->getLastPrices();
// Başarılı yanıt kontrolü
if (isset($prices['ResponseMsg']) && $prices['ResponseMsg'] === 'SUCCESSFUL') {
// Tabloyu oluştur ve göster
echo $api->generatePriceTable($prices);
} else {
echo '<div class="container">';
echo '<div class="header"><h1>⚠️ Hata</h1></div>';
echo '<div class="table-container">';
echo '<p>API\'den veri alınamadı. Lütfen daha sonra tekrar deneyin.</p>';
echo '</div>';
echo '</div>';
}
} catch (Exception $e) {
echo '<div class="container">';
echo '<div class="header"><h1>⚠️ Hata</h1></div>';
echo '<div class="table-container">';
echo '<p>Hata: ' . htmlspecialchars($e->getMessage()) . '</p>';
echo '</div>';
echo '</div>';
}
?>
</body>
</html>
Veri testini yapamadım, yetkilendirme gerekiyordu.