GetVersionController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. $requestUrl = env('OURO_GAME_CDN','https://cdn.moeda777.com/glo/mexico/update/');
  56. $data=self::fetchDatas($GameNames,$requestUrl);
  57. if(!$inner){
  58. $ret = json_encode($data);
  59. Redis::set('getVersion', $ret);
  60. }
  61. }
  62. return $data;
  63. }
  64. private static function fetchDatas($GameNames,$requestUrl){
  65. $data = [];
  66. $http = new HttpCurl();
  67. foreach ($GameNames as $gameName) {
  68. if ($gameName == 'assets') {
  69. $url = $requestUrl . 'assets/version.manifest';
  70. } else {
  71. $url = $requestUrl . $gameName . "/" . $gameName . "_ver.manifest";
  72. }
  73. $res = $http->curl_get($url);
  74. try {
  75. $toArr = \GuzzleHttp\json_decode($res, true);
  76. }catch (\Exception $exception){
  77. $toArr['version'] =0;
  78. }
  79. $data[$gameName] = $toArr['version'] ?? 0;
  80. }
  81. return $data;
  82. }
  83. // 清空版本信息
  84. public function delVersion()
  85. {
  86. Redis::del('getVersion');
  87. Redis::del('getVersionRuby');
  88. // ClearCache::dispatch();
  89. return apiReturnSuc();
  90. }
  91. }