LoginController.php 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\Game\AgentLinks;
  4. use App\Game\GlobalUserInfo;
  5. use App\Game\QuickAccountPass;
  6. use App\Game\QuickAccountPassStore;
  7. use App\Game\RePayConfig;
  8. use App\Game\Services\AgentService;
  9. use App\Game\Services\OuroGameService;
  10. use App\Game\Services\RouteService;
  11. use App\Game\WebChannelConfig;
  12. use App\Http\Controllers\Controller;
  13. use App\Http\helper\NumConfig;
  14. use App\IpLocation;
  15. use App\Jobs\AfEvent;
  16. use App\Models\Account\AccountPhone;
  17. use App\Models\AccountsInfo;
  18. use App\Models\GamePhoneVerityCode;
  19. use App\Models\SystemStatusInfo;
  20. use App\Models\Treasure\GameScoreInfo;
  21. use App\Notification\TelegramBot;
  22. use App\Services\ApkService;
  23. use App\Services\StoredProcedure;
  24. use App\Services\VipService;
  25. use App\Util;
  26. use App\Utility\SetNXLock;
  27. use Carbon\Carbon;
  28. use Illuminate\Http\Request;
  29. use Illuminate\Support\Facades\Cookie;
  30. use Illuminate\Support\Facades\Crypt;
  31. use Illuminate\Support\Facades\DB;
  32. use Illuminate\Support\Facades\Hash;
  33. use Illuminate\Support\Facades\Log;
  34. use Illuminate\Support\Facades\Redis;
  35. use Illuminate\Support\Facades\Validator;
  36. use PDO;
  37. // use Yansongda\Pay\Log;
  38. class LoginController extends Controller
  39. {
  40. public function __construct()
  41. {
  42. }
  43. public function LoginByCode(Request $request,$onlyVerify=false)
  44. {
  45. $RegisterLocation = $request->country ?? env('COUNTRY_CODE','1');
  46. $Phone = $request->phone;
  47. $PhoneCode = $request->code;
  48. $PhoneCode= preg_replace('/\D/s', '', $PhoneCode);
  49. if (empty($Phone)) {
  50. return apiReturnFail(['web.verify.num_empty', 'PhoneNum Empty']);
  51. }
  52. if (mb_strlen($PhoneCode) > 6) {
  53. return apiReturnFail(['web.verify.code_too_long', 'Phone code is too long']);
  54. }
  55. $Phone = $RegisterLocation.trim($Phone);
  56. Log::info('验证电话开始' . $Phone);
  57. $redisKey = 'LoginByCode_' . $Phone;
  58. if (!SetNXLock::getExclusiveLock($redisKey)) {
  59. return apiReturnFail(['web.withdraw.try_again_later', 'Tente novamente mais tarde']);
  60. }
  61. if (!is_numeric($PhoneCode)) {
  62. SetNXLock::release($redisKey);
  63. Log::info('web.verify.code_incorrect_or_expired LoginByCode is_numeric($PhoneCode)',[$Phone,$PhoneCode]);
  64. return apiReturnFail(['web.verify.code_incorrect_or_expired', 'O código está incorreto ou o tempo passou']);
  65. }
  66. $verifyCode = GamePhoneVerityCode::verifyCode($Phone, $PhoneCode);
  67. SetNXLock::release($redisKey);
  68. //TODO 上线前去掉测试
  69. if ($verifyCode != trim($PhoneCode)) {
  70. Log::info('web.verify.code_incorrect_or_expired LoginByCode $verifyCode',[$Phone,$PhoneCode]);
  71. return apiReturnFail(['web.verify.code_incorrect_or_expired', 'O código está incorreto ou o tempo passou']);
  72. }
  73. if($onlyVerify)return true;
  74. $config = RouteService::getChannelConfig($request);
  75. $user = GlobalUserInfo::query()->where('RegionID', $config->isRegionUnique())->where("Phone", $Phone)->first();
  76. if ($user) {
  77. $user = GlobalUserInfo::toWebData($user);
  78. return response()->json(apiReturnSuc($user, ['login.success', 'Login bem-sucedido, bem-vindo de volta!']));//->withCookie($this->setLoginCookie($user['sign']));
  79. } else {
  80. return apiReturnFail(['web.login.notfound', 'Sua conta não foi encontrada, registre-se ou tente novamente!']);
  81. }
  82. }
  83. public function BindPhone(Request $request)
  84. {
  85. $user = GlobalUserInfo::$me;
  86. $RegisterLocation = $request->country ?? env('COUNTRY_CODE','1');
  87. $Phone = $request->phone;
  88. $PhoneCode = $request->code;
  89. if (empty($Phone)) {
  90. Log::info('web.verify.num_empty',[$Phone,$PhoneCode]);
  91. return apiReturnFail(['web.verify.num_empty', 'PhoneNum Empty']);
  92. }
  93. if (mb_strlen($PhoneCode) > 6) {
  94. Log::info('web.verify.code_too_long',[$Phone,$PhoneCode]);
  95. return apiReturnFail(['web.verify.code_too_long', 'Phone code is too long']);
  96. }
  97. $Phone = $RegisterLocation.trim($Phone);
  98. Log::info('绑定电话开始' . $Phone);
  99. $redisKey = 'BindPhone_' . $Phone;
  100. if (!SetNXLock::getExclusiveLock($redisKey)) {
  101. Log::info('web.withdraw.try_again_later',[$Phone,$PhoneCode]);
  102. return apiReturnFail(['web.withdraw.try_again_later', 'Tente novamente mais tarde']);
  103. }
  104. if (!is_numeric($PhoneCode)) {
  105. SetNXLock::release($redisKey);
  106. Log::info('web.verify.code_incorrect_or_expired BindPhone nonum',[$Phone,$PhoneCode]);
  107. return apiReturnFail(['web.verify.code_incorrect_or_expired', 'O código está incorreto ou o tempo passou']);
  108. }
  109. $verifyCode = GamePhoneVerityCode::verifyCode($Phone, $PhoneCode);
  110. if ($verifyCode != trim($PhoneCode)) {
  111. SetNXLock::release($redisKey);
  112. Log::info("web.verify.code_incorrect_or_expired BindPhone $verifyCode",[$Phone,$PhoneCode]);
  113. return apiReturnFail(['web.verify.code_incorrect_or_expired', 'O código está incorreto ou o tempo passou']);
  114. }
  115. $config = RouteService::getChannelConfig($request);
  116. // 查看手机号是否已经绑定
  117. // $first = DB::connection('write')->table('QPAccountsDB.dbo.AccountPhone')
  118. // ->where('PhoneNum', $Phone)
  119. //// ->where('Channel', $user->Channel)
  120. // ->orWhere('UserID', $user->UserID)
  121. $first = GlobalUserInfo::query()->where(function ($query) use ($Phone, $user, $config) {
  122. $query->where(function ($q) use ($Phone, $user) {
  123. $q->where('RegionID', $user->RegionID??"")->where('Phone', $Phone);
  124. })->orWhere(function ($q) use ($user) {
  125. $q->where('UserID', $user->UserID)->where('Phone', '<>', '');
  126. });
  127. })->first();
  128. if ($first) {
  129. SetNXLock::release($redisKey);
  130. Log::info('web.verify.already_bound',[$Phone,$PhoneCode]);
  131. // return apiReturnFail(['web.verify.already_bound', 'O número de telefone foi vinculado']); // 电话号码已绑定
  132. return apiReturnFail(['web.verify.already_bound', 'O número de telefone foi vinculado'],GlobalUserInfo::getGameUserInfoToWeb('UserID',$first->UserID)); // 电话号码已绑定
  133. }
  134. // if (!isset($request->password) || !isset($request->repassword) || $request->password != $request->repassword) {
  135. // Log::info("web.reg.password_notsame",[$Phone,$PhoneCode]);
  136. // return apiReturnFail(['web.reg.password_notsame', 'As senhas digitadas duas vezes são inconsistentes, digite novamente!'], '', 2);
  137. // }
  138. $PhoneNum = $Phone;
  139. $Phone = $this->checkPhone($PhoneNum, $RegisterLocation, $request);
  140. //有错误返回
  141. if (is_array($Phone) || is_object($Phone)){
  142. Log::info(json_encode($Phone),[$Phone,$PhoneCode]);
  143. return $Phone;
  144. }
  145. $UserID = $user->UserID;
  146. $BindDate = Carbon::now()->toDateTimeString();
  147. $LogonPass = $request->password??$PhoneCode;
  148. $Channel = $user->Channel;
  149. $RegionID = $user->RegionID;
  150. // 绑定手机号
  151. AccountPhone::insert(compact('UserID', 'PhoneNum', 'BindDate', 'Channel','RegionID'));
  152. GlobalUserInfo::where('GlobalUID', $user->GlobalUID)->update([ 'Phone' => $Phone, 'RegisterLocation' => $RegisterLocation]);
  153. Log::info('绑定手机号'.'-'.$user->GlobalUID.'-' . $Phone . '-' . $LogonPass . '-' . $UserID);
  154. // --绑定手机赠送金币
  155. $SendGold = SystemStatusInfo::OnlyGetCacheValue('BindPhoneReward') ?? 500;
  156. DB::table('QPRecordDB.dbo.LogProp')->insert(['UserID' => $UserID, 'PropID' => 30000, 'PropNum' => $SendGold, 'Source' => 11, 'Param' => null]);
  157. OuroGameService::AddScore($UserID, $SendGold, OuroGameService::REASON_BindPhone,false);
  158. $RecordPlatformDataModel = new \App\Models\RecordPlatformData();
  159. $RecordPlatformDataModel->BindToday($Channel,$user->RegisterDate);
  160. AgentService::recordPerformance($UserID, 0,1);
  161. SetNXLock::release($redisKey);
  162. return apiReturnSuc(GlobalUserInfo::getGameUserInfoToWeb('UserID', $UserID));
  163. /**
  164. *
  165. * INSERT INTO [QPAccountsDB].[dbo].[AccountPhone] ([UserID],[PhoneNum],[BindDate],[LogonPass],[Channel])values(@UserId,@szPhoneNum,GETDATE(),@strLogonPass,@Channel)
  166. *
  167. * --绑定手机赠送金币
  168. * DECLARE @SendGold int
  169. * select @SendGold = [StatusValue] from QPAccountsDB.dbo.SystemStatusInfo where [StatusName] = 'BindPhoneReward'
  170. * if @SendGold is null
  171. * begin
  172. * set @SendGold = 500;
  173. * end
  174. *
  175. * INSERT INTO QPRecordDB.dbo.LogProp(UserID,PropID,PropNum,Source,[Param],RecordData)
  176. * VALUES(@UserId,30000,@SendGold,11,NULL,GETDATE())
  177. *
  178. * EXEC QPRecordDB.dbo.GSP_YN_GR_RecordGameScore
  179. * @dwUserID=@UserId,
  180. * @lChangeScore=@SendGold,
  181. * @nReason = 21,--绑定手机赠送
  182. * @nServerID=0,
  183. * @strUniqueCode='',
  184. * @lRevenue=0,
  185. * @Type=0
  186. *
  187. * update QPTreasureDB.dbo.GameScoreInfo set Score = Score+@SendGold where @UserId = UserID
  188. */
  189. }
  190. // public function PwaInstalled(Request $request)
  191. // {
  192. // $FPID=$request->input("bfp","");
  193. // $user=$request->user();
  194. //
  195. // GlobalUserInfo::where('FPID',$FPID)->orWhere('UserID',$user->UserID)->update(['PwaInstalled'=>1]);
  196. // }
  197. function generateUUID($userId, $location = '1', $region = null,$Channel=99)
  198. {
  199. if(!$region)$region=env('REGION_24680','sa-east');
  200. // 从随机字节创建基础 UUID
  201. $randomBytes = bin2hex(random_bytes(3)); // 6个字符
  202. $randomBytes=str_pad(dechex($Channel),4,'0',STR_PAD_LEFT).$randomBytes;//补上4个channel
  203. // 缩短区域和语言码以适应 UUID 格式
  204. $locCode = substr(md5($location), 0, 4); // 4个字符
  205. $regionCode = substr(md5($region), 0, 4); // 4个字符
  206. // 确保 UserID 以十六进制形式适应最后部分
  207. $userIdHex = substr("000000000" . $userId, -10, 10); // 变长,确保适应
  208. // 构造 UUID
  209. $uuid = sprintf('%s-%s-%s-%s', $randomBytes, $locCode, $regionCode, $userIdHex);
  210. return $uuid;
  211. }
  212. /// 'PayTotal',
  213. // 'PayTimes',
  214. // 'WithdrawTotal',
  215. // 'LessThan',
  216. // 'Condition',
  217. // 'Price',
  218. // 'Amount',
  219. // 'Gift',
  220. // 'TimeLimit',
  221. // 'Status',
  222. public function GetUserInfo(Request $request)
  223. {
  224. $user = $request->globalUser;
  225. $user = GlobalUserInfo::toWebData($user);
  226. self::CheckTimeBonus($user);
  227. // 计算VIP等级
  228. //$user['vip'] = VipService::calculateVipLevel($user['UserID'] ?? 0);
  229. return apiReturnSuc($user);
  230. }
  231. public static function CheckTimeBonus(&$user)
  232. {
  233. return;
  234. if(!$user)return;
  235. $outdatas=null;
  236. if($user['Channel']==99)return ;
  237. try {
  238. $key='repay_temp_'.$user['UserID'];
  239. if(Redis::exists($key)){
  240. $lastData=json_decode(Redis::get($key),true);
  241. if(!isset($lastData['settime'])){
  242. $lastData['settime']=time();
  243. Redis::set($key, json_encode($lastData));
  244. }
  245. $lastData['timeleft']=$lastData['TimeLimit']-(time()-$lastData['settime']);
  246. unset($lastData['PayTotal'],$lastData['PayTimes'],$lastData['WithdrawTotal'],$lastData['LessThan'],$lastData['id'],$lastData['Condition']);
  247. $user['bonus_pack'] = $lastData;
  248. }else {
  249. //处理新逻辑
  250. $datas = RePayConfig::CacheDatas();
  251. if($user['UserID']=='50000005'){
  252. $user['Score']=10;
  253. }
  254. if (isset($datas) && is_array($datas) && count($datas)) {
  255. $datas = array_filter($datas, function ($v) use ($user) {
  256. return $user['Score'] < $v['LessThan'];
  257. });
  258. }
  259. if (isset($datas) && is_array($datas) && count($datas)) {
  260. // $userstat = DB::connection('write')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  261. // ->where('UserID', $user['UserID'])->first();
  262. $dbh = DB::connection()->getPdo();
  263. $stmt = $dbh->prepare( "EXEC [QPTreasureDB].[dbo].[GSP_GR_QueryUserRechargeInfo] @dwUserID = ".$user['UserID']);
  264. $stmt->execute();
  265. $userstat = $stmt->fetch(\PDO::FETCH_ASSOC);
  266. if($user['UserID']=='50000005'){
  267. $userstat['Recharge']=60000;
  268. $userstat['Withdraw']=0;
  269. }
  270. if ($userstat) {
  271. $datas = array_filter($datas, function ($v) use ($userstat) {
  272. return $userstat['Withdraw'] <= $v['WithdrawTotal'] * NumConfig::NUM_VALUE
  273. && $userstat['Recharge'] >= $v['PayTotal']* NumConfig::NUM_VALUE
  274. && $userstat['RechargeTimes'] <= $v['PayTimes'];
  275. });
  276. } else {
  277. $datas = [];
  278. }
  279. $outdatas = $datas;
  280. if (isset($datas) && is_array($datas) && count($datas)) {
  281. $datas = array_values($datas);
  282. $lastData = $datas[0];
  283. foreach ($datas as $k => $v) {
  284. if ($v['PayTotal'] > $lastData['PayTotal']) {
  285. $lastData = $v;
  286. }
  287. }
  288. if (!empty($lastData)) {
  289. $lastData['gear'] = DB::table('agent.dbo.recharge_gear')
  290. ->where('money', $lastData['Amount'])
  291. ->whereBetween('gift_id', [300, 400])
  292. ->where('status', 2)
  293. ->select('gift_id', 'money', 'give', 'favorable_price', 'second_give')
  294. ->first();
  295. if(empty($lastData['gear'])){
  296. $lastData['gear']=[
  297. 'money' => $lastData['Amount'],
  298. 'gear' => '[{"id":"2","status":1},{"id":"4","status":-1},{"id":"6","status":1},{"id":"11","status":1},{"id":"15","status":1},{"id":"19","status":1}]',
  299. 'status' => 2,
  300. 'created_at' => date('Y-m-d H:i:s.v'),
  301. 'favorable_price' => $lastData['Amount'],
  302. 'image' => '11',
  303. 'give' => $lastData['Gift'],
  304. 'first_pay' => 0,
  305. 'name' => '二次付费',
  306. 'gift_id' => DB::table('agent.dbo.recharge_gear')->where('gift_id','<',400)->max('gift_id')+1,
  307. 'channels' => '',
  308. 'second_give' => 0
  309. ];
  310. DB::table('agent.dbo.recharge_gear')->insert($lastData['gear']);
  311. $lastData['gear']=(object)$lastData['gear'];
  312. }
  313. $lastData['gear']->id = 28;
  314. $lastData['settime']=time();
  315. $lastData['timeleft']=$lastData['TimeLimit'];
  316. $lastData['gear'] = (array)$lastData['gear'];
  317. }
  318. unset($lastData['PayTotal'],$lastData['PayTimes'],$lastData['WithdrawTotal'],$lastData['LessThan'],$lastData['id'],$lastData['Condition']);
  319. Redis::setex($key, $lastData['TimeLimit'], json_encode($lastData));
  320. $user['bonus_pack'] = $lastData;
  321. }
  322. }
  323. }
  324. }catch (\Exception $e) {
  325. TelegramBot::getDefault()->sendMsgWithEnv($e->getMessage().json_encode($outdatas).$e->getTraceAsString());
  326. }
  327. }
  328. public function modiEmail(Request $request)
  329. {
  330. $user = $request->globalUser;
  331. // 自定义错误消息
  332. $messages = [
  333. 'Email.email' => 'O formato do email fornecido está incorreto. ',
  334. 'Email.unique' => 'Este endereço de e-mail foi registrado. ',
  335. ];
  336. // 验证规则
  337. $validator = Validator::make($request->all(), [
  338. 'Email' => 'required|email|unique:mysql.webgame.GlobalUserInfo,Email,' . $user->GlobalUID . ',GlobalUID',
  339. ], $messages);
  340. if ($validator->fails()) {
  341. // 返回具体的错误消息
  342. return apiReturnFail(['web.user.email_fail', $validator->errors()], '', 422);
  343. }
  344. $user->update($validator->validate());
  345. return response()->json(apiReturnSuc(GlobalUserInfo::toWebData($user), ['user.info.modi_success', 'Informação modificada']));
  346. }
  347. public function modiPhone(Request $request)
  348. {
  349. $user = $request->globalUser;
  350. // 自定义错误消息
  351. $messages = [
  352. 'Phone.string' => 'O número de telefone deve estar no formato string. ',
  353. 'Phone.max' => 'O número de telefone não pode exceder 20 caracteres. ',
  354. 'Phone.unique' => 'Este número de telefone já existe. ',
  355. ];
  356. // 验证规则
  357. $validator = Validator::make($request->all(), [
  358. 'Phone' => 'required|string|max:20|unique:mysql.webgame.GlobalUserInfo,Phone,' . $user->GlobalUID . ',GlobalUID',
  359. ], $messages);
  360. if ($validator->fails()) {
  361. // 返回具体的错误消息
  362. return apiReturnFail(['web.user.phone_fail', $validator->errors()], '', 422);
  363. }
  364. $user->update($validator->validate());
  365. return response()->json(apiReturnSuc(GlobalUserInfo::toWebData($user), ['user.info.modi_success', 'Informação modificada']));
  366. }
  367. public function modiUserInfo(Request $request)
  368. {
  369. $user = $request->globalUser;
  370. $validatedData = Validator::make($request->all(), [
  371. 'NickName' => 'nullable|string|max:32',
  372. 'FaceID' => 'nullable|integer|min:1',
  373. 'Gender' => 'nullable|integer|in:0,1,2',
  374. 'DefaultLanguage' => 'nullable|string|max:10',
  375. 'ThemeColor' => 'nullable|in:dark,light'
  376. ], [
  377. 'NickName.string' => 'O apelido deve ser uma string válida. ',
  378. 'NickName.max' => 'O apelido não pode exceder 32 caracteres. ',
  379. 'FaceID.integer' => 'O ID facial deve ser um número inteiro. ',
  380. 'FaceID.min' => 'O ID facial deve ser maior que 0. ',
  381. 'Gender.integer' => 'A seleção de gênero é inválida. ',
  382. 'Gender.in' => 'O gênero deve ser 0 (feminino), 1 (masculino) ou 2 (desconhecido). ',
  383. 'DefaultLanguage.string' => 'O idioma padrão deve ser uma string válida. ',
  384. 'DefaultLanguage.max' => 'O identificador de idioma padrão não pode exceder 10 caracteres. ',
  385. 'ThemeColor.in' => 'A cor do tema deve ser "escuro" ou "claro". '
  386. ]);
  387. if ($validatedData->fails()) {
  388. foreach ($validatedData->errors() as $key => $value) {
  389. return apiReturnFail(['web.modiUserInfo.fail_' . $key, $value[0]], '', 422);
  390. }
  391. }
  392. $validatedData = $validatedData->validate();
  393. foreach ($validatedData as $key => $value) {
  394. if (empty($validatedData[$key]) && $validatedData[$key] !== 0) unset($validatedData[$key]);
  395. }
  396. if (isset($validatedData['FaceID'])) $validatedData['FaceID'] = ($validatedData['FaceID'] - 1) % 16 + 1;
  397. if (isset($validatedData['NickName'])) $validatedData['NickName'] = Util::filterNickName($validatedData['NickName']);
  398. $user->update($validatedData);
  399. return response()->json(apiReturnSuc(GlobalUserInfo::toWebData($user,true), ['user.info.modi_success', 'Informação modificada']));
  400. }
  401. private function checkPhoneCode(Request $request)
  402. {
  403. $user=GlobalUserInfo::$me;
  404. $RegisterLocation = $request->country ?? env('COUNTRY_CODE','55');
  405. $userPhone="";
  406. if($user&&isset($user->Phone)&&substr($user->Phone,0,2)==$RegisterLocation){
  407. $userPhone = explode($RegisterLocation, $user->Phone)[1];
  408. }
  409. $Phone = $request->phone??$userPhone;
  410. // if($Phone!=$userPhone){
  411. // return apiReturnFail(['web.withdraw.try_again_later', 'Tente novamente mais tarde']);
  412. // }
  413. $PhoneCode = $request->code;
  414. if (empty($Phone)) {
  415. return apiReturnFail(['web.verify.num_empty', 'PhoneNum Empty']);
  416. }
  417. if (mb_strlen($PhoneCode) > 6) {
  418. return apiReturnFail(['web.verify.code_too_long', 'Phone code is too long']);
  419. }
  420. $Phone = $RegisterLocation.trim($Phone);
  421. Log::info('验证电话开始' . $Phone);
  422. $redisKey = 'checkPhoneCode_' . $Phone;
  423. if (!SetNXLock::getExclusiveLock($redisKey)) {
  424. return apiReturnFail(['web.withdraw.try_again_later', 'Tente novamente mais tarde']);
  425. }
  426. if (!is_numeric($PhoneCode)) {
  427. SetNXLock::release($redisKey);
  428. Log::info('web.verify.code_incorrect_or_expired checkPhoneCode nonum',[$Phone,$PhoneCode]);
  429. return apiReturnFail(['web.verify.code_incorrect_or_expired', 'O código está incorreto ou o tempo passou']);
  430. }
  431. $verifyCode = GamePhoneVerityCode::verifyCode($Phone, $PhoneCode);
  432. SetNXLock::release($redisKey);
  433. if ($verifyCode != trim($PhoneCode)) {
  434. Log::info('web.verify.code_incorrect_or_expired checkPhoneCode noveri',[$Phone,$PhoneCode]);
  435. return apiReturnFail(['web.verify.code_incorrect_or_expired', 'O código está incorreto ou o tempo passou']);
  436. }
  437. return 1;
  438. }
  439. public function forgetPassword(Request $request)
  440. {
  441. $check=$this->checkPhoneCode($request);
  442. if($check!==1){
  443. return $check;
  444. }
  445. $RegisterLocation = $request->country ?? env('COUNTRY_CODE','55');
  446. $user = GlobalUserInfo::getGameUserInfo("Phone", $RegisterLocation . $request->phone);
  447. if(!$user||empty($user)){
  448. return $this->registerUser($request);
  449. return apiReturnFail(['web.login.notfound', 'Erro de entrada, tente novamente!'], '', 2);
  450. }
  451. $request->globalUser=$user;
  452. return $this->modiPassword($request,false);
  453. }
  454. public function forgetInsurePassword(Request $request)
  455. {
  456. $check=$this->checkPhoneCode($request);
  457. if($check!==1){
  458. return $check;
  459. }
  460. return $this->modiInsurePassword($request,false);
  461. }
  462. public function modiPassword(Request $request,$checkOldpass=true)
  463. {
  464. $user = $request->globalUser;
  465. if($checkOldpass) {
  466. $oldpassword = $request->input('oldpassword');
  467. if (!Hash::check($oldpassword, $user->LogonPass)) {
  468. return apiReturnFail(['web.user.password_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  469. }
  470. }
  471. $newpassword = $request->input('newpassword');
  472. $renewpassword = $request->input('renewpassword');
  473. if (empty($newpassword) || empty($renewpassword)) {
  474. return apiReturnFail(['web.user.password_fail', 'A senha original está errada, digite-a novamente.'], '', 3);
  475. }
  476. if ($newpassword == $renewpassword) {
  477. $user->LogonPass = Hash::make($newpassword);
  478. $user->update(['LogonPass' => $user->LogonPass]);
  479. return response()->json(apiReturnSuc(GlobalUserInfo::toWebData($user), ['user.password.modi_success', 'Redefinição de senha concluída!']));//->withCookie($this->setLoginCookie($user['sign']));
  480. } else {
  481. return apiReturnFail(['web.reg.password_notsame', 'As senhas digitadas duas vezes são inconsistentes, digite novamente!'], '', 2);
  482. }
  483. }
  484. public function modiInsurePassword(Request $request,$checkOldpass=true)
  485. {
  486. $user = $request->globalUser;
  487. if($checkOldpass) {
  488. $oldpassword = $request->input('oldpassword');
  489. if (!empty($user->InsurePass) && !Hash::check($oldpassword, $user->InsurePass)) {
  490. return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  491. }
  492. }
  493. $newpassword = $request->input('newpassword');
  494. $renewpassword = $request->input('renewpassword');
  495. if (empty($newpassword) || empty($renewpassword)) {
  496. return apiReturnFail(['web.user.password_fail', 'A senha original está errada, digite-a novamente.'], '', 3);
  497. }
  498. if ($newpassword == $renewpassword) {
  499. $user->InsurePass = Hash::make($newpassword);
  500. $user->update(['InsurePass' => $user->InsurePass]);
  501. return response()->json(apiReturnSuc(GlobalUserInfo::toWebData($user), ['user.password.modi_success', 'Redefinição de senha concluída!']));//->withCookie($this->setLoginCookie($user['sign']));
  502. } else {
  503. return apiReturnFail(['web.reg.paypass_notsame', 'As senhas digitadas duas vezes são inconsistentes, digite novamente!'], '', 2);
  504. }
  505. }
  506. public function Logout(Request $request)
  507. {
  508. return response()->json(apiReturnSuc('', ['logout.success', 'Você saiu com sucesso.']))->withCookie(self::clearLoginCookie());
  509. }
  510. public static function getPwaBonus(Request $request)
  511. {
  512. $user=$request->user();
  513. $haveBonus=Redis::get('pwa_bonus:'.$user->UserID);
  514. $config = RouteService::getChannelConfig($request);
  515. if($haveBonus&&$config->BONUS_PWA()>0){
  516. [$OrgScore,$NowScore]=OuroGameService::AddFreeScore($user->UserID,$config->BONUS_PWA(),OuroGameService::REASON_PwaBonus,false);
  517. $data=GlobalUserInfo::toWebData($user);
  518. $data['Score']=$NowScore;
  519. Redis::del('pwa_bonus:'.$user->UserID);
  520. if(date('Ymd',strtotime($user->RegisterDate)) == date('Ymd')){
  521. $RecordPlatformDataModel = new \App\Models\RecordPlatformData();
  522. $RecordPlatformDataModel->PwaToday($user->Channel);
  523. }
  524. return response()->json(apiReturnSuc($data, ['user.bonus.pwa_bonus_success', 'Bônus PWA recebido com sucesso!']));
  525. }else{
  526. return response()->json(apiReturnFail(['user.bonus.pwa_bonus_fail', 'Você já recebeu o bônus PWA.',$haveBonus,$config->BONUS_PWA()]));
  527. }
  528. }
  529. private function isSequentialOrRepetitive($phoneNumber)
  530. {
  531. // 移除国家代码和非数字字符
  532. $digits = $phoneNumber;//substr($phoneNumber, 2);
  533. // 检查连号
  534. if (preg_match('/(\d)\1{5,}/', $digits)) { // 改为检测6个或更多连续相同的数字
  535. return true;
  536. }
  537. // 检查顺子,增加检测递增和递减顺子
  538. $ascending = true;
  539. $descending = true;
  540. for ($i = 0; $i < strlen($digits) - 1; $i++) {
  541. if (ord($digits[$i + 1]) - ord($digits[$i]) != 1) {
  542. $ascending = false;
  543. }
  544. if (ord($digits[$i]) - ord($digits[$i + 1]) != 1) {
  545. $descending = false;
  546. }
  547. }
  548. if ($ascending || $descending) {
  549. return true;
  550. }
  551. return false;
  552. }
  553. /**
  554. * @param Request $request
  555. * @return GlobalUserInfo|false
  556. */
  557. public static function checkLogin(Request $request)
  558. {
  559. // $sign=$request->cookie('guuid')??$request->sign;
  560. $sign = $request->sign;
  561. if ($sign) {
  562. try {
  563. $arr = explode('|', Crypt::decryptString($sign));
  564. $globalUID = $arr[0];
  565. $timestamp = intval($arr[1]);
  566. if (time() > $timestamp) return false;
  567. $user = GlobalUserInfo::getGameUserInfo('GlobalUID', $globalUID);
  568. if ($user) {
  569. if ($arr[2] == substr(md5($user->LogonPass), 0, 6)) {
  570. $FPID = $request->input("bfp", "");
  571. if (!empty($FPID)) {
  572. if (empty($user->FPID)) $user->update(['FPID' => $FPID]);
  573. if ($user->LastFPID != $FPID) $user->update(['LastFPID' => $FPID]);
  574. }
  575. if (empty($user->ShortHashID)) {
  576. $ShortHashID = explode('-', $globalUID)[0];
  577. $user->update(['ShortHashID' => $ShortHashID]);
  578. }
  579. GlobalUserInfo::$me = $user;
  580. if (intval($request->input('pwa', 0)) == 1) {
  581. if (intval($user->PwaInstalled) == 0) {
  582. $user->update(['PwaInstalled' => 1]);
  583. //s2s
  584. AfEvent::dispatch([
  585. 'UserID' => $user->UserID,
  586. 'event_name' => 'Lead',
  587. 'custom_data' => [
  588. 'content_name' => 'Install Pwa1',
  589. 'status' => 1,
  590. ],
  591. ]);
  592. $config = RouteService::getChannelConfig($request);
  593. if($config->BONUS_PWA()>0){
  594. Redis::setex('pwa_bonus:'.$user->UserID,86400,1);
  595. }
  596. }
  597. }
  598. return $user;
  599. }
  600. }
  601. } catch (\Exception $e) {
  602. }
  603. }
  604. return false;
  605. }
  606. private function guestLogin($user,$isRegister=false)
  607. {
  608. $qp=QuickAccountPass::query()->where('UserID',$user->UserID)->first();
  609. if(!$qp){
  610. $qp=$this->getGustAccount($user->UserID);
  611. $user->Accounts=$qp['account'];
  612. $user->LogonPass=Hash::make($qp['password']);
  613. $user->save();
  614. }
  615. $user = GlobalUserInfo::toWebData($user,true);
  616. if($isRegister)$user['reg'] = 1;
  617. if($qp){
  618. if(!is_array($qp))$qp=$qp->toArray();
  619. $user['account']=$qp['account'];
  620. $user['password']=$qp['password'];
  621. }
  622. return response()->json(apiReturnSuc($user, ['login.success', 'Login bem-sucedido, bem-vindo de volta!']));
  623. }
  624. public function login(Request $request)
  625. {
  626. $type=$request->input('type','id');
  627. $FPID = $request->input("bfp", "");
  628. $user=null;
  629. $config = RouteService::getChannelConfig($request);
  630. if($type=='guest'){
  631. //游客模式打开,随时可以登录
  632. //$user=GlobalUserInfo::where('FPID',$FPID)->where('Phone','')->where('Email','')->first();
  633. $user=GlobalUserInfo::where('FPID',$FPID)->where('RegionID',$config->isRegionUnique())->first();
  634. if(!$user){
  635. return $this->registerUser($request);
  636. }else{
  637. return $this->guestLogin($user);
  638. }
  639. }
  640. if (!isset($request->account)) {
  641. return apiReturnFail(["web.login.account_empty", 'Por favor insira o nome de usuário!']);
  642. }
  643. if (!isset($request->password)) {
  644. return apiReturnFail(['web.login.password_empty', 'Por favor insira a senha!'], '', 302);
  645. }
  646. $RegisterLocation = $request->country ?? env('COUNTRY_CODE','55');
  647. if (strstr($request->account, '@')) {
  648. $user = GlobalUserInfo::query()->where('RegionID', $config->isRegionUnique())->where("Email", $request->account)->first();
  649. } else if (is_numeric($request->account)) {
  650. $user = GlobalUserInfo::query()->where('RegionID', $config->isRegionUnique())->where("Phone", $RegisterLocation . $request->account)->first();
  651. } else {
  652. $user = GlobalUserInfo::query()->where('RegionID', $config->isRegionUnique())->where("Accounts", $request->account)->first();
  653. }
  654. if ($user) {
  655. if (Hash::check($request->password, $user->LogonPass)) {
  656. $user = GlobalUserInfo::toWebData($user,true);
  657. return response()->json(apiReturnSuc($user, ['login.success', 'Login bem-sucedido, bem-vindo de volta!']));//->withCookie($this->setLoginCookie($user['sign']));
  658. } else {
  659. return apiReturnFail(['web.login.notfound', 'Erro de entrada, tente novamente!'], '', 2);
  660. }
  661. } else {
  662. return apiReturnFail(['web.login.notfound', 'Sua conta não foi encontrada, registre-se ou tente novamente!']);
  663. }
  664. }
  665. private function checkPhone($Phone, $RegisterLocation = '1',Request $request=null)
  666. {
  667. $OrgPhone=$Phone;
  668. // dd($RegisterLocation,$Phone,str_starts_with($Phone,$RegisterLocation),$Phone=explode($RegisterLocation,$Phone));
  669. if(!empty($RegisterLocation)&&str_starts_with($Phone,$RegisterLocation)){
  670. $Phone=$OrgPhone;
  671. }
  672. if (!empty($Phone)) {
  673. // 验证规则
  674. // Remove spaces and dashes from the input
  675. $Phone = str_replace(['-', ' '], '', $Phone);
  676. // Check if the number has 11 digits and the third character is 9
  677. if ($RegisterLocation == env('COUNTRY_CODE','1')) {
  678. // if (!preg_match('/^\d{2}9\d{8}$/', $Phone)) {
  679. // return apiReturnFail(['web.user.phone_fail', 'Not correct phone number'], '', 422);
  680. // }
  681. }
  682. if ($this->isSequentialOrRepetitive($Phone)) {
  683. return apiReturnFail(['web.user.phone_fail', 'Not correct phone number'], '', 422);
  684. }
  685. // if(!str_starts_with($Phone,$RegisterLocation)) {
  686. // $Phone = $RegisterLocation . $Phone;
  687. // }
  688. }
  689. if (!empty($Phone)) {
  690. $config = RouteService::getChannelConfig($request);
  691. $isExist = GlobalUserInfo::query()
  692. ->where('RegionID', $config->isRegionUnique())
  693. ->where(function ($query) use ($Phone, $OrgPhone) {
  694. $query->where("Phone", $Phone)->orWhere('Accounts', $OrgPhone);
  695. })
  696. ->first();
  697. //账户查重
  698. if ($isExist) {
  699. if ($request&&Hash::check($request->password, $isExist->LogonPass)) {
  700. return $isExist;
  701. }
  702. return apiReturnFail(['web.reg.fail_phone_exist', 'O número de telefone já existe, altere-o e tente se cadastrar novamente!']);
  703. }
  704. }
  705. return $Phone;
  706. }
  707. public function createGuestAccounts()
  708. {
  709. $accs=[];
  710. for($i=0;$i<100;$i++) {
  711. $acc = $this->makeGuestAccount();
  712. while(QuickAccountPassStore::where("account", $acc['account'])->exists()) {
  713. $acc = $this->makeGuestAccount();
  714. }
  715. QuickAccountPassStore::create($acc);
  716. $accs[]=$acc;
  717. }
  718. return ['accs'=>$accs];
  719. }
  720. public function getGustAccount($UserID)
  721. {
  722. $acc=QuickAccountPass::whereNull('UserID')->first();
  723. if(!$acc){
  724. $res=$this->createGuestAccounts();
  725. $accs=$res['accs'];
  726. if($accs){
  727. QuickAccountPass::insert($accs);
  728. }
  729. $acc=QuickAccountPass::query()->whereNull('UserID')->first();
  730. }
  731. if($acc){
  732. $acc->update(['UserID' => $UserID]);
  733. }
  734. return $acc->toArray();
  735. }
  736. public function makeGuestAccount()
  737. {
  738. // 词库
  739. $words = ["sun", "moon", "star", "sky", "wind", "fire", "water", "earth","apple","banana","cherry","date","elderberry","fig","grape","honeydew","kiwi","lemon","mango","nectarine","orange","peach","pear","plum","quince","raspberry","strawberry","tangerine","ugli","vanilla","watermelon","xylophone","yam","zucchini","airplane","balloon","camera","drum","eagle","flag","guitar","hat","iceberg","jacket","kite","lamp","mountain","notebook","octopus","penguin","quilt","robot","sunflower","train","umbrella","vase","whale","yacht","zebra","actor","bicycle","carrot","dolphin","elephant","fountain","grape","honey","internet","jungle","koala","lemonade","moose","ninja","octopus","puzzle","quasar","rocket","sunset","trampoline","unicorn","violin","whale","xylophone","yellow","zebra","adventure","bubble","cactus","daisy","envelope","feather","gorilla","horizon","jellyfish","kitchen","lighthouse","mushroom","notebook","orchestra","penguin","quilt","river","snowflake","telescope","universe","vortex","whisper","xenon","yoga","zebra","airport","beach","cucumber","dolphin","eggplant","fishing","grapevine","hiking","jelly","keyboard","lunar","monkey","northern","ocean","pebble","question","robot","scarf","thunder","underwear","vivid","windmill","xylophone","yogurt","zoo","amethyst","butterfly","cloud","dream","emerald","frost","garden","harmony","island","jigsaw","kaleidoscope","lily","melody","nectar","obsidian","parrot","quilt","rainbow","storm","twilight","vortex","whistle","xenon","yarn","zeppelin","antelope","bridge","cobweb","diamond","energy","feather","giraffe","horizon","icicle","jungle","kettle","lemonade","morning","nightfall","octagon","peacock","quasar","riddle","snowman","tulip","unicorn","violet","wonder","xenon","yellow","zodiac","albatross","bamboo","carpet","dandelion","echo","flamingo","galaxy","honeycomb","illusion","jellybean","knight","lighthouse","moonlight","ninja","orchestra","penguin","quill","robot","sunrise","tiger","umbrella","vampire","wisteria","xylophone","yawn","zebra","acrobat","beetle","coral","dusk","elm","frost","grace","horizon","igloo","jacket","kite","lamb","meadow","nail","owl","prism","quince","raven","sand","telescope","universe","vacuum","waterfall","xylophone","yacht","zenith","alphabet","breeze","crystal","dawn","eagle","festival","glow","horizon","ivory","jewel","knob","lemon","magnet","noon","oak","path","quest","rose","skyline","trail","umbrella","vortex","wave","xylophone","yellow","zephyr","abstract","beetle","cherry","dolphin","enigma","flame","giraffe","horizon","ink","jewel","kaleidoscope","lily","matrix","neptune","oasis","puzzle","quartz","rain","snowflake","tulip","ufo","vortex","whale","xylophone","yarn","zeppelin","apple","amazon","google","microsoft","facebook","twitter","netflix","sony","samsung","intel","nike","adidas","coca-cola","pepsi","oracle","ibm","hp","dell","nvidia","twitter","afghanistan","brazil","canada","denmark","egypt","france","germany","hungary","india","japan","kenya","luxembourg","morocco","nigeria","oman","portugal","qatar","russia","spain","turkey","ukraine","vietnam","albert","isaac","marie","charles","nelson","martin","george","abraham","leo","vincent","john","michael","james","robert","david","mary","jennifer","linda","patricia","susan"];
  740. $numbers = range(0, 999);
  741. // 生成账号和密码
  742. $word1 = $words[array_rand($words)];
  743. // $word2 = $words[array_rand($words)];
  744. $number = str_pad($numbers[array_rand($numbers)], 2, '0', STR_PAD_LEFT);
  745. $account= $word1 . $number ;
  746. $word = $words[array_rand($words)];
  747. $number = str_pad($numbers[array_rand($numbers)], 2, '0', STR_PAD_LEFT);
  748. $password= $word . $number;
  749. return compact('account', 'password');
  750. }
  751. public function getUserByFPID($FPID)
  752. {
  753. $user=GlobalUserInfo::getGameUserInfo('FPID', $FPID);
  754. return $user;
  755. }
  756. private $maxFpsidLimit=2;
  757. public function registerUser(Request $request, $regByGuest = false)
  758. {
  759. //type=id,phone,sms,mail,guest
  760. $type=$request->input('type',"id");
  761. if (!$regByGuest&&$type!='guest') {
  762. if (!isset($request->email) && !isset($request->phone)&&!isset($request->account)) {
  763. return apiReturnFail(["web.reg.account_empty", 'Por favor insira o nome de usuário!']);
  764. }
  765. if (!isset($request->password) || !isset($request->repassword) || $request->password != $request->repassword) {
  766. return apiReturnFail(['web.reg.password_notsame', 'As senhas digitadas duas vezes são inconsistentes, digite novamente!'], '', 2);
  767. }
  768. }
  769. $FPID = $request->input("bfp", "");
  770. if($type=='sms'){
  771. $verifyRes=$this->LoginByCode($request,true);
  772. //报错
  773. if(is_array($verifyRes))return $verifyRes;
  774. }else{
  775. //把数据卡限制住
  776. // if (GlobalUserInfo::where('FPID',$FPID)->count() > $this->maxFpsidLimit) {
  777. // $allAcc=GlobalUserInfo::where('FPID',$FPID)->get()->toArray();
  778. // $reqs=$request->all();
  779. // Util::WriteLog('maxreg',compact('allAcc','reqs'));
  780. // return apiReturnFail(['web.reg.fail_ipmax', 'Too many register requests!']);
  781. // }
  782. }
  783. if (empty($FPID)) {
  784. return apiReturnFail(['web.reg.fail_phone_exist', 'O número de telefone já existe, altere-o e tente se cadastrar novamente!']);
  785. }
  786. //获取默认配置
  787. $config = RouteService::getChannelConfig($request);
  788. //游客注册检查是否已经注册
  789. if($type=='guest'){
  790. $where = [];
  791. $where[] = ['FPID', $FPID];
  792. $where[] = ['Phone', ''];
  793. $where[] = ['Email', ''];
  794. $where[] = ['RegionID', $config->isRegionUnique()];
  795. $guestUser=GlobalUserInfo::where($where)->first();
  796. if($guestUser){
  797. //存在,直接返回去
  798. return $this->guestLogin($guestUser);
  799. }
  800. }
  801. $login_ip = IpLocation::getRealIp();
  802. $RegisterLocation = $request->country ?? env('COUNTRY_CODE',55);
  803. $ServerRegion = env('REGION_24680','sa-east');
  804. $Language = $request->lang ?? $request->getLocale();
  805. $Phone = $request->phone ?? "";
  806. $Phone = $this->checkPhone($Phone, $RegisterLocation,$request);
  807. //有错误返回
  808. if (is_array($Phone)) {
  809. return $Phone;
  810. }else if(is_object($Phone)&&isset($Phone->GlobalUID)){
  811. //原来就存在,直接返回
  812. $guser = GlobalUserInfo::toWebData($Phone,true);
  813. $guser['reg'] = 1;
  814. return response()->json(apiReturnSuc($guser, ['reg.success', 'Registro realizado com sucesso!']));
  815. }
  816. if (isset($request->email) && strstr($request->email, '@')) {
  817. $isExist = GlobalUserInfo::query()->where("Email", $request->email)->exists();
  818. //账户查重
  819. if ($isExist) {
  820. return apiReturnFail(['web.reg.fail_email_exist', 'O e-mail já existe, altere-o e tente se cadastrar novamente!']);
  821. }
  822. }
  823. $redisKey = 'register_' . $FPID;
  824. if (!SetNXLock::getExclusiveLock($redisKey)) {
  825. return apiReturnFail(['web.withdraw.try_again_later', 'Tente novamente mais tarde']);
  826. }
  827. $Channel = 0;
  828. //保持邀请和被邀请的渠道序列统一
  829. $ActCode = $request->input('act');
  830. if(strstr($ActCode,'http')){
  831. $ActCode=explode('http',$ActCode)[0];
  832. }
  833. $ReferrType = 0;
  834. if ($ActCode) {
  835. //使用邀请的Code来保持邀请被邀请的用户注册渠道一致性
  836. $link = AgentLinks::getByCode($ActCode);
  837. if ($link) {
  838. $inviter = AccountsInfo::where('UserID', $link->UserID)->first();
  839. if($inviter&&is_object($inviter)) {
  840. $Channel = $inviter->Channel;
  841. $ReferrType = 2;
  842. }
  843. }
  844. }
  845. if(!$Channel){
  846. //非游客注册
  847. while($config->isGuestOpen()&&!$regByGuest){
  848. RouteService::clearChannelConfig();
  849. $config = RouteService::getChannelConfig($request);
  850. }
  851. $Channel = $config->Channel;
  852. if($Channel!=env('REGION_24680_DEFAULT_CHANNEL',100))$ReferrType = 1;
  853. }else{
  854. //先搜索本地配置
  855. $config = WebChannelConfig::getByChannel($Channel);
  856. }
  857. $Package = $config->PackageName;
  858. if ($config) {
  859. //每小时对齐两个表的包名
  860. if(!Redis::exists('ChannelPackageName'.$Channel)) {
  861. $pack = DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel', $Channel)->select('PackageName')->first();
  862. if ($pack) {
  863. Redis::setex('ChannelPackageName' . $Channel, 3600, $Package);
  864. if ($Package != $pack->PackageName) {
  865. DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel', $Channel)->update(['PackageName' => $Package]);
  866. }
  867. }
  868. }
  869. }
  870. $account= $request->account??$request->email ?? $request->phone ?? $FPID;
  871. //注册到游戏服务器
  872. $user = $this->registerAccountInfo($request, $Package, $Channel,$account);
  873. //返回错误
  874. if (is_array($user) && !isset($user['UserID'])) {
  875. SetNXLock::release($redisKey);
  876. return $user;
  877. }
  878. if (!$user) {
  879. SetNXLock::release($redisKey);
  880. return apiReturnFail(['web.withdraw.try_again_later', 'Pausa de login']);
  881. }
  882. //代理注册,保留号段10000-100000
  883. if($request->input('isagent',0)=='24680'){
  884. $oldid=$user['UserID'];
  885. $newid=AccountsInfo::whereBetween('UserID',[10000,100000])->max('UserID')??10000;
  886. $newid++;
  887. $acc=AccountsInfo::find($oldid);
  888. $newacc=$acc->toArray();
  889. $acc->delete();
  890. $newacc['UserID']=$newid;
  891. $pdo = DB::connection('write')->getPdo();
  892. $pdo->setAttribute(PDO::SQLSRV_ATTR_DIRECT_QUERY, true);
  893. DB::connection('write')->unprepared("set identity_insert QPAccountsDB.dbo.AccountsInfo on;");
  894. DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')->insert($newacc);
  895. DB::connection('write')->unprepared("set identity_insert QPAccountsDB.dbo.AccountsInfo off;");
  896. $pdo->setAttribute(PDO::SQLSRV_ATTR_DIRECT_QUERY, false);
  897. $old=['UserID'=>$oldid];$new=['UserID'=>$newid];
  898. DB::connection('write')->table('QPAccountsDB.dbo.UserAgent')->where($old)->update($new);
  899. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')->where($old)->update($new);
  900. $user['UserID']=$newid;
  901. }
  902. $UserID = $user['UserID'];
  903. $GameID = $user['GameID'];
  904. $password=$request->password;
  905. $globalUserInfo = GlobalUserInfo::getGameUserInfo('UserID', $UserID);
  906. if ($globalUserInfo) {
  907. $GlobalUID = $globalUserInfo->GlobalUID;
  908. } else {
  909. if($type=='guest'){
  910. //改成从中心区获取idpass
  911. $idps=$this->getGustAccount($UserID);
  912. $account=$idps['account'];
  913. $password=$idps['password'];
  914. }
  915. $GlobalUID = $this->generateUUID($UserID, $RegisterLocation, $ServerRegion,$Channel??99);
  916. $ShortHashID = explode('-', $GlobalUID)[0];
  917. //先搞定userid
  918. $globalUserInfo = new GlobalUserInfo([
  919. 'UserID' => $UserID,
  920. 'GameID' => $GameID,
  921. 'FF' => $request->input('ff', ''),
  922. 'FPID' => $FPID,
  923. 'LastFPID' => $FPID,
  924. 'ShortHashID' => $ShortHashID,
  925. 'GlobalUID' => $GlobalUID,
  926. 'Accounts' => $account, // Assuming email is received from request
  927. 'Email' => $request->email ?? '', // Assuming email is received from request
  928. 'Phone' => $Phone, // Assuming email is received from request
  929. 'LogonPass' => Hash::make($password),
  930. 'LogonIP' => $login_ip,
  931. 'Gender' => 1,
  932. 'RegisterIP' => $login_ip,
  933. 'RegisterLocation' => $RegisterLocation,
  934. 'ServerRegion' => $ServerRegion,
  935. 'DefaultLanguage' => $Language,
  936. 'Channel' => $Channel??99,
  937. 'RegionID' => $config->isRegionUnique(),
  938. 'ReferrType' => $ReferrType,
  939. 'RegisterDate' => date('Y-m-d H:i:s'),
  940. 'InsurePass' => '',
  941. 'UserRight' => 0,
  942. 'Level' => 0,
  943. 'Exp' => 0,
  944. 'FaceID' => $user['FaceID'],
  945. 'NickName' => $user['NickName'],
  946. 'Registed' =>1,
  947. 'PwaInstalled' =>$request->input('pwa',0),
  948. // 'InsurePass' => Hash::make($request->insurePassword),
  949. // Add other fields as needed
  950. ]);
  951. try {
  952. $globalUserInfo->save();
  953. } catch (\Exception $exception) {
  954. Log::error($exception->getMessage());
  955. }
  956. }
  957. GlobalUserInfo::$me=$globalUserInfo;
  958. if($Channel==env('REGION_24680_DEFAULT_CHANNEL',100)){
  959. Util::WriteLog('c99',json_encode($_SERVER));
  960. }
  961. //注册钱数要归0
  962. // $newRegGolds=$config->isRegZeroMoneyOpen()?0:$config->BONUS_REG();
  963. // GameScoreInfo::query()->where('UserID', $UserID)->update(['Score'=>$newRegGolds]);
  964. $agentUser = AgentService::SetUserAgent($GlobalUID, $UserID, $ActCode);
  965. SetNXLock::release($redisKey);
  966. if ($regByGuest) {
  967. return GlobalUserInfo::getGameUserInfo("UserID", $UserID);
  968. }
  969. $cookieParam = $request->input('cookie', '');
  970. $fbclid = ApkService::extractFbclid($cookieParam);
  971. ApkService::bindCookie($globalUserInfo, $request->input('s_k', ''), $fbclid, $cookieParam);
  972. $guser = GlobalUserInfo::toWebData($globalUserInfo,true);
  973. // if($agentUser->Higher1ID){
  974. // //获取邀请者信息
  975. // $inviter=AccountsInfo::where('UserID',$agentUser->Higher1ID)->first();
  976. // }
  977. $guser['reg'] = 1;
  978. if($type=='guest'){
  979. $guser['account'] = $account;
  980. $guser['password'] = $password;
  981. }
  982. $defaultGameId = 931;
  983. $recommendGame = '/game/' . $defaultGameId;
  984. // 如果用户信息存在,根据GameID的最后一位数字查询映射关系
  985. if ($guser && isset($guser['GameID'])) {
  986. $gameId = (string)$guser['GameID'];
  987. $lastDigit = (int)substr($gameId, -1); // 获取最后一位数字
  988. // 查询映射关系(带缓存)
  989. $cacheKey = 'game_number_mapping:' . $lastDigit;
  990. $mapping = null;
  991. // 尝试从缓存获取
  992. $cached = Redis::get($cacheKey);
  993. if ($cached !== null) {
  994. $decoded = json_decode($cached, true);
  995. if (is_array($decoded) && !empty($decoded)) {
  996. $mapping = (object)$decoded;
  997. }
  998. }
  999. if(!$mapping){
  1000. $mapping = DB::table('agent.dbo.game_number_mapping')
  1001. ->where('number', $lastDigit)
  1002. ->first();
  1003. Redis::setex($cacheKey, $mapping ? 86400 : 300, json_encode($mapping ?: []));
  1004. }
  1005. if ($mapping && isset($mapping->game_id) && $mapping->game_id) {
  1006. $defaultGameId = $mapping->game_id;
  1007. $recommendGame = '/game/' . $mapping->game_id;
  1008. }
  1009. }
  1010. $guser['recommendGame'] = $recommendGame;
  1011. AccountsInfo::where('UserID', $UserID)->update(['UserMedal' => $defaultGameId ]);
  1012. Util::WriteLog('register_params',[$request,$guser]);
  1013. //s2s上报
  1014. AfEvent::dispatch([
  1015. 'UserID' => $UserID,
  1016. 'event_name' => 'CompleteRegistration',
  1017. 'custom_data' => [
  1018. 'content_name' => 'register_success',
  1019. 'status' => 1,
  1020. ],
  1021. ]);
  1022. if($request->input('pwa',0)){
  1023. AfEvent::dispatch([
  1024. 'UserID' => $UserID,
  1025. 'event_name' => 'Lead',
  1026. 'custom_data' => [
  1027. 'content_name' => 'Install Pwa2',
  1028. 'status' => 1,
  1029. ],
  1030. ]);
  1031. }
  1032. return response()->json(apiReturnSuc($guser, ['reg.success', 'Registro realizado com sucesso!']));//->withCookie($this->setLoginCookie($guser['sign']));
  1033. }
  1034. public function registerUserNew(Request $request, $regByGuest = true)
  1035. {
  1036. //type=id,phone,sms,mail,guest
  1037. $type=$request->input('type',"id");
  1038. $FPID = $request->input("bfp", "");
  1039. if (empty($FPID)) {
  1040. return apiReturnFail(['web.reg.fail_phone_exist', 'O número de telefone já existe, altere-o e tente se cadastrar novamente!']);
  1041. }
  1042. $config = RouteService::getChannelConfig($request);
  1043. $where = [];
  1044. $where[] = ['FPID', $FPID];
  1045. // $where[] = ['Phone', ''];
  1046. // $where[] = ['Email', ''];
  1047. $where[] = ['RegionID', $config->isRegionUnique()];
  1048. $guestUser=GlobalUserInfo::where($where)->first();
  1049. if($guestUser){
  1050. //存在,直接返回去
  1051. return $this->guestLogin($guestUser);
  1052. }
  1053. $login_ip = IpLocation::getRealIp();
  1054. $RegisterLocation = $request->country ?? env('COUNTRY_CODE',1);
  1055. $ServerRegion = env('REGION_24680','sa-east');
  1056. $Language = $request->lang ?? $request->getLocale();
  1057. $redisKey = 'register_' . $FPID;
  1058. if (!SetNXLock::getExclusiveLock($redisKey)) {
  1059. return apiReturnFail(['web.withdraw.try_again_later', 'Tente novamente mais tarde']);
  1060. }
  1061. $Channel = 0;
  1062. //保持邀请和被邀请的渠道序列统一
  1063. $ActCode = $request->input('act');
  1064. if(strstr($ActCode,'http')){
  1065. $ActCode=explode('http',$ActCode)[0];
  1066. }
  1067. $Package = 'com.uswin.game777';
  1068. $ReferrType = 0;
  1069. if ($ActCode) {
  1070. //使用邀请的Code来保持邀请被邀请的用户注册渠道一致性
  1071. $link = AgentLinks::getByCode($ActCode);
  1072. if ($link) {
  1073. $inviter = AccountsInfo::where('UserID', $link->UserID)->first();
  1074. if($inviter&&is_object($inviter)) {
  1075. $Channel = $inviter->Channel;
  1076. $ReferrType = 2;
  1077. }
  1078. }
  1079. }
  1080. if(!$Channel){
  1081. //获取默认配置
  1082. // $config = RouteService::getChannelConfig($request);
  1083. //非游客注册
  1084. // while($config->isGuestOpen()&&!$regByGuest){
  1085. // RouteService::clearChannelConfig();
  1086. // $config = RouteService::getChannelConfig($request);
  1087. // }
  1088. $Channel = $config->Channel;
  1089. if($Channel!=env('REGION_24680_DEFAULT_CHANNEL',100))$ReferrType = 1;
  1090. }else{
  1091. //先搜索本地配置
  1092. $config = WebChannelConfig::getByChannel($Channel);
  1093. }
  1094. $Package = $config->PackageName;
  1095. if ($config) {
  1096. //每小时对齐两个表的包名
  1097. if(!Redis::exists('ChannelPackageName'.$Channel)) {
  1098. $pack = DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel', $Channel)->select('PackageName')->first();
  1099. if ($pack) {
  1100. Redis::setex('ChannelPackageName' . $Channel, 3600, $Package);
  1101. if ($Package != $pack->PackageName) {
  1102. DB::table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel', $Channel)->update(['PackageName' => $Package]);
  1103. }
  1104. }
  1105. }
  1106. }
  1107. $account= $request->account??$request->email ?? $request->phone ?? $FPID;
  1108. //注册到游戏服务器
  1109. $user = $this->registerAccountInfo($request, $Package, $Channel,$account);
  1110. //返回错误
  1111. if (is_array($user) && !isset($user['UserID'])) {
  1112. SetNXLock::release($redisKey);
  1113. return $user;
  1114. }
  1115. if (!$user) {
  1116. SetNXLock::release($redisKey);
  1117. return apiReturnFail(['web.withdraw.try_again_later', 'Pausa de login']);
  1118. }
  1119. //代理注册,保留号段10000-100000
  1120. $UserID = $user['UserID'];
  1121. $GameID = $user['GameID'];
  1122. $password=$request->password;
  1123. $globalUserInfo = GlobalUserInfo::getGameUserInfo('UserID', $UserID);
  1124. if ($globalUserInfo) {
  1125. $GlobalUID = $globalUserInfo->GlobalUID;
  1126. } else {
  1127. // if($type=='guest'){
  1128. // //改成从中心区获取idpass
  1129. // $idps=$this->getGustAccount($UserID);
  1130. // $account=$idps['account'];
  1131. // $password=$idps['password'];
  1132. // }
  1133. $GlobalUID = $this->generateUUID($UserID, $RegisterLocation, $ServerRegion,$Channel??99);
  1134. $ShortHashID = explode('-', $GlobalUID)[0];
  1135. //先搞定userid
  1136. $globalUserInfo = new GlobalUserInfo([
  1137. 'UserID' => $UserID,
  1138. 'GameID' => $GameID,
  1139. 'FF' => $request->input('ff', ''),
  1140. 'FPID' => $FPID,
  1141. 'LastFPID' => $FPID,
  1142. 'ShortHashID' => $ShortHashID,
  1143. 'GlobalUID' => $GlobalUID,
  1144. 'Accounts' => $account, // Assuming email is received from request
  1145. 'Email' => $request->email ?? '', // Assuming email is received from request
  1146. 'Phone' => '', // Assuming email is received from request
  1147. 'LogonPass' => Hash::make($password),
  1148. 'LogonIP' => $login_ip,
  1149. 'Gender' => 1,
  1150. 'RegisterIP' => $login_ip,
  1151. 'RegisterLocation' => $RegisterLocation,
  1152. 'ServerRegion' => $ServerRegion,
  1153. 'DefaultLanguage' => $Language,
  1154. 'Channel' => $Channel??100,
  1155. 'RegionID' => $config->isRegionUnique(),
  1156. 'ReferrType' => $ReferrType,
  1157. 'RegisterDate' => date('Y-m-d H:i:s'),
  1158. 'InsurePass' => '',
  1159. 'UserRight' => 0,
  1160. 'Level' => 0,
  1161. 'Exp' => 0,
  1162. 'FaceID' => $user['FaceID'],
  1163. 'NickName' => $user['NickName'],
  1164. 'Registed' =>1,
  1165. 'PwaInstalled' =>$request->input('pwa',0),
  1166. // 'InsurePass' => Hash::make($request->insurePassword),
  1167. // Add other fields as needed
  1168. ]);
  1169. try {
  1170. $globalUserInfo->save();
  1171. } catch (\Exception $exception) {
  1172. Log::error($exception->getMessage());
  1173. }
  1174. }
  1175. GlobalUserInfo::$me=$globalUserInfo;
  1176. if($Channel==env('REGION_24680_DEFAULT_CHANNEL',100)){
  1177. Util::WriteLog('c99',json_encode($_SERVER));
  1178. }
  1179. //注册钱数要归0
  1180. // $newRegGolds=$config->isRegZeroMoneyOpen()?0:$config->BONUS_REG();
  1181. // GameScoreInfo::query()->where('UserID', $UserID)->update(['Score'=>$newRegGolds]);
  1182. $agentUser = AgentService::SetUserAgent($GlobalUID, $UserID, $ActCode);
  1183. SetNXLock::release($redisKey);
  1184. // if ($regByGuest) {
  1185. // return GlobalUserInfo::getGameUserInfo("UserID", $UserID);
  1186. // }
  1187. $cookieParam = $request->input('cookie', '');
  1188. $fbclid = ApkService::extractFbclid($cookieParam);
  1189. ApkService::bindCookie($globalUserInfo, $request->input('s_k', ''), $fbclid, $cookieParam);
  1190. $guser = GlobalUserInfo::toWebData($globalUserInfo,true);
  1191. // if($agentUser->Higher1ID){
  1192. // //获取邀请者信息
  1193. // $inviter=AccountsInfo::where('UserID',$agentUser->Higher1ID)->first();
  1194. // }
  1195. $guser['reg'] = 1;
  1196. //
  1197. // if($type=='guest'){
  1198. // $guser['account'] = $account;
  1199. // $guser['password'] = $password;
  1200. // }
  1201. $defaultGameId = 931;
  1202. $recommendGame = '/game/' . $defaultGameId;
  1203. $guser['recommendGame'] = $recommendGame;
  1204. // 如果用户信息存在,根据GameID的最后一位数字查询映射关系
  1205. if ($guser && isset($guser['GameID'])) {
  1206. $gameId = (string)$guser['GameID'];
  1207. $lastDigit = (int)substr($gameId, -1); // 获取最后一位数字
  1208. // 查询映射关系(带缓存)
  1209. $cacheKey = 'game_number_mapping:' . $lastDigit;
  1210. $mapping = null;
  1211. $cacheHit = false;
  1212. // 尝试从缓存获取
  1213. $cached = Redis::get($cacheKey);
  1214. if ($cached !== null) {
  1215. $decoded = json_decode($cached, true);
  1216. // 如果解码成功且不是空数组,说明有数据
  1217. if (is_array($decoded) && !empty($decoded)) {
  1218. $mapping = (object)$decoded; // 转换为对象以保持兼容性
  1219. $cacheHit = true;
  1220. } elseif ($decoded === []) {
  1221. // 空数组表示数据库中没有记录,已缓存,直接跳过查询
  1222. $cacheHit = true;
  1223. $mapping = null;
  1224. }
  1225. }
  1226. // 缓存未命中,查询数据库
  1227. if (!$cacheHit) {
  1228. $mapping = DB::connection('write')
  1229. ->table('agent.dbo.game_number_mapping')
  1230. ->where('number', $lastDigit)
  1231. ->first();
  1232. // 存入缓存,24小时过期
  1233. if ($mapping) {
  1234. Redis::setex($cacheKey, 86400, json_encode($mapping));
  1235. } else {
  1236. // 即使不存在也缓存,避免频繁查询,缓存5分钟
  1237. Redis::setex($cacheKey, 300, json_encode([]));
  1238. }
  1239. }
  1240. if ($mapping && !empty($mapping) && isset($mapping->game_id) && $mapping->game_id) {
  1241. $defaultGameId = $mapping->game_id;
  1242. $recommendGame = '/game/' . $mapping->game_id;
  1243. }
  1244. $guser['recommendGame'] = $recommendGame;
  1245. }
  1246. AccountsInfo::where('UserID', $UserID)->update(['UserMedal' => $defaultGameId ]);
  1247. Util::WriteLog('register_params',[$request,$guser]);
  1248. //s2s上报
  1249. AfEvent::dispatch([
  1250. 'UserID' => $UserID,
  1251. 'event_name' => 'CompleteRegistration',
  1252. 'custom_data' => [
  1253. 'content_name' => 'register_success',
  1254. 'status' => 1,
  1255. ],
  1256. ]);
  1257. if($request->input('pwa',0)){
  1258. AfEvent::dispatch([
  1259. 'UserID' => $UserID,
  1260. 'event_name' => 'Lead',
  1261. 'custom_data' => [
  1262. 'content_name' => 'Install Pwa2',
  1263. 'status' => 1,
  1264. ],
  1265. ]);
  1266. }
  1267. return response()->json(apiReturnSuc($guser, ['reg.success', 'Registro realizado com sucesso!']));//->withCookie($this->setLoginCookie($guser['sign']));
  1268. }
  1269. public function registerAccountInfo(Request $request, $PackageName = 'com.uswin.game777', $Channel = 0,$account=null)
  1270. {
  1271. if (empty($Channel) || !$Channel) $Channel = env('REGION_24680_DEFAULT_CHANNEL',100);
  1272. //防止串行
  1273. $app=DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')->where('Channel', $Channel)->first();
  1274. if($app)$PackageName=$app->PackageName;
  1275. $FPID = $request->input("bfp", "");
  1276. $Accounts = $account??$FPID ?? $request->adid ?? $request->gaaid ?? md5(random_bytes(30));
  1277. $SpreadID = 0;
  1278. $Password = $request->password ?? md5(random_bytes(30));
  1279. $FaceI = mt_rand(1, 16);
  1280. $Gender = $request->gender ?? 0;
  1281. $InsurePass = "";
  1282. $Phone = $request->phone ?? "";
  1283. $ip = $request->header("X_REAL_IP") ?? $request->ip();
  1284. $MachineID = $Accounts;
  1285. $cbType = 1;
  1286. if (!empty($Phone)) {
  1287. $cbType = 2;
  1288. }
  1289. $res = StoredProcedure::ALLRegisterAccounts(
  1290. $Accounts,
  1291. '1',
  1292. $SpreadID,
  1293. $Password,
  1294. $InsurePass,
  1295. $FaceI,
  1296. $Gender,
  1297. 1,
  1298. $Phone,
  1299. $ip,
  1300. $MachineID,
  1301. $cbType,
  1302. $Channel,
  1303. $PackageName
  1304. );
  1305. Log::info('注册结果 ' . json_encode($res));
  1306. $ReturnValue = $res['ReturnValue'] ?? 0;
  1307. if (is_bool($res)) {
  1308. $ReturnValue = 3;
  1309. }
  1310. $message = '';
  1311. if ($ReturnValue > 0) {
  1312. switch ($ReturnValue) {
  1313. case 1: # 注册暂停
  1314. return apiReturnFail(['web.reg.fail_suspend', 'Registro suspenso']);
  1315. break;
  1316. case 2: # 登录暂停
  1317. return apiReturnFail(['web.reg.fail_stoplogin', 'Pausa de login']);
  1318. break;
  1319. case 3: # 登录暂停
  1320. return apiReturnFail(['web.withdraw.try_again_later', 'Pausa de login']);
  1321. break;
  1322. case 201: # accounts已经存在
  1323. case 301:
  1324. case 8: # 帐号已存在,请换另一帐号名字尝试再次注册!
  1325. $exist_user = AccountsInfo::where('Accounts', $Accounts . $Channel)->first();
  1326. if ($exist_user) {
  1327. $isexitGuser = GlobalUserInfo::getGameUserInfo('UserID', $exist_user->UserID);
  1328. if ($isexitGuser) {
  1329. return apiReturnFail(['web.reg.fail_account_exist', 'A conta já existe, altere outro nome de conta e tente se registrar novamente!'],compact('res','Accounts'));
  1330. } else {
  1331. $res = $exist_user;
  1332. }
  1333. } else {
  1334. return apiReturnFail(['web.withdraw.try_again_later', 'Pausa de login']);
  1335. }
  1336. break;
  1337. case 10: # IP最大注册数量
  1338. return apiReturnFail(['web.reg.fail_ipmax', 'Mesmo IP não pode registrar várias contas']);
  1339. break;
  1340. }
  1341. }
  1342. Util::WriteLog('login', $res);
  1343. // $user=AccountsInfo::query()->where("Accounts",$Accounts)->first();
  1344. // Util::WriteLog('login',$user);
  1345. return $res;
  1346. }
  1347. protected function setLoginCookie($encryptedGlobalUID)
  1348. {
  1349. // $encryptedGlobalUID = Crypt::encryptString($GlobalUID);
  1350. $cookie = Cookie::make('guuid', $encryptedGlobalUID, 60 * 24 * 365, "/", null, true, false, false, 'None');
  1351. return $cookie;
  1352. }
  1353. static public function clearLoginCookie()
  1354. {
  1355. $cookie = Cookie::make('guuid', "", -60, "/", null, true, false, false, 'None');
  1356. return $cookie;
  1357. }
  1358. }