LoginController.php 69 KB

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