HacksawController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. '1042' => '1.47.0',
  32. '1043' => '1.44.16',
  33. '1048' => '1.58.1',
  34. '1049' => '1.50.4',
  35. '1055' => '1.60.1',
  36. '1058' => '1.42.2',
  37. '1059' => '1.66.3',
  38. '1066' => '1.43.0',
  39. '1067' => '1.70.2',
  40. '1069' => '1.56.3',
  41. '1070' => '1.32.0',
  42. '1071' => '1.50.1',
  43. '1081' => '1.32.0',
  44. '1083' => '1.52.2',
  45. '1084' => '1.64.0',
  46. '1087' => '1.44.3',
  47. '1091' => '1.36.3',
  48. '1093' => '1.41.5',
  49. '1096' => '1.16.1',
  50. '1099' => '1.23.1',
  51. '1102' => '1.35.2',
  52. '1117' => '1.29.0',
  53. '1127' => '1.33.5',
  54. '1131' => '1.34.2',
  55. '1135' => '1.45.2',
  56. '1140' => '1.28.2',
  57. '1144' => '1.46.2',
  58. '1160' => '1.48.0',
  59. '1164' => '1.75.1',
  60. '1168' => '1.43.0',
  61. '1172' => '1.48.1',
  62. '1176' => '1.39.1',
  63. '1181' => '1.74.1',
  64. '1185' => '1.11.2',
  65. '1189' => '1.14.3',
  66. '1193' => '1.50.5',
  67. '1197' => '1.31.2',
  68. '1201' => '1.40.3',
  69. '1205' => '1.21.2',
  70. '1209' => '1.29.0',
  71. '1213' => '1.39.1',
  72. '1217' => '1.35.3',
  73. '1221' => '1.21.1',
  74. '1225' => '1.46.2',
  75. '1229' => '1.25.1',
  76. '1233' => '1.33.2',
  77. '1237' => '1.20.2',
  78. '1243' => '1.29.1',
  79. '1247' => '1.47.1',
  80. '1251' => '1.21.0',
  81. '1259' => '1.21.4',
  82. '1263' => '1.15.2',
  83. '1267' => '1.10.3',
  84. '1271' => '1.14.0',
  85. '1275' => '1.21.3',
  86. '1279' => '1.22.7',
  87. '1305' => '1.22.4',
  88. '1309' => '1.22.0',
  89. '1314' => '1.19.1',
  90. '1340' => '1.14.2',
  91. '1344' => '1.16.6',
  92. '1348' => '1.25.0',
  93. '1352' => '1.23.1',
  94. '1356' => '1.26.0',
  95. '1360' => '1.18.0',
  96. '1364' => '1.16.1',
  97. '1372' => '1.17.4',
  98. '1392' => '1.29.2',
  99. '1396' => '1.19.0',
  100. '1400' => '1.33.0',
  101. '1404' => '1.18.6',
  102. '1408' => '1.58.1',
  103. '1422' => '1.47.3',
  104. '1426' => '1.37.0',
  105. '1430' => '1.10.3',
  106. '1434' => '1.28.5',
  107. '1438' => '1.31.0',
  108. '1442' => '1.26.1',
  109. '1452' => '1.63.2',
  110. '1456' => '1.30.0',
  111. '1460' => '1.17.0',
  112. '1474' => '1.15.0',
  113. '1478' => '1.23.5',
  114. '1482' => '1.43.2',
  115. '1490' => '1.24.3',
  116. '1494' => '1.19.1',
  117. '1508' => '1.31.0',
  118. '1514' => '1.16.3',
  119. '1530' => '1.35.5',
  120. '1534' => '1.37.1',
  121. '1554' => '1.10.5',
  122. '1558' => '1.28.1',
  123. '1562' => '1.46.0',
  124. '1570' => '1.17.1',
  125. '1580' => '1.32.2',
  126. '1584' => '1.28.7',
  127. '1602' => '1.45.0',
  128. '1608' => '1.39.1',
  129. '1612' => '1.24.5',
  130. '1616' => '1.27.7',
  131. '1620' => '1.37.0',
  132. '1689' => '1.31.0',
  133. ];
  134. /**
  135. * Hacksaw 子游戏载入入口
  136. * 请求: /game/hacksaw/lunch?gid=1632
  137. */
  138. public function gameLunch(Request $request)
  139. {
  140. $gid = (string) $request->input('gid');
  141. $user = $request->user();
  142. $userid = $user->UserID;
  143. $version = self::$gameVersions[$gid] ?? null;
  144. if ($version === null) {
  145. abort(404, 'Hacksaw game version not configured for gid: ' . $gid);
  146. }
  147. GameCard::$enableStateCheck = false;
  148. $gamecard = GameCard::where('gid', $gid)->where('brand', 'Hacksaw')->first();
  149. if (!$gamecard) {
  150. abort(404, 'Game not found');
  151. }
  152. $in_gameid = OuroGameService::getUserInGame($userid, $user->GlobalUID);
  153. if ($in_gameid != intval($gamecard->id)) {
  154. Util::WriteLog('24680game', compact('in_gameid', 'gamecard', 'user'));
  155. }
  156. $gamecard->increment('play_num', 1);
  157. LogGamecardClick::recordClick($gamecard->id, $userid);
  158. $lang = GlobalUserInfo::getLocale();
  159. $supportLang = ['en', 'da', 'de', 'es', 'fi', 'fr', 'id', 'it', 'ja', 'ko', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sv', 'th', 'tr', 'vi', 'zh', 'my'];
  160. if (!in_array($lang, $supportLang)) {
  161. $lang = 'en';
  162. }
  163. $configurls = json_decode(env('CONFIG_GAMES'), true);
  164. $configurl = $configurls['hacksaw'] ?? $configurls['hkg'] ?? null;
  165. if (!$configurl) {
  166. $staticHost = 'static.pgn-nmu2nd.com';
  167. $apiHost = 'api.pgn-nmu2nd.com';
  168. } else {
  169. $staticHost = $configurl['source'] ?? 'static.pgn-nmu2nd.com';
  170. $apiHost = $configurl['api'] ?? 'api.pgn-nmu2nd.com';
  171. }
  172. $cdnserver = 'https://' . $staticHost;
  173. $apiBase = 'https://' . $apiHost . '/api';
  174. $lobbyurl = $cdnserver;
  175. // $sign = GlobalUserInfo::genGuuidSign($user);
  176. $newToken = base64_encode(random_bytes(20));
  177. $Currency = env("CONFIG_24680_CURRENCY", "BRL");
  178. $CurrencySymbol = env("CONFIG_24680_DOLLAR", "R$");
  179. $data['currency'] = $Currency;
  180. $data['dollar'] = $CurrencySymbol;
  181. $data['limit_room']=0;
  182. $account = AccountsInfo::where('UserID', $userid)->first();
  183. if(!$account){
  184. TelegramBot::getDefault()->sendMsgWithEnv("hawksaw_ fail11111:" . json_encode([$request->all(),$data]) );
  185. abort(404, 'User not found');
  186. }else{
  187. $account=$account->toArray();
  188. }
  189. $data = array_merge($data, $account);
  190. Redis::setex($newToken, 7200, json_encode($data));
  191. $params = [
  192. 'language' => $lang,
  193. 'channel' => 'mobile',
  194. 'gameid' => $gid,
  195. 'mode' => 2,
  196. 'token' => $newToken,
  197. 'lobbyurl' => $lobbyurl,
  198. 'currency' => env('CONFIG_24680_CURRENCY', 'EUR'),
  199. 'partner' => 'demo',
  200. 'env' => $apiBase,
  201. 'realmoneyenv' => $apiBase,
  202. ];
  203. $url = $cdnserver . '/' . $gid . '/' . $version . '/index.html?' . http_build_query($params);
  204. return "<script>
  205. parent.postMessage({cmd:\"closeLoading\"},\"*\");
  206. location.href='$url';
  207. </script>";
  208. }
  209. }