<?php
function fetchAffiliateStats($apiUrl, $token, $userId, $startDate = null, $endDate = null, $gameIdentifiers = null, $categories = null, $providers = null)
{
$url = $apiUrl . "/affiliate/v2/stats";
$headers = [
"Authorization: Bearer $token",
"Content-Type: application/json",
];
$params = [
"userId" => $userId,
"startDate" => $startDate,
"endDate" => $endDate,
"gameIdentifiers" => $gameIdentifiers,
"categories" => $categories,
"providers" => $providers,
];
// Remove null values
return $value !== null;
});
$url = $url . "?" . $queryString;
if ($httpCode === 200) {
} else {
throw new Exception("Failed to fetch data: $httpCode $response");
}
}
function maskUsername($username)
{
return "***" . substr($username, -1); }
return substr($username, 0, 2) . "***" . substr($username, -1); }
function assignPrizes($leaderboard)
{
$prizeStructure = [1000, 700, 600, 500, 400, 350, 300, 250, 250, 200, 200, 150, 150, 100, 100];
foreach ($leaderboard as $index => &$user) {
$user["prize"] = $prizeStructure[$index] ?? 0;
}
return $leaderboard;
}
function getLeaderboard($data)
{
usort($data, function ($a, $b) { return $b["wagered"] <=> $a["wagered"];
});
foreach ($data as &$user) {
$user["username"] = maskUsername($user["username"]);
}
return assignPrizes($data);
}
// Main script
try {
$API_URL = "https://r...content-available-to-author-only...t.com";
$TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjM1ZGIwNDMyLWI1ZWMtNDZlMy1hMTVkLWVhOTgzOWRlOWYzNCIsIm5vbmNlIjoiNWFkMjc3MDAtZjY0Ni00YTljLTg1ZTItNWVkODM5YjU0ZTQ3Iiwic2VydmljZSI6ImFmZmlsaWF0ZVN0YXRzIiwiaWF0IjoxNzI2OTAzMDg4fQ.zwCClkUh9b1QWFLCjrY1AwFiWOM2ohbdA5UNjuSNgk8";
$USER_ID = "35db0432-b5ec-46e3-a15d-ea9839de9f34";
$START_DATE = (new DateTime("2024-11-01"))->format(DateTime::ISO8601);
$END_DATE = (new DateTime("2025-01-15"))->format(DateTime::ISO8601);
$GAME_IDENTIFIERS = "-housegames:dice";
$CATEGORIES = "slots,provably fair";
$PROVIDERS = "";
$stats = fetchAffiliateStats($API_URL, $TOKEN, $USER_ID, $START_DATE, $END_DATE, $GAME_IDENTIFIERS, $CATEGORIES, $PROVIDERS);
$leaderboard = getLeaderboard($stats);
foreach (array_slice($leaderboard, 0, 25) as $index => $user) { str_pad($user["prize"], 10) . PHP_EOL
; }
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . PHP_EOL;
}
PD9waHAKCmZ1bmN0aW9uIGZldGNoQWZmaWxpYXRlU3RhdHMoJGFwaVVybCwgJHRva2VuLCAkdXNlcklkLCAkc3RhcnREYXRlID0gbnVsbCwgJGVuZERhdGUgPSBudWxsLCAkZ2FtZUlkZW50aWZpZXJzID0gbnVsbCwgJGNhdGVnb3JpZXMgPSBudWxsLCAkcHJvdmlkZXJzID0gbnVsbCkKewogICAgJHVybCA9ICRhcGlVcmwgLiAiL2FmZmlsaWF0ZS92Mi9zdGF0cyI7CiAgICAkaGVhZGVycyA9IFsKICAgICAgICAiQXV0aG9yaXphdGlvbjogQmVhcmVyICR0b2tlbiIsCiAgICAgICAgIkNvbnRlbnQtVHlwZTogYXBwbGljYXRpb24vanNvbiIsCiAgICBdOwoKICAgICRwYXJhbXMgPSBbCiAgICAgICAgInVzZXJJZCIgPT4gJHVzZXJJZCwKICAgICAgICAic3RhcnREYXRlIiA9PiAkc3RhcnREYXRlLAogICAgICAgICJlbmREYXRlIiA9PiAkZW5kRGF0ZSwKICAgICAgICAiZ2FtZUlkZW50aWZpZXJzIiA9PiAkZ2FtZUlkZW50aWZpZXJzLAogICAgICAgICJjYXRlZ29yaWVzIiA9PiAkY2F0ZWdvcmllcywKICAgICAgICAicHJvdmlkZXJzIiA9PiAkcHJvdmlkZXJzLAogICAgXTsKCiAgICAvLyBSZW1vdmUgbnVsbCB2YWx1ZXMKICAgICRwYXJhbXMgPSBhcnJheV9maWx0ZXIoJHBhcmFtcywgZnVuY3Rpb24gKCR2YWx1ZSkgewogICAgICAgIHJldHVybiAkdmFs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