API Dokümantasyonu
1. Genel Bilgi
- API Sunucu URL'si:
https://vkptrg.yjmelqyefm.net/api
- API Anahtarı:
70Bp3tGkuV4jUfcxupDNg6Hrk
- Mağaza ID (shop_id):
1
- Para Birimi:
TRY
- Zaman Damgası (timestamp): Her çağrıda
time() fonksiyonu ile oluşturulur.
2. İmza Oluşturma (Signature)
Her API isteğinde, istek yolu API anahtarıyla HMAC SHA256 algoritması kullanılarak imzalanır.
function generateSignature($path, $apiKey) {
return hash_hmac('sha256', $path, $apiKey);
}
// Örnek kullanım:
$path = "/allgames/1/{timestamp}";
$signature = generateSignature($path, "JnaJWxTX7X9Cno9SqtYuo18KG");
Oluşturulan imza, API çağrısının URL'sine eklenir:
https://vkptrg.yjmelqyefm.net/api/allgames/1/{timestamp}/{signature}
3. API Çağrısı
Tüm oyunları çekmek için kullanılan fonksiyon:
function sendApiRequest($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
die("cURL Hatası: " . curl_error($ch));
}
curl_close($ch);
return json_decode($response, true);
}
4. Oyun URL'si Oluşturma
Mobil: Eğer game ve category parametreleri varsa, kullanıcı aşağıdaki şekilde yönlendirilir:
$gamePath = "/game/{category}/{game_name}/1/{login_user_name}/{timestamp}";
$gameSignature = generateSignature($gamePath, $apiKey);
$redirectUrl = $apiServerUrl . $gamePath . '/' . $gameSignature . "?currency=BGN";
header("Location: " . $redirectUrl);
exit;
Masaüstü: Oyun URL'si bir iframe içinde yüklenir:
$iframeGameUrl = $apiServerUrl . $gamePath . '/' . $gameSignature . "?currency=BGN";
5. Uygulama Akışı
- API üzerinden tüm oyunlar
/allgames/1/{timestamp} yoluyla çekilir.
- Belirli bir kategoriye göre oyunlar filtrelenir.
- Kullanıcının cihaz türüne göre (mobil veya masaüstü) oyun URL'si oluşturulur ve yönlendirme veya
iframe yüklemesi yapılır.
- Kullanıcı oturumu kontrol edilir; geçerli değilse giriş sayfasına yönlendirilir.
6. Kullanıcı Bilgileri Sorgulama (getuserdata)
// JSON içerik türünü ayarlayın
header("Content-Type: application/json");
require_once __DIR__ . '/../config.php';
try {
$db = new Db();
$connection = $db->connect();
if (!$connection) {
echo json_encode(["error" => "Veritabanı bağlantı hatası."]);
exit;
}
$username = isset($_GET['username']) ? trim($_GET['username']) : '';
if (empty($username)) {
echo json_encode(["error" => "Eksik parametreler!"]);
exit;
}
$stmt = $connection->prepare("SELECT score FROM users WHERE username = :username");
$stmt->execute(['username' => $username]);
if ($user = $stmt->fetch()) {
echo json_encode([
"Username" => $username,
"Balance" => number_format((float)$user['score'], 2, '.', '')
]);
} else {
echo json_encode(["error" => "Kullanıcı bulunamadı."]);
}
} catch (PDOException $e) {
echo json_encode(["error" => "Veritabanı hatası: " . $e->getMessage()]);
} catch (Exception $e) {
echo json_encode(["error" => "Hata: " . $e->getMessage()]);
}
7. Bakiye Güncelleme (update balance)
header("Content-Type: application/json");
require_once __DIR__ . '/../config.php';
$db = new Db();
$connection = $db->connect();
if (!$connection) {
echo json_encode(["error" => "Veritabanı bağlantı hatası."]);
exit;
}
$data = json_decode(file_get_contents('php://input'), true);
$username = $data['Username'] ?? '';
$changingBalance = isset($data['ChangingBalance']) ? (float)$data['ChangingBalance'] : 0.0;
$game = $data['Game'] ?? '';
$gameCategory = $data['GameCategory'] ?? '';
$transactionId = $data['TransactionId'] ?? '';
$signature = $data['Signature'] ?? '';
if (empty($username) || empty($game) || empty($gameCategory) || empty($transactionId)) {
echo json_encode(["error" => "Eksik veya hatalı parametreler!"]);
exit;
}
try {
$stmt = $connection->prepare("SELECT score FROM users WHERE username = :username");
$stmt->execute(['username' => $username]);
$user = $stmt->fetch();
if (!$user) {
echo json_encode(["error" => "Kullanıcı bulunamadı."]);
exit;
}
$newBalance = $user['score'] + $changingBalance;
$updateStmt = $connection->prepare("UPDATE users SET score = :score WHERE username = :username");
$updateStmt->execute(['score' => $newBalance, 'username' => $username]);
echo json_encode([
"Username" => $username,
"Balance" => number_format($newBalance, 2, '.', ''),
"Game" => $game,
"GameCategory" => $gameCategory,
"TransactionId" => $transactionId
]);
} catch (PDOException $e) {
echo json_encode(["error" => "Veritabanı hatası: " . $e->getMessage()]);
exit;
} catch (Exception $e) {
echo json_encode(["error" => "Bir hata oluştu: " . $e->getMessage()]);
exit;
}
8. Uygulama Akışı
- API üzerinden tüm oyunlar
/allgames/1/{timestamp} yoluyla çekilir.
- Oyunlar belirli kategorilere göre filtrelenir.
- Kullanıcının cihazına göre (mobil/masaüstü) ilgili oyun URL'si oluşturulur ve yönlendirme veya
iframe kullanılır.
- Kullanıcı oturumu kontrol edilir; geçerli değilse giriş sayfasına yönlendirilir.
- getuserdata: Belirtilen kullanıcı adı için bakiye sorgulaması yapılır.
- update balance: Gelen parametreler doğrultusunda kullanıcının bakiyesi güncellenir.
Bu yapı sayesinde slot oyunlarınızı sisteminize entegre edebilir, API entegrasyonu, kullanıcı bakiyesi sorgulama ve bakiye güncelleme işlemlerini sorunsuz şekilde gerçekleştirebilirsiniz.