LoginController.php 71 KB

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