ApiController.php 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Facade\TableName;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\helper\HttpCurl;
  6. use App\Http\helper\NumConfig;
  7. use App\IpLocation;
  8. use App\Jobs\Order;
  9. use App\Models\AccountsInfo;
  10. use App\Models\Cpf;
  11. use App\Models\PrivateMail;
  12. use App\Models\RecordScoreInfo;
  13. use App\Models\SystemStatusInfo;
  14. use App\Notification\TelegramBot;
  15. use App\Services\Custom;
  16. use App\Services\Goopago;
  17. use App\Services\IpCheck;
  18. use App\Services\OrderServices;
  19. use App\Services\StoredProcedure;
  20. use App\Util;
  21. use App\Utility\SetNXLock;
  22. use Illuminate\Http\Request;
  23. use Illuminate\Support\Facades\DB;
  24. use Illuminate\Support\Facades\Redis;
  25. use Log;
  26. // use Yansongda\Pay\Log;
  27. class ApiController extends Controller
  28. {
  29. public function sendTele(Request $request)
  30. {
  31. TelegramBot::getDefault()->sendMsg($request->str);
  32. }
  33. public function log(Request $request){
  34. Util::WriteLog("log",$request->all());
  35. }
  36. public function checkLocale(Request $request){
  37. $UserID=$request->input("UserID");
  38. $user=AccountsInfo::where("UserID",$UserID)->first();
  39. if(!$user){
  40. return apiReturnFail(['web.error.user_not_exist',__('messages.api.user.user_not_exist')]);
  41. }
  42. $Locale=$user->BindLocale;
  43. return apiReturnSuc(compact('UserID','Locale'));
  44. }
  45. public function bindLocale(Request $request){
  46. $UserID=$request->input("UserID");
  47. $Locale=$request->input("Locale");
  48. $user=AccountsInfo::where("UserID",$UserID)->first();
  49. if(!is_string($Locale))$Locale='en';
  50. if(!$user){
  51. return apiReturnFail(['web.error.user_not_exist',__('messages.api.user.user_not_exist')]);
  52. }
  53. if(strstr(env('VALID_LOCALE','pt,en,es'),$Locale)){
  54. return apiReturnFail(['web.error.Locale_not_found',__('messages.api.user.locale_not_supported')]);
  55. }
  56. AccountsInfo::where("UserID",$UserID)->update(["BindLocale"=>$Locale]);
  57. return apiReturnSuc(compact('UserID','Locale'));
  58. }
  59. public function checkCountry(Request $request){
  60. $UserID=$request->input("UserID");
  61. $user=AccountsInfo::where("UserID",$UserID)->first();
  62. if(!$user){
  63. return apiReturnFail(['web.error.user_not_exist',__('messages.api.user.user_not_exist')]);
  64. }
  65. $Country=$user->BindCountry;
  66. return apiReturnSuc(compact('UserID','Country'));
  67. }
  68. public function bindCountry(Request $request){
  69. $UserID=$request->input("UserID");
  70. $Country=$request->input("Country");
  71. $user=AccountsInfo::where("UserID",$UserID)->first();
  72. if(!is_string($Country))$Country='CO';
  73. if(!$user){
  74. return apiReturnFail(['web.error.user_not_exist',__('messages.api.user.user_not_exist')]);
  75. }
  76. // if(!empty($user->BindCountry)&&$user->BindCountry!=$Country){
  77. // return apiReturnFail(['web.error.user_already_bind',__('messages.api.user.user_already_bind')]);
  78. // }
  79. if(!isset(IpCheck::$countries[$Country])){
  80. return apiReturnFail(['web.error.country_not_found',__('messages.api.user.country_not_found')]);
  81. }
  82. AccountsInfo::where("UserID",$UserID)->update(["BindCountry"=>$Country]);
  83. return apiReturnSuc(compact('UserID','Country'));
  84. }
  85. public function errorReport(Request $request){
  86. Util::WriteLog('clientError',$request->header());
  87. try {
  88. $config = $request->input('config');
  89. $sign = $request->input('s');
  90. if (md5($config . 'nicaia') == $sign) {
  91. $exception = $request->input('exception');
  92. $config = $request->input('config');
  93. $uid = $request->input('uid');
  94. $hash = md5($exception);
  95. $config = substr($config, 0, 3000);
  96. $userinfo = ['ErrorID' => 0, 'IP' => $request->ip(), 'UserID' => $uid, 'Config' => $config, 'Lang' => $request->header('accept-language') ?? '', 'UserAgent' => substr($request->header('user-agent') ?? '', 0, 200)];
  97. $exception = \GuzzleHttp\json_decode($exception, true);
  98. $config = \GuzzleHttp\json_decode($config, true);
  99. $config['firstUseIpList'] = array_slice($config['firstUseIpList'], 0, 1);
  100. $userinfo['Config'] = json_encode($config);
  101. $exception = ['HashKey' => $hash, 'Msg' => urldecode($exception[2]), 'Stack' => urldecode($exception[3]), 'Package' => $config['AppId'] . '_' . $config['ClientVersion'], 'Channel' => Util::getPackageByURL($config['AppId'])['channel']];
  102. $package = $exception['Package'];
  103. $error = DB::table("QPRecordDB.dbo.ClientError")->where(["HashKey" => $hash, 'Package' => $package])->first();
  104. if (!$error) {
  105. $userinfo['ErrorID'] = DB::table("QPRecordDB.dbo.ClientError")->insertGetId($exception);
  106. } else {
  107. $userinfo['ErrorID'] = $error->ID;
  108. if ($error->DateKey != date("Y-m-d") && $error->Sign == 0) {
  109. $userinfo['ErrorID'] = DB::table("QPRecordDB.dbo.ClientError")->insertGetId($exception);
  110. } else {
  111. DB::table("QPRecordDB.dbo.ClientError")->where('ID', $error->ID)->update(['Times' => $error->Times + 1]);
  112. }
  113. }
  114. $exuser = DB::table("QPRecordDB.dbo.ClientErrorUsers")->where(['ErrorID' => $userinfo['ErrorID'], 'UserID' => $userinfo['UserID'], 'DateKey' => date("Y-m-d")])->first();
  115. if ($exuser && isset($exuser->ID)) {
  116. DB::table("QPRecordDB.dbo.ClientErrorUsers")->where('ID', $exuser->ID)->update(['Times' => $exuser->Times + 1]);
  117. } else {
  118. // DB::table("QPRecordDB.dbo.ClientErrorUsers")->insert($userinfo);
  119. }
  120. if ($hash == 'ca512f200c7060491b76af73d12c8952') {
  121. return apiReturnSuc(['script' => 'jsb.fileUtils.removeDirectory(jsb.fileUtils.getWritablePath());setTimeout(()=>cc.game.restart(), 500);']);
  122. }
  123. // Util::WriteLog('clientError',$request->header());
  124. return apiReturnSuc([]);
  125. }
  126. }catch (\Exception $exception){
  127. return apiReturnSuc([]);
  128. }
  129. }
  130. public function maintain(){
  131. return apiReturnSuc(['ret' =>['state' => 0 ,'content' => __('messages.api.common.maintenance_in_progress')]]);
  132. }
  133. //评论过
  134. public function rateUs(Request $request){
  135. $pack=$request->input("PackageName");
  136. $v=$request->input("v");
  137. $UserID=$request->input("UserID");
  138. $cv=1;
  139. if(isset($request->cv)){
  140. $cvstr=explode('.',$request->cv);
  141. $cv=array_pop($cvstr);
  142. }
  143. DB::table("QPRecordDB.dbo.AccountsRateUsRecord")->insert(['UserID'=>$UserID,'Package'=>$pack."_$v"."_$cv"]);
  144. }
  145. //设置分销
  146. public function setCommission(Request $request)
  147. {
  148. $user_id = $request->input('user_id');
  149. $commission = $request->input('commission');
  150. $result = Subordinate::setCommission(['user_id' => $user_id, 'commission' => $commission]);
  151. return $result;
  152. }
  153. //用户留言
  154. public function userMessageAdd(Request $request)
  155. {
  156. $params = $request->all();
  157. if (empty($params['GameID'])) {
  158. return ['status' => false, 'msg' => __('messages.api.common.user_info_not_obtained')];
  159. }
  160. $insert['GameID'] = $params['GameID'];
  161. $insert['PID'] = 0;
  162. $url = $request->url() . '?message=' . $params['message'];
  163. $url = urldecode($url);
  164. $query = parse_url($url)['query'];
  165. $paramsArr = explode('&', $query);
  166. foreach ($paramsArr as $k => $v) {
  167. $a = explode('=', $v);
  168. $arr[$a[0]] = $a[1];
  169. }
  170. if (empty($arr['message']) || !isset($arr['message'])) {
  171. return ['status' => false, 'msg' => __('messages.api.common.fill_message')];
  172. }
  173. $insert['Msg'] = $arr['message'];
  174. if (mb_strlen($insert['Msg']) > 300) {
  175. return apiReturnFail(__('messages.api.common.characters_too_long'));
  176. }
  177. $insert['CreateAt'] = date('Y-m-d H:i:s');
  178. $insert['Type'] = 0;
  179. $result = DB::table('QPAccountsDB.dbo.Message')
  180. ->insert($insert);
  181. if ($result) {
  182. return ['status' => true, 'msg' => __('messages.api.message.leave_success'), 'code' => 200];
  183. } else {
  184. return ['status' => false, 'msg' => __('messages.api.message.leave_fail'), 'code' => 301];
  185. }
  186. }
  187. //获取留言
  188. public function userMessageList(Request $request)
  189. {
  190. $game_id = $request->input('GameID');
  191. if ($game_id == 0) {
  192. return ['status' => true, 'msg' => __('messages.api.message.get_success'), 'data' => []];
  193. }
  194. $ids = DB::connection('read')->table('QPAccountsDB.dbo.Message')
  195. ->where('GameID', $game_id)
  196. ->pluck('ID');
  197. $data = DB::connection('read')->table('QPAccountsDB.dbo.Message')
  198. ->whereIn('PID', $ids)
  199. ->orwhere('GameID', $game_id)
  200. ->orderBy('CreateAt', 'desc')
  201. ->get()->toArray();
  202. $data = array_reverse($data);
  203. foreach ($data as &$val) {
  204. $val->CreateAt = date('Y-m-d H:i:s', strtotime($val->CreateAt));
  205. }
  206. $ids = $ids->toArray();
  207. // 消息改已读
  208. DB::connection('write')->table('QPAccountsDB.dbo.Message')
  209. ->whereIn('PID', $ids)
  210. ->update(['is_read' => 1]);
  211. $r = DB::connection('write')->table('QPAccountsDB.dbo.Message')->where('GameID', $game_id)->update(['is_read' => 1]);
  212. // foreach ($ids as $v) {
  213. // DB::table('QPAccountsDB.dbo.Message')->where('PID', $v)->update(['is_read' => 1]);
  214. // }
  215. if ($data) {
  216. return ['status' => true, 'msg' => __('messages.api.message.get_success'), 'data' => $data];
  217. } else {
  218. return ['status' => false, 'msg' => __('messages.api.message.no_chat_record'), 'data' => []];
  219. }
  220. }
  221. // 获取用户未读消息总数
  222. public function wait_read(Request $request)
  223. {
  224. $GameID = (int)$request->GameID ?: '';
  225. if (empty($GameID)) {
  226. return apiReturnSuc();
  227. }
  228. $ids = DB::connection('read')->table('QPAccountsDB.dbo.Message')
  229. ->where('GameID', $GameID)
  230. ->pluck('ID');
  231. $count = DB::connection('read')->table('QPAccountsDB.dbo.Message as a')
  232. ->join('QPAccountsDB.dbo.Message as b', function ($query) use ($GameID) {
  233. $query->on('a.ID', 'b.ID')->orwhere('b.GameID', $GameID)->where('b.is_read', 0);
  234. })
  235. ->whereIn('a.PID', $ids)
  236. ->where('a.is_read', 0)
  237. ->count();
  238. return apiReturnSuc($count);
  239. }
  240. public function getServiceList(){
  241. $key='customer_service_n';
  242. if(Redis::exists($key)) {
  243. $list=json_decode(Redis::get($key));
  244. }
  245. if(!isset($list)||empty($list)){
  246. $list = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  247. ->where('StatusName', 'Email')
  248. ->orWhere('StatusName', 'WhatsApp')
  249. ->orWhere('StatusName', 'Telegram')
  250. ->get();
  251. $WhatsApp_ID = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  252. ->where('StatusName', 'WhatsApp_ID')
  253. ->first();
  254. $chat = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  255. ->where('StatusName', 'Telegram')
  256. ->first();
  257. foreach ($list as &$value) {
  258. if ($value->StatusName == 'WhatsApp') {
  259. $value->StatusValue = $WhatsApp_ID->StatusString;
  260. }
  261. if ($value->StatusName == 'Telegram') {
  262. $value->StatusValue = $chat->StatusString;
  263. // if (rand(1, 100) > 50) {
  264. // $value->StatusValue = '';
  265. // }
  266. }
  267. }
  268. Redis::set($key,json_encode($list));
  269. Redis::expire($key, 600);
  270. }
  271. $packinfo=Util::getPackageByURL();
  272. if($packinfo&&isset($packinfo['channel'])) {
  273. $channel = $packinfo['channel'];
  274. }else{
  275. $channel=100;
  276. }
  277. $rand_value=-1;
  278. foreach ($list as &$value) {
  279. if ($value->StatusName == 'WhatsApp') {
  280. if(strstr($value->StatusValue,"{")) {
  281. $value->StatusValue = json_decode($value->StatusValue, true);
  282. if(isset($value->StatusValue[$channel])){
  283. $value->StatusValue=$value->StatusValue[$channel];
  284. }else{
  285. $value->StatusValue=$value->StatusValue['default'];
  286. }
  287. //一个渠道下多个
  288. if(strstr($value->StatusValue,',')) {
  289. $arr=explode(',',$value->StatusValue);
  290. if($rand_value==-1)$rand_value=array_rand($arr);
  291. $value->StatusValue=$arr[$rand_value];
  292. }
  293. }
  294. if(strstr($value->StatusString,'{')) {
  295. $value->StatusString = json_decode($value->StatusString, true);
  296. if(isset($value->StatusString[$channel])){
  297. $value->StatusString=$value->StatusString[$channel];
  298. }else{
  299. $value->StatusString=$value->StatusString['default'];
  300. }
  301. //一个渠道下多个
  302. if(strstr($value->StatusString,',')) {
  303. $arr=explode(',',$value->StatusString);
  304. if($rand_value==-1)$rand_value=array_rand($arr);
  305. $value->StatusString=$arr[$rand_value];
  306. }
  307. //替换+和补?
  308. $d=$value->StatusString;
  309. if(strstr($d,'+')){
  310. $d=str_replace('+','',$d);
  311. }
  312. if(!strstr($d,'?')){
  313. $d.='?';
  314. }
  315. $value->StatusString=$d;
  316. }
  317. }
  318. }
  319. return $list;
  320. }
  321. private function getServiceListHigh(){
  322. $key='high_customer_service';
  323. if(Redis::exists($key)) {
  324. $list=json_decode(Redis::get($key));
  325. }
  326. if(!isset($list)||empty($list)){
  327. $list = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  328. ->where('StatusName', 'Email')
  329. ->orWhere('StatusName', 'WhatsApp')
  330. ->orWhere('StatusName', 'OnlineChat')
  331. ->get();
  332. $WhatsApp_ID = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  333. ->where('StatusName', 'WhatsApp_ID')
  334. ->first();
  335. $chat = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  336. ->where('StatusName', 'OnlineChat')
  337. ->first();
  338. foreach ($list as &$value) {
  339. if ($value->StatusName == 'WhatsApp') {
  340. $value->StatusValue = $WhatsApp_ID->StatusString;
  341. }
  342. if ($value->StatusName == 'OnlineChat') {
  343. $value->StatusValue = $chat->StatusString;
  344. if (rand(1, 100) > 50) {
  345. $value->StatusValue = '';
  346. }
  347. }
  348. }
  349. Redis::set($key,json_encode($list));
  350. Redis::expire($key, 600);
  351. }
  352. $packinfo=Util::getPackageByURL();
  353. if($packinfo&&isset($packinfo['channel'])) {
  354. $channel = $packinfo['channel'];
  355. }else{
  356. $channel=100;
  357. }
  358. $rand_value=-1;
  359. foreach ($list as &$value) {
  360. if ($value->StatusName == 'WhatsApp') {
  361. if(strstr($value->StatusValue,"{")) {
  362. $value->StatusValue = json_decode($value->StatusValue, true);
  363. if(isset($value->StatusValue[$channel])){
  364. $value->StatusValue=$value->StatusValue[$channel];
  365. }else{
  366. $value->StatusValue=$value->StatusValue['default'];
  367. }
  368. //一个渠道下多个
  369. if(strstr($value->StatusValue,',')) {
  370. $arr=explode(',',$value->StatusValue);
  371. if($rand_value==-1)$rand_value=array_rand($arr);
  372. $value->StatusValue=$arr[$rand_value];
  373. }
  374. }
  375. if(strstr($value->StatusString,'{')) {
  376. $value->StatusString = json_decode($value->StatusString, true);
  377. if(isset($value->StatusString[$channel])){
  378. $value->StatusString=$value->StatusString[$channel];
  379. }else{
  380. $value->StatusString=$value->StatusString['default'];
  381. }
  382. //一个渠道下多个
  383. if(strstr($value->StatusString,',')) {
  384. $arr=explode(',',$value->StatusString);
  385. if($rand_value==-1)$rand_value=array_rand($arr);
  386. $value->StatusString=$arr[$rand_value];
  387. }
  388. }
  389. }
  390. }
  391. return $list;
  392. }
  393. // 客服功能
  394. public function customer_service()
  395. {
  396. $list=$this->getServiceList();
  397. $result = apiReturnSuc($list);
  398. // $dir = $path = app()->basePath() . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'cache';
  399. // if (!file_exists($dir)) {
  400. // mkdir($dir, 0777);
  401. // }
  402. // $path = $dir . DIRECTORY_SEPARATOR . "customer_service.json";
  403. // file_put_contents($path, json_encode($result));
  404. return $result;
  405. }
  406. // 渠道审核屏蔽ID白名单
  407. public function channel_shield_id_white(Request $request)
  408. {
  409. $GameID = $request->GameID ?: '';
  410. if (empty($GameID)) {
  411. return apiReturnFail(__('messages.api.common.missing_user_id'));
  412. }
  413. $State = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  414. ->where('StatusName', 'ChannelShieldIDWhite')
  415. ->first();
  416. if ($State->StatusValue == 2) {
  417. return apiReturnFail();
  418. }
  419. $first = DB::connection('write')->table('QPPlatformDB.dbo.ChannelShieldIDWhite')
  420. ->where('GameID', $GameID)
  421. ->where('State', 1)
  422. ->first();
  423. if ($first) {
  424. return apiReturnSuc();
  425. }
  426. return apiReturnFail();
  427. }
  428. public function getLoginIpMap($package){
  429. $key="getLoginIpMap_$package";
  430. try {
  431. if (Redis::exists($key)) {
  432. $arrs = json_decode(Redis::get($key), true);
  433. }
  434. }catch (\Exception $e){}
  435. if(!isset($arrs)){
  436. $pack = Util::getPackageByURL($package);
  437. $channel = 100;
  438. if (isset($pack) && $pack['bundleid'] == $package) {
  439. $channel = $pack['channel'];
  440. }
  441. // SELECT FROM LoginIPMap WITH(nolock) WHERE Channel=@Channel AND Status=1
  442. if (!DB::table("QPPlatformDB.dbo.LoginIPMap")->where("Channel", $channel)->exists()) $channel = 100;
  443. $arrs = DB::table("QPPlatformDB.dbo.LoginIPMap")
  444. ->select("ID", "LoginAddr", "LoginPort")
  445. ->where("Channel", $channel)
  446. ->orderBy("ID")
  447. ->get()->toArray();
  448. Redis::set($key,json_encode($arrs));
  449. Redis::expire($key,60);
  450. }
  451. return $arrs;
  452. }
  453. // 返回登录IP
  454. public function LoginIPMap(Request $request)
  455. {
  456. $PackageName = (string)$request->get('PackageName');
  457. // $list = StoredProcedure::getLoginIPMap($PackageName);
  458. $list = $this->getLoginIpMap($PackageName);
  459. $result = $request->ip();
  460. return apiReturnSuc($list, $result);
  461. }
  462. public function LoginIP_Hand($ip_check_key,Request $request){
  463. $data=$this->LoginIPData($request);
  464. $ndata=[
  465. $ip_check_key.'_list' => $data['list'],
  466. // $ip_check_key.'_login_ip' => $data['login_ip'],
  467. $ip_check_key.'_ouro_init' => $data['ouro_init']??"",
  468. $ip_check_key=>$data['ip_check'],
  469. ];
  470. return base64_encode(json_encode(apiReturnSuc($ndata)));
  471. }
  472. public function LoginIP_Mask($ip_check_key,Request $request){
  473. $code=base64_decode($request->get("code"));
  474. $data=$this->LoginIPData($request,json_decode($code,true));
  475. $ndata=[
  476. $ip_check_key.'_list' => $data['list'],
  477. // $ip_check_key.'_login_ip' => $data['login_ip'],
  478. $ip_check_key.'_init' => $data['ouro_init']??"",
  479. $ip_check_key=>$data['ip_check'],
  480. ];
  481. // dd($ndata);
  482. return base64_encode(json_encode(apiReturnSuc($ndata)));
  483. }
  484. public function LoginIP_NMask($checkkey,$ip_check_key,Request $request){
  485. $ck2package=[
  486. 'check'=>'gold.ruby777.play',
  487. 'version'=>'com.legends777.game.slots'
  488. ];
  489. $chatport=[
  490. 'check'=>8340,
  491. 'version'=>8340
  492. ];
  493. $api=[
  494. 'check'=>'api',
  495. 'version'=>'api'
  496. ];
  497. $PackageName = $request->get('PackageName')??"";
  498. if(empty($PackageName)&&!isset($ck2package[$checkkey]))return;
  499. $ver=$request->ver??$request->cv;
  500. $cvstr = explode('.', $ver);
  501. $cv = array_pop($cvstr);//js客户端版本
  502. $v = array_pop($cvstr);//android code
  503. $requestInfo=[
  504. 'PackageName'=>$PackageName??$ck2package[$checkkey],
  505. 'v'=>$v
  506. ];
  507. $data=$this->LoginIPData($request,$requestInfo);
  508. // dd($data);
  509. $ndata=[
  510. $ip_check_key=>$data['ip_check'],
  511. $ip_check_key.'1' => $data['list'],
  512. // $ip_check_key.'_login_ip' => $data['login_ip'],
  513. $ip_check_key.'2' => $data['ouro_init']??"",
  514. $ip_check_key.'3' => $data['base_url']??"",
  515. $ip_check_key.'4' => ChannelController::searchChannel($requestInfo['PackageName'],$cv),
  516. $ip_check_key.'5' => $checkkey=="version"?GetVersionController::getVersion():GetVersionController::getVersionRuby(),
  517. $ip_check_key.'6' => 'http://'.$_SERVER["HTTP_HOST"].'/'.$api[$checkkey].'/game_api/billboard',
  518. $ip_check_key.'7' => $data['customer']??"",
  519. $ip_check_key.'8' => $data['cdn']??"",
  520. $ip_check_key.'9' => $chatport[$checkkey],
  521. ];
  522. // dd($ndata);
  523. return str_replace('Y','%',base64_encode(json_encode(apiReturnSuc($ndata))));
  524. }
  525. private function LoginIPData(Request $request,$otherData=[]){
  526. $PackageName = strval($request->get('PackageName')??$otherData['PackageName']??"");
  527. if(empty($PackageName))return;
  528. $v = $request->get('v')??0;
  529. if(!$v&&isset($otherData['v']))$v=$otherData['v'];
  530. $v=intval($v);
  531. $cv=Util::getClientVer();
  532. $service = new IpCheck();
  533. // $list = StoredProcedure::getLoginIPMap($PackageName);
  534. $list = $this->getLoginIpMap($PackageName);
  535. // $login_ip = $request->ip();
  536. $login_ip = IpLocation::getIP();
  537. $rip=IpLocation::getRealIp();
  538. $ip=IpLocation::getIP();
  539. if($login_ip!=$rip||$login_ip!=$ip){
  540. TelegramBot::getDefault()->sendMsgWithEnv(json_encode(['login_ip'=>$login_ip,'rip'=>$rip,'ip'=>$ip]));
  541. }
  542. $ipcheck=$service->ipCheck($login_ip,$PackageName,$v);
  543. $needfake=0;
  544. if(strstr($PackageName,'com.ouro777.ares')){
  545. if(!$ipcheck)$needfake=1;
  546. $ipcheck='BR';
  547. }
  548. $data = [
  549. 'list' => $ipcheck?$list:[$list[0]],
  550. 'login_ip' => $login_ip,
  551. 'ip_check' => $ipcheck?true:false,
  552. 'ip_black'=>false,
  553. 'customer'=>'',
  554. 'chatport'=>0,
  555. 'org'=>true,
  556. ];
  557. // 'showRateUs'=>1,//发起评分
  558. if(!$ipcheck){
  559. $data = [
  560. 'list' => $ipcheck?$list:[$list[0]],
  561. 'login_ip' => '',
  562. 'ip_check' => $ipcheck?true:false,
  563. 'ip_black'=>false,
  564. ];
  565. }else{
  566. $data['gamesorts']=ChannelController::searchChannel($PackageName,$cv);
  567. $data['gameversions']=GetVersionController::getVersion();
  568. $data['webgamerooms']=GameApiController::webGameRooms();
  569. $data['show_billboard']='http://'.$request->getHttpHost().'/api/game_api/billboard';
  570. $data['customer']=$this->getServiceList();
  571. $data['wss_server']='wss://'.env('CONFIG_OURO_WSS').':';
  572. $data['chatport']=8340;
  573. $data['vip_config']=RechargeController::getVipConfig();
  574. $packinfo=DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  575. ->where('PackageName', $PackageName)->select("AdjustConfig","Version")->first();
  576. $data['adjust']=$packinfo->AdjustConfig??0;
  577. $data['spv']=$packinfo->Version??0;
  578. //PK支付在paychanel显示手机号确认
  579. $data['show_phone_confirm']=0;
  580. $data['g']=$needfake;
  581. $data['base_url']=env('APP_URL').'/';
  582. $data['gear_act']=false;
  583. $data['free_relief']=1;
  584. $data['runhorse_value']=1;
  585. if($login_ip=='116.87.197.194'){
  586. // $data['gear_act']=env('BASE_CDN').'glo/pakistan/assets/act/deposit.png';
  587. }
  588. $data['share_rich']=env('SHARE_MAIN_TITLE','<bold><color=#FFCC00>PK3</c><color=#ffffff>.BET</color></bold>');
  589. $data['kefu_switch']=0;
  590. $data['upgrade_bonus'] = SystemStatusInfo::OnlyGetCacheValue('BindPhoneReward') ?? 100;
  591. $VALID_COUNTRY=explode(',',env('VALID_COUNTRY','BR'));
  592. if(count($VALID_COUNTRY)) {
  593. $data['valid_countries'] = array_filter(IpCheck::$countries,function ($v) use($VALID_COUNTRY){return in_array($v,$VALID_COUNTRY);},ARRAY_FILTER_USE_KEY);
  594. // $data['valid_countries'] = ['CO' => IpCheck::$countries['CO'], 'PE' => IpCheck::$countries['PE']];
  595. }
  596. if(env('MULTI_COUNTRY',0)==1) {
  597. $data['loc'] = $ipcheck;
  598. }else{
  599. $data['loc'] = env('VALID_COUNTRY');
  600. }
  601. }
  602. $data['init_games']=[Util::$KIND_ID_FRUIT9X,Util::$KIND_ID_HALLOWEEN];
  603. switch (env('VALID_COUNTRY','BR')){
  604. case 'PK':
  605. {
  606. $data['init_games'] = [Util::$KIND_ID_FRUIT9X, Util::$KIND_ID_OLYMPUS, Util::$KIND_ID_AVIATOR2, Util::$KIND_ID_MINES, Util::$KIND_ID_LHD];
  607. break;
  608. }
  609. case 'BD':
  610. {
  611. $data['init_games'] = [Util::$KIND_ID_FRUIT9X, Util::$KIND_ID_OLYMPUS, Util::$KIND_ID_AVIATOR2, Util::$KIND_ID_MINES, Util::$KIND_ID_LHD];
  612. break;
  613. }
  614. }
  615. if(in_array($PackageName,['com.ssme2.ttt','com.bigwinappstore.spain','com.ssme.test'])){
  616. if($ipcheck){
  617. $data['ouro_init'] = "truco_init_bx";
  618. }else{
  619. $data['ouro_init'] = "";
  620. }
  621. }
  622. if(in_array($PackageName,['com.silamedia.chocolaterecipe','com.fantasy.fruit'])){
  623. $data['ou']='close';//closeUpdate
  624. }
  625. if(strstr($ipcheck,"MX")){
  626. if($PackageName==Util::$PACKAGE_110||$PackageName==Util::$PACKAGE_113) {
  627. $data['ouro_init'] = "mx_init_1224";
  628. }else{
  629. $data['ouro_init']="mx_init7";
  630. }
  631. // if(in_array($PackageName,["com.game.dream.snake","com.rosidapps.lagufelix","com.crazy.balloon","com.crazy.balloon2","com.rosidapps.lagufelix2","com.game.dream.snake2","com.secggplcheck.ott","com.secggplcheck.ott2","com.colorclicker.nhbfv","com.colorclicker.nhbfv2"])){
  632. // }
  633. Util::WriteLog('entermx','');
  634. }
  635. if(strstr($ipcheck,"MXX")){
  636. if($PackageName==Util::$PACKAGE_110) {
  637. $data['ouro_init'] = "mx_init_1224";
  638. }
  639. }
  640. return $data;
  641. }
  642. // 返回登录IP--新接口
  643. public function LoginIP(Request $request)
  644. {
  645. $data=$this->LoginIPData($request);
  646. return apiReturnSuc($data);
  647. }
  648. // 返回登录IP--新接口
  649. public function LoginIPCheck(Request $request)
  650. {
  651. $PackageName = (string)$request->get('PackageName');
  652. $login_ip = (string)$request->get('ip');
  653. $service = new IpCheck();
  654. // $list = StoredProcedure::getLoginIPMap($PackageName);
  655. $list = $this->getLoginIpMap($PackageName);
  656. $data = [
  657. 'list' => $list,
  658. 'login_ip' => $login_ip,
  659. 'kefu_switch' => 0,
  660. 'ip_check' => $service->ipCheck($login_ip),
  661. 'base_url'=>'',//多对多跳转
  662. // 'show_billboard'=>'http://api.slotfuns.com/api/rank/index?UserID=186408',//billboardd地址
  663. 'customer'=>$this->getServiceList()
  664. ];
  665. if($PackageName=="com.vencedor.appstore"||$PackageName=="com.vencedor.ios"){
  666. $data['ip_check']=false;
  667. Util::WriteLog('appstore',$data );
  668. }
  669. return apiReturnSuc($data);
  670. }
  671. // 用户支付绑定信息修改
  672. public function updateAccountsPayInfo(Request $request)
  673. {
  674. $account = $request->Account ?: '';
  675. $phone = $request->Phone ?: '';
  676. $email = $request->Email ?: '';
  677. $UserID = $request->UserID ?: '';
  678. $PixNum = $request->PixNum ?: '';
  679. if (empty($UserID)) return apiReturnFail(__('messages.api.common.missing_info'));
  680. if(!Util::validateCpf($PixNum)){
  681. return apiReturnFail(__('messages.api.withdraw_info.wrong_cpf'));
  682. }
  683. $redisKey = 'Api_updateAccountsPayInfo_'.$UserID;
  684. $lock = SetNXLock::getExclusiveLock($redisKey);
  685. if (!$lock) {
  686. return apiReturnFail(__('messages.api.withdraw_info.try_again_later'));
  687. }
  688. $exist = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')->where('UserID', $UserID)->first();
  689. if ($exist) {
  690. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')->where('UserID', $UserID)->update(['PixNum' => $PixNum]);
  691. } else {
  692. $data = ['BankUserName' => $account, 'PhoneNumber' => $phone, 'EmailAddress' => $email, 'UserID' => $UserID, 'PixNum' => $PixNum, 'Achieves' => '', 'HistoryWithDraw' => 0];
  693. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  694. ->insert($data);
  695. }
  696. SetNXLock::release($redisKey);
  697. return apiReturnSuc();
  698. }
  699. // 用户支付绑定信息获取
  700. public function getAccountsPayInfo(Request $request)
  701. {
  702. $UserID = $request->UserID ?: '';
  703. if (empty($UserID)) return apiReturnFail(__('messages.api.common.missing_info'));
  704. if(strstr($UserID,"&")){
  705. $UserID=explode("&",$UserID)[0];
  706. }
  707. $userInfo = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  708. ->where('UserID', $UserID)
  709. ->first();
  710. if(!$userInfo)return apiReturnFail(__('messages.api.common.missing_info'));
  711. //同一个内网
  712. $localIp=explode('.',env('SERVER_GAME_REDIS_HOST'))[0];
  713. $RegisterIP=$userInfo->RegisterIP;
  714. $LastLogonIP=$userInfo->LastLogonIP;
  715. $ip=IpLocation::getIP();
  716. if(str_starts_with($RegisterIP,$localIp)){
  717. $RegisterIP=$ip;
  718. }
  719. if(str_starts_with($LastLogonIP,$localIp)){
  720. $LastLogonIP=$ip;
  721. }
  722. if($LastLogonIP!=$userInfo->LastLogonIP||$RegisterIP!=$userInfo->RegisterIP){
  723. DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  724. ->where('UserID', $UserID)
  725. ->update(['RegisterIP'=>$RegisterIP,'LastLogonIP'=>$LastLogonIP]);
  726. }
  727. $info = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  728. ->where('UserID', $UserID)
  729. ->select('PixNum')
  730. ->first();
  731. //召回
  732. try {
  733. $callback = DB::table(TableName::agent() . 'UserCallBack')->where('UserID', $UserID)->first();
  734. if($callback){
  735. if($callback->call_state == 0){
  736. $update = [
  737. 'call_state' => 1,
  738. 'CallbackDate' => date('Y-m-d H:i:s'),
  739. 'LastLogonDate' => date('Y-m-d H:i:s'),
  740. ];
  741. //召回奖励
  742. Custom::updateAdminBonus($callback->admin_id,20,1);
  743. }else{
  744. $update = [
  745. 'LastLogonDate' => date('Y-m-d H:i:s'),
  746. ];
  747. }
  748. DB::table(TableName::agent() . 'UserCallBack')->where('UserID', $UserID)->update($update);
  749. }
  750. }catch (\Exception $e){
  751. }
  752. //巴西才能这样验证
  753. if(!empty($info->PixNum)&&env('COUNTRY_CODE')=='55'){
  754. if(!Util::validateCpf($info->PixNum)){
  755. $info->PixNum="";
  756. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  757. ->where('UserID', $UserID)->update(['PixNum' => $info->PixNum]);
  758. }
  759. }
  760. return apiReturnSuc($info);
  761. }
  762. // 提现手续费返回
  763. public function withDrawTax()
  764. {
  765. $WithDrawTax = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo as si')
  766. ->where('si.StatusName', 'WithDrawTax')
  767. ->value('StatusValue');
  768. $WithDrawTax = $WithDrawTax / 100;
  769. return apiReturnSuc(compact('WithDrawTax'));
  770. }
  771. public function newGuide(Request $request){
  772. $UserID = $request->UserID ?: '';
  773. if (empty($UserID)) return apiReturnSuc(['new_guide' => 0]);
  774. //玩家信息
  775. $userInfo = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  776. ->where('UserID', $UserID)
  777. ->first();
  778. if (empty($userInfo)) return apiReturnSuc(['new_guide' => 0]);
  779. return apiReturnSuc(['new_guide' =>(time() - strtotime($userInfo->RegisterDate)>4000)?0:1]);
  780. }
  781. public function test(Request $request){
  782. return apiReturnSuc(['ret' =>[]]);
  783. }
  784. public function onlineList(){
  785. if (Redis::exists('Online_Real')) {
  786. $online = Redis::get('Online_Real');
  787. $online = json_decode($online,true);
  788. } else {
  789. $field = ['gi.GameID', 'gi.Nullity', 'gi.SortID', 'gi.ServerName', 'gi.ServerID'];
  790. $list = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo as gi')
  791. ->whereIn('GameID', config('games.openKGame'))
  792. ->leftJoin('QPTreasureDB.dbo.GameScoreLocker as gl', function ($query) {
  793. $query->on('gl.ServerID', 'gi.ServerID')->selectRaw('gl.ServerID')->groupBy('ServerID')->whereRaw('datediff(hh,gl.CollectDate,getdate())<=5');
  794. })
  795. ->select($field)
  796. ->where('Nullity', 0)
  797. ->selectRaw('IsNull(count(DISTINCT gl.UserID),0) as game_count')
  798. ->groupBy($field)
  799. ->orderBy('gi.GameID', 'asc')
  800. ->orderBy('gi.ServerName', 'asc')
  801. ->get()->toArray();
  802. $online = [];
  803. foreach ($list as $item) {
  804. $item = json_decode(json_encode($item), true);
  805. if (isset($online[$item['GameID']])) {
  806. $online[$item['GameID']][$item['SortID']] += intval($item['game_count']);
  807. } else {
  808. if ($item['GameID'] == 4000) {
  809. $online[$item['GameID']] = [1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0];
  810. } else {
  811. $online[$item['GameID']] = [1 => 0, 2 => 0, 3 => 0];
  812. }
  813. $online[$item['GameID']][$item['SortID']] = intval($item['game_count']);
  814. }
  815. }
  816. $online[4010][1] = intval($online[3014][1] / 8);
  817. $online[4000][1] = intval($online[3017][1] / 7);
  818. $online[917][1] = intval($online[3010][1] / 6);
  819. foreach ($online as $gid => &$ol) {
  820. if($gid == 6001){
  821. $ol[1] = $ol[1] * 368;
  822. }else{
  823. $ol[1] = $ol[1] * 168;
  824. }
  825. $ol[2] = intval($ol[1] / 5);
  826. $ol[3] = intval($ol[1] / 16);
  827. if ($gid == 4000) {
  828. $ol[4] = intval($ol[1] / 18);
  829. $ol[5] = intval($ol[1] / 19);
  830. $ol[6] = intval($ol[1] / 20);
  831. $ol[7] = intval($ol[1] / 21);
  832. }
  833. if ($gid == 917) {
  834. $ol[1] = 0;
  835. $ol[2] = 0;
  836. }
  837. if ($gid == 4010) {
  838. $ol[3] = 0;
  839. }
  840. }
  841. Redis::set('Online_Real',json_encode($online));
  842. Redis::expire('Online_Real', 120);
  843. }
  844. return apiReturnSuc(['ret' =>$online]);
  845. }
  846. public function jackpot(){
  847. $redis = Redis::connection('ServerGameRedis');
  848. $data = [
  849. 3010 => [
  850. 1 => $redis->get("jackpot_3010_1")+0,
  851. 2 => $redis->get("jackpot_3010_2")+0,
  852. 3 => $redis->get("jackpot_3010_3")+0
  853. ],
  854. 3014 => [
  855. 1 => $redis->get("jackpot_3014_1")+0,
  856. 2 => $redis->get("jackpot_3014_2")+0,
  857. 3 => $redis->get("jackpot_3014_3")+0,
  858. 4 => $redis->get("jackpot_3014_4")+0
  859. ],
  860. 3017 => [
  861. 1 => $redis->get("jackpot_3017_1")+0,
  862. 2 => $redis->get("jackpot_3017_2")+0,
  863. 3 => $redis->get("jackpot_3017_3")+0
  864. ],
  865. 3018 => [
  866. //jackpot_{$kindID}_{$v}_{$v1}
  867. 1 => $redis->get("jackpot_3018_1_0")+$redis->get("jackpot_3018_1_1")+$redis->get("jackpot_3018_1_2")+$redis->get("jackpot_3018_1_3")+$redis->get("jackpot_3018_1_4"),
  868. 2 => $redis->get("jackpot_3018_2_0")+$redis->get("jackpot_3018_2_1")+$redis->get("jackpot_3018_2_2")+$redis->get("jackpot_3018_2_3")+$redis->get("jackpot_3018_2_4"),
  869. 3 => $redis->get("jackpot_3018_3_0")+$redis->get("jackpot_3018_3_1")+$redis->get("jackpot_3018_3_2")+$redis->get("jackpot_3018_3_3")+$redis->get("jackpot_3018_3_4"),
  870. ],
  871. 3020 => [
  872. 1 => $redis->get("jackpot_3020_1_0")+$redis->get("jackpot_3020_1_1")+$redis->get("jackpot_3020_1_2")+$redis->get("jackpot_3020_1_3"),
  873. 2 => $redis->get("jackpot_3020_2_0")+$redis->get("jackpot_3020_2_1")+$redis->get("jackpot_3020_2_2")+$redis->get("jackpot_3020_2_3"),
  874. 3 => $redis->get("jackpot_3020_3_0")+$redis->get("jackpot_3020_3_1")+$redis->get("jackpot_3020_3_2")+$redis->get("jackpot_3020_3_3")
  875. ]
  876. ];
  877. return apiReturnSuc(['ret' =>$data]);
  878. }
  879. }