LoginController.php 68 KB

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