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