ServerService.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace App\Game\Services;
  3. use App\Util;
  4. use GuzzleHttp\Client;
  5. use GuzzleHttp\Exception\RequestException;
  6. class ServerService
  7. {
  8. static $example=[
  9. 'Bangladesh'=>'',
  10. 'Pakistan'=>'',
  11. 'Latin'=>'',
  12. 'OrgBrazil'=>'',
  13. 'Brazil'=>'',
  14. 'Europe'=>'',
  15. 'Russia'=>'',
  16. 'Mexico'=>'',
  17. 'Singapore'=>''
  18. ];
  19. static $codeToServer = [
  20. '6f83' => [
  21. 'Subsite' => 'Bangladesh',
  22. 'Country' => 'Bangladesh',
  23. 'Currency' => 'BDT',
  24. 'Lang' => 'bn',
  25. 'ServerRegion' => 'ap-south-bd',
  26. 'Api' => 'http://bdapi.24680.org'
  27. ],
  28. 'b1ec' => [
  29. 'Subsite' => 'Pakistan',
  30. 'Country' => 'Pakistan',
  31. 'Currency' => 'PKR',
  32. 'Lang' => 'en',
  33. 'ServerRegion' => 'me-east',
  34. 'Api' => 'http://pkapi.24680.org'
  35. ],
  36. '9bf6' => [
  37. 'Subsite' => 'OrgBrazil',
  38. 'Country' => 'Brazil',
  39. 'Currency' => 'BRL',
  40. 'Lang' => 'pt',
  41. 'ServerRegion' => 'sa-east-org',
  42. 'Api' => 'http://api.ouro777.com'
  43. ],
  44. '3ef5' => [
  45. 'Subsite' => 'Latin',
  46. 'Country' => 'Peru_Colombia',
  47. 'Currency' => 'USD',
  48. 'Lang' => 'pt',
  49. 'ServerRegion' => 'sa-west',
  50. 'Api' => 'http://saapi.24680.org'
  51. ],
  52. 'eb1a' => [
  53. 'Subsite' => 'Brazil',
  54. 'Country' => 'Brazil',
  55. 'Currency' => 'BRL',
  56. 'Lang' => 'pt',
  57. 'ServerRegion' => 'sa-east',
  58. 'Api' => 'http://brapi.24680.org'
  59. ],
  60. '90dd' => [
  61. 'Subsite' => 'Europe',
  62. 'Country' => 'German',
  63. 'Currency' => 'EUR',
  64. 'Lang' => 'en',
  65. 'ServerRegion' => 'eu-central',
  66. 'Api' => 'http://euapi.24680.org'
  67. ],
  68. '720d' => [
  69. 'Subsite' => 'Russia',
  70. 'Country' => 'Russia',
  71. 'Currency' => 'RUB',
  72. 'Lang' => 'ru',
  73. 'ServerRegion' => 'eu-russian',
  74. 'Api' => 'http://ruapi.24680.org'
  75. ],
  76. '2b80' => [
  77. 'Subsite' => 'Mexico',
  78. 'Country' => 'Mexico',
  79. 'Currency' => 'MXN',
  80. 'Lang' => 'es',
  81. 'ServerRegion' => 'na-mexico',
  82. 'Api' => 'http://mxapi.24680.org'
  83. ],
  84. ];
  85. public static function GetGlobalServerInfoByCode($code)
  86. {
  87. return self::$codeToServer[$code] ?? self::$codeToServer['90dd'];
  88. }
  89. public static function GetGlobalServerInfoBySubsite($subsite)
  90. {
  91. foreach (self::$codeToServer as $code => $server) {
  92. if ($server['Subsite'] == $subsite) {
  93. return $server;
  94. }
  95. }
  96. return self::$codeToServer['90dd'];
  97. }
  98. public static function IsLocalUser($GlobalUID)
  99. {
  100. return self::GetGlobalServerInfoByGUID($GlobalUID)['ServerRegion'] == env('REGION_24680', 'sa-east');
  101. }
  102. /**
  103. * @param $GlobalUID
  104. * @return string[]
  105. */
  106. public static function GetGlobalServerInfoByGUID($GlobalUID)
  107. {
  108. ////"917c74999c-b53b-eb1a-0004478930"
  109. $codes = explode("-", $GlobalUID);
  110. $config = @self::$codeToServer[$codes[2]];
  111. if(!$config)return self::$codeToServer['eb1a'];
  112. return $config;
  113. }
  114. public static function GetApiByGUID($GlobalUID)
  115. {
  116. return self::GetGlobalServerInfoByGUID($GlobalUID)['Api'];
  117. }
  118. public static function GlobalToUserID($GlobalUID)
  119. {
  120. return intval(explode('-', $GlobalUID)[3]);
  121. }
  122. public static function GetLocalSign()
  123. {
  124. return substr(md5(env('REGION_24680', 'sa-east')),0,4);
  125. }
  126. public static function RedirectToSub($GlobalUID)
  127. {
  128. $apiurl = self::GetApiByGUID($GlobalUID);
  129. // 获取当前请求的 GET 和 POST 数据
  130. // $getData = $request->query(); // 获取 GET 数据
  131. $postData = $_POST; // 获取 POST 数据
  132. $client = new Client();
  133. $response = $client->post($apiurl . $_SERVER['REQUEST_URI'], [
  134. 'verify'=>false,
  135. 'form_params' => $postData, // 传递 POST 数据// 'query' => $getData, // 传递 GET 数据
  136. ]);
  137. $res = json_decode($response->getBody(), true);
  138. // Util::WriteLog('subserver',$res);
  139. return $res;
  140. }
  141. }