2
0

AutoApkController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Facade\TableName;
  4. use App\Game\Services\RouteService;
  5. use App\Game\WebChannelConfig;
  6. use App\Http\Controllers\Controller;
  7. use App\IpLocation;
  8. use App\Models\AgentClickLog;
  9. use App\Models\WithdrawalChannelPositionConfig;
  10. use App\Util;
  11. use GuzzleHttp\Client;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Facades\DB;
  14. use Illuminate\Support\Facades\Redis;
  15. class AutoApkController extends Controller
  16. {
  17. protected $defaultChannel=100;
  18. public function index()
  19. {
  20. $this->defaultChannel=env('REGION_24680_DEFAULT_CHANNEL',100);
  21. }
  22. public function h5jump(Request $request){
  23. $url="https://cdn.24680.com/client/orgbr/index.html";
  24. Util::WriteLog("h5","");
  25. $redirect_url=$url.'?'.http_build_query($request->all());
  26. header("Location: $redirect_url", true, 302);
  27. exit();
  28. // return redirect($url.'?'.http_build_query($request->all()));
  29. }
  30. public function channelConfig(Request $request)
  31. {
  32. $config = WebChannelConfig::getByChannel($request->input('c','100'));
  33. return response()->json(['apkurl'=>$config->LightApk]);
  34. }
  35. public function jumpApkByConfig(Request $request)
  36. {
  37. $config = WebChannelConfig::getByChannel($request->input('c','100'));
  38. return redirect($config->LightApk);
  39. }
  40. public function health(Request $request){
  41. // 从Redis读取系统健康状态配置
  42. $healthConfig = Redis::get('system:health');
  43. if (!$healthConfig) {
  44. // 如果Redis中没有配置,则返回默认值
  45. return ['status' => 1, 'pay' => 1, 'cashout' => 1, 'notice' => '','other'=>json_decode($healthConfig, true)];
  46. }
  47. // 返回Redis中的配置
  48. return json_decode($healthConfig, true);
  49. }
  50. public function inside(Request $request){
  51. // 读取文件内容
  52. $file_path = public_path('inside.htm');
  53. $content = file_get_contents($file_path);
  54. // 替换 URL
  55. $old_url = 'https://saapi.24680.org';
  56. $new_url = env('APP_URL');
  57. $updated_content = str_replace($old_url, $new_url, $content);
  58. $updated_content = str_replace('BRL', env('CONFIG_24680_CURRENCY','BRL'), $updated_content);
  59. // 替换 URL
  60. $old_url = 'domain=brapi.24680.org';
  61. $new_url = 'domain='.$_SERVER['HTTP_HOST'];
  62. $updated_content = str_replace($old_url, $new_url, $updated_content);
  63. $old_url = 'domain=.24680.org';
  64. $new_url = 'domain='.$_SERVER['HTTP_HOST'];
  65. $updated_content = str_replace($old_url, $new_url, $updated_content);
  66. $UserID=$request->uid??0;
  67. if($UserID) {
  68. AgentClickController::checkClick($UserID);
  69. }
  70. return $updated_content; // 返回结果
  71. }
  72. public function findUrlSign(Request $request){
  73. $packageName = $request->input('packageName')??$request->input('PackageName');
  74. $packageConfig=DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('PackageName',$packageName)->first()->toArray();
  75. if(!$packageConfig){
  76. return apiReturnFail();
  77. }
  78. return apiReturnSuc($packageConfig);
  79. }
  80. /////模板包资源 //包体 pack/input/apks //签名 pack/input/keystore //替换目录 pack/input/res/ //输出目录 临时制作目录 pack/output //工具 解包 签名 pack/tools
  81. //
  82. ////最终包输出目录 app/public/apks/
  83. //
  84. //接口 get post api/getApk //包名 packageName //app名字 appName //icon url 名字随意 iconUrl //圆icon url 名字随意 iconRoundUrl //指定制作配置 默认ouro777 不更改可不传 pkey
  85. //
  86. public function createApk(Request $request)
  87. {
  88. $packageName = $request->input('packageName');
  89. //投放标识
  90. $channelName = $request->input('channelName');
  91. $appName = $request->input('appName');
  92. $iconUrl = $request->input('iconUrl');
  93. $iconRoundUrl = $request->input('iconRoundUrl');
  94. $adminSign=$request->input('adminSign',"dk");
  95. $pkey=env('DEFAULT_APK_PKEY','ouro777');
  96. $configToPkey=['bxorg'=>'ouro777','mxorg'=>'ouro777_mx','bx_skin2_nftd'=>'BR_SKIN1_NewFirstPay','bx_org_nftd'=>'BR_ORG_NewFirstPay','colperu_org'=>'oro777_sa','bx24680'=>'red24680','pakistan_org'=>'pakistan'];
  97. if($request->has('config')){
  98. $config = preg_replace('/[^a-zA-Z_]+$/', '', trim($request->input('config')));
  99. $pkey=$configToPkey[$config]??$pkey;
  100. }
  101. $params=compact('packageName','appName','iconUrl','iconRoundUrl','pkey');
  102. $api='getApk';
  103. if($request->input('rebuild',0)==1){
  104. $api='rebuildApk';
  105. }
  106. // dd('http://15.228.201.93/api/'.$api.'?' . http_build_query($params));
  107. try {
  108. $url='http://15.228.201.93/api/'.$api.'?' . http_build_query($params);
  109. $client = new Client(['timeout'=>60]);
  110. $response = $client->get($url, [
  111. 'timeout' => 60
  112. ]);
  113. $result = $response->getBody();
  114. }catch (\Exception $e){
  115. Util::WriteLog('autoapk',$e->getMessage().$e->getTraceAsString());
  116. return apiReturnFail(__('messages.api.auto_apk.please_wait'));
  117. }
  118. $result=json_decode($result,true);
  119. if($result['code']!=200){
  120. $result['makeurl']='http://15.228.201.93/api/'.$api.'?' . http_build_query($params);
  121. return $result;
  122. }
  123. Util::WriteLog('autoapk',$result);
  124. //制作成功,建立数据
  125. $packageUrl=$result['data']['packageUrl'];
  126. $packageUrl=str_replace('http://18.228.154.186/','https://d388b4gb9i0dwg.cloudfront.net/',$packageUrl);
  127. $packageConfig=$this->autoCreateChannel($packageName,$channelName,$adminSign);
  128. $signConfigs=[
  129. 'xidu'=>['david_view','david','xidu','liang','newapk','desheng','William'],
  130. ];
  131. //修改后台权限
  132. $Channel=$packageConfig['Channel'];
  133. DB::connection('mysql')->table('dcat-admin.admin_users')->whereIn('username',$signConfigs[$adminSign])->orderBy('username')->each(function($item) use ($Channel) {
  134. $item=(array)$item;
  135. $channels=json_decode($item['channel'],true);
  136. if(!in_array($Channel,$channels))$channels[]=$Channel;
  137. DB::connection('mysql')->table('dcat-admin.admin_users')->where('username',$item['username'])->update(['channel'=>json_encode($channels)]);
  138. });
  139. $urlSign=$packageConfig['AppKey'];
  140. $data=['packageUrl'=>$packageUrl,'packageName'=>$packageName,'channel'=>$packageConfig['Channel'],'urlSign'=>$urlSign];
  141. return apiReturnSuc($data);
  142. }
  143. public function modifyRights($packageConfig,$adminSign='dk')
  144. {
  145. $xidu=['xidu','kele','liang','laoma888','William'];
  146. $signConfigs=[
  147. 'dk'=>array_merge(['david_view','david'],$xidu),
  148. 'xidu'=>$xidu,
  149. 'aresbigs'=>array_merge(['aresbigs'],$xidu),
  150. // 'xidu'=>['xidu','kele','liang','newapk_ours','desheng'],
  151. ];
  152. //修改后台权限
  153. $Channel=$packageConfig['Channel'];
  154. DB::connection('mysql')->table('dcat-admin.admin_users')->whereIn('username',$signConfigs[$adminSign])->orderBy('username')->each(function($item) use ($Channel) {
  155. $item=(array)$item;
  156. $channels=json_decode($item['channel'],true);
  157. if(!in_array($Channel,$channels))$channels[]=$Channel;
  158. DB::connection('mysql')->table('dcat-admin.admin_users')->where('username',$item['username'])->update(['channel'=>json_encode($channels)]);
  159. });
  160. }
  161. public function autoCreateChannel($packageName, $channelName,$adminSign='dk')
  162. {
  163. $packageConfig=DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('PackageName',$packageName)->first();
  164. $UnionSign=0;
  165. if($adminSign=='dk'){
  166. //联运通道
  167. $UnionSign=1;
  168. $channelName='USA_'.$channelName;
  169. }else{
  170. $channelName='NEW_'.$channelName;
  171. }
  172. if(!$packageConfig){
  173. $sample=DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel',$this->defaultChannel)->orderBy('ID')->first();
  174. $post=(array)$sample;
  175. unset($post['ID']);
  176. $post['Remarks'] = $post['AliasName']=$channelName;
  177. $post['UnionSign']=$UnionSign;
  178. $post['PackageName'] = $packageName;
  179. $post['AppKey']= Util::generateRandomString();
  180. $post['Sort'] = $this->defaultChannel;
  181. while(DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')->where('AppKey', $post['AppKey'])->exists()) {
  182. $post['AppKey'] = Util::generateRandomString();
  183. }
  184. $maxChannel=DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')->max('Channel');
  185. $post['Channel']=$Channel = $maxChannel+1;
  186. DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  187. ->insert($post);
  188. if($Channel){
  189. $createConfig = function () use($Channel) {
  190. $config = new WithdrawalChannelPositionConfig();
  191. $config->channel = $Channel;
  192. return $config;
  193. };
  194. $config = WithdrawalChannelPositionConfig::query()->where('channel', $Channel)->first() ?: $createConfig();
  195. $config->save();
  196. }
  197. }else{
  198. $packageConfig=(array)$packageConfig;
  199. if($packageConfig['Remarks']!=$channelName||$packageConfig['AliasName']!=$channelName){
  200. DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('PackageName',$packageName)->update(['Remarks'=>$channelName,'AliasName'=>$channelName]);
  201. WebChannelConfig::where('Channel', $packageConfig['Channel'])->update(['Remarks' => $channelName,'PackageName'=>$packageName]);
  202. }
  203. $Channel=$packageConfig['Channel'];
  204. $post=$packageConfig;
  205. }
  206. if(WebChannelConfig::where('Channel', $Channel)->exists()) {
  207. WebChannelConfig::where('Channel', $Channel)->update(['Remarks' => $channelName,'PackageName'=>$packageName]);
  208. }else {
  209. $templateConfig = WebChannelConfig::getByChannel($this->defaultChannel);
  210. if($templateConfig) {
  211. $config = $templateConfig->toArray();
  212. $config['Remarks'] = $channelName;
  213. $config['Channel'] = $Channel;
  214. $config['PackageName'] = $packageName;
  215. unset($config['ID']);
  216. WebChannelConfig::insert($config);
  217. }
  218. }
  219. $dcatChannel=DB::connection('mysql')->table('dcat-admin.channel')->where('channel',$Channel);
  220. if($dcatChannel->exists()){
  221. $dcatChannel->update(['channel_name'=>$channelName]);
  222. }else{
  223. DB::connection('mysql')->table('dcat-admin.channel')->insert(['channel'=>$Channel,'channel_name'=>$channelName,'package_name'=>'','remark'=>'']);
  224. }
  225. $dcatChannel=DB::connection('mysql')->table('dcat-admin.channel_ownership')->where('channel',$Channel);
  226. if($dcatChannel->exists()){
  227. $dcatChannel->update(['name'=>$channelName]);
  228. }else{
  229. DB::connection('mysql')->table('dcat-admin.channel_ownership')->insert(['channel'=>$Channel,'name'=>$channelName]);
  230. }
  231. return $post;
  232. }
  233. }