GetVersionController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\helper\HttpCurl;
  4. use App\Jobs\ClearCache;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Redis;
  7. class GetVersionController
  8. {
  9. public function index(Request $request)
  10. {
  11. $login_ip = $request->ip();
  12. $inIp = config('inIp');
  13. $inner = 0;
  14. if(in_array($login_ip,$inIp)){
  15. $inner = 1;
  16. }
  17. $data=self::getVersion($inner);
  18. $result = apiReturnSuc($data);
  19. return $result;
  20. }
  21. public function indexRuby(Request $request)
  22. {
  23. $login_ip = $request->ip();
  24. $inIp = config('inIp');
  25. $inner = 0;
  26. if(in_array($login_ip,$inIp)){
  27. $inner = 1;
  28. }
  29. $data=self::getVersionRuby($inner);
  30. $result = apiReturnSuc($data);
  31. return $result;
  32. }
  33. public static function getVersionRuby($inner=false){
  34. $key="getVersionRuby";
  35. if (Redis::exists($key) ) {
  36. $data = json_decode(Redis::get($key));
  37. }else{
  38. $GameNames = [
  39. 'RsROMAN', 'RsDZPK', 'RsCACHETA','RsTRUCO','RsFRUIT9X','RsFOOTBALL', 'RsOLYMPUS','RsTREASURE','RsRAIO','RsHALLOWEEN',"RsCRASH","RsMINES","RsBCBM","RsSGYYL","RsJOKER","RsHIVE","RsATENA","RsGOLDTIGER","RsOX","RsBIGBASS"
  40. ];
  41. $requestUrl = 'http://static.ruby777.gold/br/update/';
  42. $data=self::fetchDatas($GameNames,$requestUrl);
  43. $ret = json_encode($data);
  44. Redis::set($key, $ret);
  45. }
  46. return $data;
  47. }
  48. public static function getVersion($inner=false){
  49. if (Redis::exists('getVersion') && !$inner) {
  50. $data = json_decode(Redis::get('getVersion'));
  51. } else {
  52. $GameNames = [
  53. 'AVIATOR2','AVIATOR','ROMAN', 'DZPK', 'CACHETA','TRUCO','FRUIT9X','FOOTBALL','NEWOLYMPUS','AZTEC', 'OLYMPUS','TREASURE','RAIO','HALLOWEEN',"CRASH","MINES","BCBM","SGYYL","JOKER5x1","HIVE","ATENA","GOLDTIGER","OX","BIGBASS","LHD"
  54. ];
  55. // 测试
  56. // $requestUrl = 'https://update.zzl78.cn/UpdateFiles/BrazilNewTest/';
  57. // 正式
  58. // if (!env('IS_TEST', 0)) {
  59. // $requestUrl = 'https://cdn.moeda777.com/hot/ouro777/';
  60. // } else {
  61. //// $requestUrl = 'https://spain-new.oss-cn-hangzhou.aliyuncs.com/HotUpdateAddr/TTUpdate/';
  62. // $requestUrl = 'https://cdn.moeda777.com/hot/ouro777/';
  63. // }
  64. $requestUrl = env('OURO_GAME_CDN','https://cdn.moeda777.com/glo/mexico/update/');
  65. $data=self::fetchDatas($GameNames,$requestUrl);
  66. if(!$inner){
  67. $ret = json_encode($data);
  68. Redis::set('getVersion', $ret);
  69. }
  70. }
  71. return $data;
  72. }
  73. private static function fetchDatas($GameNames,$requestUrl){
  74. $data = [];
  75. $http = new HttpCurl();
  76. foreach ($GameNames as $gameName) {
  77. if ($gameName == 'assets') {
  78. $url = $requestUrl . 'assets/version.manifest';
  79. } else {
  80. $url = $requestUrl . $gameName . "/" . $gameName . "_ver.manifest";
  81. }
  82. $res = $http->curl_get($url);
  83. try {
  84. $toArr = \GuzzleHttp\json_decode($res, true);
  85. }catch (\Exception $exception){
  86. $toArr['version'] =0;
  87. }
  88. $data[$gameName] = $toArr['version'] ?? 0;
  89. }
  90. return $data;
  91. }
  92. // 清空版本信息
  93. public function delVersion()
  94. {
  95. Redis::del('getVersion');
  96. Redis::del('getVersionRuby');
  97. // ClearCache::dispatch();
  98. return apiReturnSuc();
  99. }
  100. }