fork download
  1. <?php
  2.  
  3. function fetchAffiliateStats($apiUrl, $token, $userId, $startDate = null, $endDate = null, $gameIdentifiers = null, $categories = null, $providers = null)
  4. {
  5. $url = $apiUrl . "/affiliate/v2/stats";
  6. $headers = [
  7. "Authorization: Bearer $token",
  8. "Content-Type: application/json",
  9. ];
  10.  
  11. $params = [
  12. "userId" => $userId,
  13. "startDate" => $startDate,
  14. "endDate" => $endDate,
  15. "gameIdentifiers" => $gameIdentifiers,
  16. "categories" => $categories,
  17. "providers" => $providers,
  18. ];
  19.  
  20. // Remove null values
  21. $params = array_filter($params, function ($value) {
  22. return $value !== null;
  23. });
  24.  
  25. $queryString = http_build_query($params);
  26. $url = $url . "?" . $queryString;
  27.  
  28. $ch = curl_init();
  29. curl_setopt($ch, CURLOPT_URL, $url);
  30. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  31. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  32.  
  33. $response = curl_exec($ch);
  34. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  35.  
  36. curl_close($ch);
  37.  
  38. if ($httpCode === 200) {
  39. return json_decode($response, true);
  40. } else {
  41. throw new Exception("Failed to fetch data: $httpCode $response");
  42. }
  43. }
  44.  
  45. function maskUsername($username)
  46. {
  47. if (strlen($username) <= 4) {
  48. return "***" . substr($username, -1);
  49. }
  50. return substr($username, 0, 2) . "***" . substr($username, -1);
  51. }
  52.  
  53. function assignPrizes($leaderboard)
  54. {
  55. $prizeStructure = [1000, 700, 600, 500, 400, 350, 300, 250, 250, 200, 200, 150, 150, 100, 100];
  56.  
  57. foreach ($leaderboard as $index => &$user) {
  58. $user["prize"] = $prizeStructure[$index] ?? 0;
  59. }
  60.  
  61. return $leaderboard;
  62. }
  63.  
  64. function getLeaderboard($data)
  65. {
  66. usort($data, function ($a, $b) {
  67. return $b["wagered"] <=> $a["wagered"];
  68. });
  69.  
  70. foreach ($data as &$user) {
  71. $user["username"] = maskUsername($user["username"]);
  72. }
  73.  
  74. return assignPrizes($data);
  75. }
  76.  
  77. // Main script
  78. try {
  79. $API_URL = "https://r...content-available-to-author-only...t.com";
  80. $TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjM1ZGIwNDMyLWI1ZWMtNDZlMy1hMTVkLWVhOTgzOWRlOWYzNCIsIm5vbmNlIjoiNWFkMjc3MDAtZjY0Ni00YTljLTg1ZTItNWVkODM5YjU0ZTQ3Iiwic2VydmljZSI6ImFmZmlsaWF0ZVN0YXRzIiwiaWF0IjoxNzI2OTAzMDg4fQ.zwCClkUh9b1QWFLCjrY1AwFiWOM2ohbdA5UNjuSNgk8";
  81. $USER_ID = "35db0432-b5ec-46e3-a15d-ea9839de9f34";
  82.  
  83. $START_DATE = (new DateTime("2024-11-01"))->format(DateTime::ISO8601);
  84. $END_DATE = (new DateTime("2025-01-15"))->format(DateTime::ISO8601);
  85. $GAME_IDENTIFIERS = "-housegames:dice";
  86. $CATEGORIES = "slots,provably fair";
  87. $PROVIDERS = "";
  88.  
  89. $stats = fetchAffiliateStats($API_URL, $TOKEN, $USER_ID, $START_DATE, $END_DATE, $GAME_IDENTIFIERS, $CATEGORIES, $PROVIDERS);
  90.  
  91. $leaderboard = getLeaderboard($stats);
  92.  
  93. echo str_pad("Rank", 5) . str_pad("Username", 15) . str_pad("Wagered (€)", 15) . str_pad("Prize (€)", 10) . PHP_EOL;
  94. echo str_repeat("=", 45) . PHP_EOL;
  95.  
  96. foreach (array_slice($leaderboard, 0, 25) as $index => $user) {
  97. echo str_pad($index + 1, 5) .
  98. str_pad($user["username"], 15) .
  99. str_pad(number_format($user["wagered"], 2), 15) .
  100. str_pad($user["prize"], 10) . PHP_EOL;
  101. }
  102. } catch (Exception $e) {
  103. echo "Error: " . $e->getMessage() . PHP_EOL;
  104. }
  105.  
Success #stdin #stdout 0.05s 26104KB
stdin
Standard input is empty
stdout
Error: Failed to fetch data: 0