LoginController.php 67 KB

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