HacksawController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\Game\GameCard;
  4. use App\Game\GlobalUserInfo;
  5. use App\Game\LogGamecardClick;
  6. use App\Game\Services\OuroGameService;
  7. use App\Models\AccountsInfo;
  8. use App\Notification\TelegramBot;
  9. use App\Util;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Routing\Controller;
  12. use Illuminate\Support\Facades\Redis;
  13. class HacksawController extends Controller
  14. {
  15. /** gid => version(与 CDN 静态资源目录一致) */
  16. private static $gameVersions = [
  17. '1632' => '1.34.2', // Speed Crash
  18. '1624' => '1.43.2', // Limbo
  19. '1590' => '1.30.0', // Dice
  20. '1446' => '1.59.1', // Baccarat
  21. '1416' => '1.30.1', // Twenty-One
  22. '1386' => '1.36.2', // Colors
  23. '1380' => '1.34.1', // Blocks
  24. '1321' => '1.41.0', // Wheel
  25. '1334' => '1.41.1', // Lines
  26. '1148' => '1.27.3', // Coins
  27. '1294' => '1.88.1', // Plinko
  28. '1328' => '1.43.0', // Hi-Lo
  29. '1126' => '1.135.0', // Mines
  30. '1154' => '1.68.1', // Boxes
  31. ];
  32. /**
  33. * Hacksaw 子游戏载入入口
  34. * 请求: /game/hacksaw/lunch?gid=1632
  35. */
  36. public function gameLunch(Request $request)
  37. {
  38. $gid = (string) $request->input('gid');
  39. $user = $request->user();
  40. $userid = $user->UserID;
  41. $version = self::$gameVersions[$gid] ?? null;
  42. if ($version === null) {
  43. abort(404, 'Hacksaw game version not configured for gid: ' . $gid);
  44. }
  45. GameCard::$enableStateCheck = false;
  46. $gamecard = GameCard::where('gid', $gid)->where('brand', 'Hacksaw')->first();
  47. if (!$gamecard) {
  48. abort(404, 'Game not found');
  49. }
  50. $in_gameid = OuroGameService::getUserInGame($userid, $user->GlobalUID);
  51. if ($in_gameid != intval($gamecard->id)) {
  52. Util::WriteLog('24680game', compact('in_gameid', 'gamecard', 'user'));
  53. }
  54. $gamecard->increment('play_num', 1);
  55. LogGamecardClick::recordClick($gamecard->id, $userid);
  56. $lang = GlobalUserInfo::getLocale();
  57. $supportLang = ['en', 'da', 'de', 'es', 'fi', 'fr', 'id', 'it', 'ja', 'ko', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sv', 'th', 'tr', 'vi', 'zh', 'my'];
  58. if (!in_array($lang, $supportLang)) {
  59. $lang = 'en';
  60. }
  61. $configurls = json_decode(env('CONFIG_GAMES'), true);
  62. $configurl = $configurls['hacksaw'] ?? $configurls['hkg'] ?? null;
  63. if (!$configurl) {
  64. $staticHost = 'static.pgn-nmu2nd.com';
  65. $apiHost = 'api.pgn-nmu2nd.com';
  66. } else {
  67. $staticHost = $configurl['source'] ?? 'static.pgn-nmu2nd.com';
  68. $apiHost = $configurl['api'] ?? 'api.pgn-nmu2nd.com';
  69. }
  70. $cdnserver = 'https://' . $staticHost;
  71. $apiBase = 'https://' . $apiHost . '/api';
  72. $lobbyurl = $cdnserver;
  73. // $sign = GlobalUserInfo::genGuuidSign($user);
  74. $newToken = base64_encode(random_bytes(20));
  75. $Currency = env("CONFIG_24680_CURRENCY", "BRL");
  76. $CurrencySymbol = env("CONFIG_24680_DOLLAR", "R$");
  77. $data['currency'] = $Currency;
  78. $data['dollar'] = $CurrencySymbol;
  79. $data['limit_room']=0;
  80. $account = AccountsInfo::where('UserID', $userid)->first();
  81. if(!$account){
  82. TelegramBot::getDefault()->sendMsgWithEnv("hawksaw_ fail11111:" . json_encode([$request->all(),$data]) );
  83. abort(404, 'User not found');
  84. }else{
  85. $account=$account->toArray();
  86. }
  87. $data = array_merge($data, $account);
  88. Redis::setex($newToken, 7200, json_encode($data));
  89. $params = [
  90. 'language' => $lang,
  91. 'channel' => 'mobile',
  92. 'gameid' => $gid,
  93. 'mode' => 2,
  94. 'token' => $newToken,
  95. 'lobbyurl' => $lobbyurl,
  96. 'currency' => env('CONFIG_24680_CURRENCY', 'EUR'),
  97. 'partner' => 'demo',
  98. 'env' => $apiBase,
  99. 'realmoneyenv' => $apiBase,
  100. ];
  101. $url = $cdnserver . '/' . $gid . '/' . $version . '/index.html?' . http_build_query($params);
  102. return "<script>
  103. parent.postMessage({cmd:\"closeLoading\"},\"*\");
  104. location.href='$url';
  105. </script>";
  106. }
  107. }