Login.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. <?php
  2. /**
  3. * api登录控制器
  4. */
  5. namespace app\api\controller\v1;
  6. use app\api\controller\Api;
  7. use app\common\library\IpLimit;
  8. use app\common\logic\Member;
  9. use app\common\model\Members;
  10. use app\common\model\Logininfo;
  11. use app\common\model\Logoutinfo;
  12. use app\common\model\Channel;
  13. use app\common\model\Subaccount;
  14. use app\common\library\JwtToken;
  15. use app\common\library\Sms;
  16. use app\common\service\FkStrategiesService;
  17. use app\service\CommonService;
  18. use app\service\TiktokService;
  19. use think\Db;
  20. use think\Cache;
  21. use app\common\logic\Member as MemberLogic;
  22. use app\common\logic\Coin;
  23. use app\common\model\Setting;
  24. use app\api\library\MemberDevice;
  25. use think\Env;
  26. use think\Exception;
  27. use think\Request;
  28. class Login extends Api
  29. {
  30. protected $membersModel;
  31. protected $noNeedLogin = ['index', 'loginsms', 'loginqq', 'loginweibo', 'third'];
  32. public function _initialize()
  33. {
  34. parent::_initialize();
  35. $this->membersModel = new Members();
  36. }
  37. /**
  38. * 普通用户登录处理
  39. */
  40. public function index()
  41. {
  42. // if (temporary()) {
  43. // $this->jsonResult('', 0, '禁止登录');
  44. // }
  45. $username = $this->input('username'); //用户名
  46. $password = $this->input('password'); //密码
  47. $imeil = trim($this->input('imeil')); //手机imeil码
  48. $gameid = $this->input('gameid'); //游戏ID
  49. $device = $this->input('device'); //设备
  50. $channelId = $this->input('channel_id'); //当前登录的渠道ID
  51. //海外游戏ip限制
  52. if (in_array($gameid, config('haiwai_game_ids'))) {
  53. $res = (new IpLimit())->validateIp(request()->ip(), $username);
  54. if ($res != 1) {
  55. $this->jsonResult('', -110, '国内用户禁止登录');
  56. }
  57. }
  58. if (empty($username)) {
  59. $this->jsonResult('', -100, '用户名不能为空');
  60. } elseif (empty($password)) {
  61. $this->jsonResult('', -100, '密码不能为空');
  62. }
  63. //游戏ID不能为空
  64. if (empty($gameid)) {
  65. $this->jsonResult('', -100, '游戏ID不能为空');
  66. }
  67. if (empty($device)) {
  68. $this->jsonResult('', -100, '没有注册设备来源');
  69. }
  70. if (empty($imeil)) {
  71. $this->jsonResult('', -100, '设备imeil异常');
  72. }
  73. if (empty($channelId)) {
  74. $this->jsonResult('', -100, '渠道不能为空');
  75. }
  76. //判断渠道
  77. $channelInfo = (new Channel)->where(['status' => 1, 'id' => $channelId])->find();
  78. if (!$channelInfo) {
  79. $this->jsonResult('', -120, '当前渠道不存在或已禁用!');
  80. } else if ($channelInfo['level'] <> 3) {
  81. $this->jsonResult('', -120, '非推广员渠道,不能进行推广,请联系客服');
  82. }
  83. if (!$game = model('Common/Game')->where(['id' => $gameid])->find()) {
  84. $this->jsonResult('', -120, '游戏信息不存在');
  85. }
  86. if ($game['cooperation_status'] == 3) {
  87. $this->jsonResult('', -120, '游戏已下架不存在');
  88. }
  89. if ($game['is_login'] == 1) {
  90. // 游戏登录白名单
  91. if(Db::name('cy_game_user_white')->where(['game_id' => $gameid, 'username' => $username])->count() == 0){
  92. $gameInfo = Db::table('cy_gameinfo')->where(['game_id' => $gameid])->field('ban_login_msg')->find();
  93. $ban_login_msg = '当前游戏禁止登录!';
  94. if(!empty($gameInfo['ban_login_msg'])){
  95. $ban_login_msg = $gameInfo['ban_login_msg'];
  96. }
  97. $this->jsonResult('', -120, $ban_login_msg);
  98. }
  99. }
  100. // 渠道禁止判断
  101. if (isFrozenOption($channelId, $gameid, 'member_login')) {
  102. $this->jsonResult('', -120, '您所在渠道已经被禁止登录此游戏!! ');
  103. }
  104. // 封禁仙剑安卓包的主播包登陆
  105. if (!in_array($username, ['zbgzzdaj', 'zbcobpyl'])) {
  106. if ($channelId == 100 && $gameid == 266) {
  107. $this->jsonResult('', -120, '您所在渠道已经被禁止登录此游戏!! ');
  108. }
  109. }
  110. //加密后密码
  111. $password = auth_code($password, "ENCODE", Env::get($this->authKey));
  112. //用户信息
  113. $userinfo = $this->membersModel->where(['username' => $username, 'password' => $password])->find();
  114. if (empty($userinfo)) {
  115. $this->jsonResult('', -120, '账号不存在或者密码不正确');
  116. }
  117. // 账号是否被冻结
  118. if (1 == $userinfo['flag']) {
  119. $this->jsonResult('', -120, '您的账号已被冻结,请联系客服QQ:' . CUSTOMER_SERVICE_QQ);
  120. }
  121. // 子账号是否被冻结
  122. $subaccountInfo = model('Subaccount')->where(['member_id' => $userinfo['id'], 'game_id' => $gameid])->find();
  123. if (1 == $subaccountInfo['flag']) {
  124. $this->jsonResult('', -120, '您的子账号已被冻结,请联系客服QQ:' . CUSTOMER_SERVICE_QQ);
  125. }
  126. //elseif($userinfo['channel_id'] != $channelId){
  127. // $this->jsonResult("",0,"登录渠道号和注册渠道不一致,无法登录");
  128. // }
  129. // $channelId = $userinfo['channel_id'];
  130. // ## 风控策略
  131. $fkData = [
  132. // 'event_type' => 'login', // username
  133. 'username' => $username, // username
  134. 'ip' => request()->ip(), // ip
  135. 'imei' => $imeil, // imei
  136. 'mobile' => $userinfo['mobile'], // 注册手机号
  137. ];
  138. $result = (new FkStrategiesService())->processEvent($fkData); // 登录
  139. if ($result['status']) {
  140. $this->jsonResult('', -120, '您的账号已被风控冻结,请联系客服QQ:' . CUSTOMER_SERVICE_QQ);
  141. }
  142. //用户登录公共部分处理
  143. $this->loginProcess($userinfo, $gameid, $imeil, $device, $channelId);
  144. exit;
  145. }
  146. /**
  147. * 手机验证码登录
  148. */
  149. /*
  150. public function loginSms()
  151. {
  152. $username = $this->input('username'); //用户名
  153. $code = $this->input('sms_code'); //短信验证码
  154. $imeil = $this->input('imeil'); //手机imeil码
  155. $gameid = $this->input('gameid'); //游戏ID
  156. $device = $this->input('device'); //设备
  157. if (empty($username)) {
  158. $this->jsonResult('',0,'用户名不能为空');
  159. }
  160. //游戏ID不能为空
  161. if (empty($gameid)) {
  162. $this->jsonResult('',0,'游戏ID不能为空');
  163. }
  164. if (empty($device)) {
  165. $this->jsonResult('',0,'没有注册设备来源');
  166. }
  167. if (empty($imeil)) {
  168. $this->jsonResult('',0,'设备imeil异常');
  169. }
  170. if($code==''){
  171. $this->jsonResult('',0,'短信验证码不能为空');
  172. }
  173. $sms = new Sms;
  174. $codeResult = $sms->checkCode($username, $code);
  175. if(!$codeResult['status']) {
  176. $this->jsonResult('', 0, $codeResult['msg']);
  177. }
  178. //用户信息
  179. $userinfo = $this->membersModel->where(['username'=>$username])->find();
  180. if(empty($userinfo))
  181. {
  182. $this->jsonResult('',0,'账号不存在');
  183. }
  184. // 判断一下当前账号是否被冻结
  185. elseif(1 == $userinfo['flag']) {
  186. $this->jsonResult('',0,'您的账号已被冻结,请联系客服QQ:'.CUSTOMER_SERVICE_QQ);
  187. }
  188. //用户登录公共部分处理
  189. $this->loginProcess($userinfo, $gameid, $imeil, $device);
  190. exit;
  191. }*/
  192. /**
  193. * QQ第三方登录
  194. */
  195. /*
  196. public function loginQq()
  197. {
  198. $access_token = $this->input('access_token'); //Access Token
  199. $imeil = $this->input('imeil'); //手机imeil码
  200. $gameid = $this->input('gameid'); //游戏ID
  201. $device = $this->input('device'); //设备
  202. if (empty($access_token)) {
  203. $this->jsonResult('',0,'access_token码不能空。');
  204. }
  205. //游戏ID不能为空
  206. if (empty($gameid)) {
  207. $this->jsonResult('',0,'游戏ID不能为空');
  208. }
  209. if (empty($device)) {
  210. $this->jsonResult('',0,'没有注册设备来源');
  211. }
  212. $url="https://graph.qq.com/oauth2.0/me?access_token={$access_token}&unionid=1";
  213. $unioid_content = getCurlContent($url);
  214. $subStr = substr($unioid_content, strpos($unioid_content, "{"));
  215. $subStr = strstr($subStr, "}", true) . "}";
  216. $unioidInfo = json_decode($subStr, true);
  217. if(!isset($unioidInfo['openid']) || !isset($unioidInfo['unionid'])) {
  218. $this->jsonResult('',0,'获取QQ的用户信息失败,请检查Access Token是否有效');
  219. }
  220. else{
  221. $request_url="https://graph.qq.com/user/get_user_info?oauth_consumer_key=".QQ_APPID."&access_token={$access_token}&openid={$unioidInfo['openid']}";
  222. $request_content = http_get($request_url);
  223. $qqInfo = json_decode($request_content, true);
  224. if(empty($qqInfo) || $qqInfo['ret']!=0)
  225. {
  226. $this->jsonResult('',0,'获取QQ的用户信息失败');
  227. }
  228. else{
  229. $qqInfo['unionid'] = $unioidInfo['unionid'];
  230. $qqInfo['qq_openid']= $unioidInfo['openid'];
  231. $qqModel = new MembersQq;
  232. $membersQqInfo = $qqModel->where(['unionid'=>$qqInfo['unionid']])->find();
  233. //注册
  234. if(empty($membersQqInfo))
  235. {
  236. }
  237. //登录
  238. else{
  239. //用户信息
  240. $userinfo = $this->membersModel->where(['id'=>$membersQqInfo['userid']])->find();
  241. //用户登录公共部分处理
  242. $this->loginProcess($userinfo, $gameid, $imeil, $device);
  243. }
  244. }
  245. }
  246. }*/
  247. /**
  248. * 判断是否节假日
  249. */
  250. public function getHoliday($date)
  251. {
  252. try {
  253. $url = "https://tool.bitefu.net/jiari/?d=$date&back=json";
  254. $result = file_get_contents($url);
  255. $result = json_decode($result, true);
  256. if (isset($result[$date]) && $result[$date] == 2) {
  257. return true;
  258. } else {
  259. return false;
  260. }
  261. } catch (\Exception $e) {
  262. return false;
  263. }
  264. }
  265. /**
  266. * 用户登录公共部分处理
  267. *
  268. * @param $userinfo : array 用户信息数组(member表)
  269. * @param $gameid : int 游戏ID
  270. * @param $imeil : string 手机imeil码
  271. * @param $device : int 注册设备来源
  272. * @param $channelId : int 当前登录的渠道ID
  273. *
  274. */
  275. private function loginProcess($userinfo, $gameid, $imeil, $device, $channelId)
  276. {
  277. //判断游戏是否冻结IP或者IMEI
  278. $LoginIp = request()->ip();
  279. $BannedInfo = model('GameBanned')->where(['game_id' => array('in', [0, $gameid]), 'banned_type' => 'ip', 'banned_device' => $LoginIp])->find();
  280. if (!empty($BannedInfo)) {
  281. log_message(json_encode([$userinfo, $gameid, $imeil, $device, $channelId, $LoginIp]), 'log', LOG_PATH . 'login/');
  282. $template = '【封禁提示】IP禁止登录:账号:' . $userinfo['username'] . ' ip:' . $LoginIp;
  283. curlDD($template, Env::get('dingtalk.notice_weelfar_url'), true);
  284. $this->jsonResult('', 0, '您的IP已被禁止登录此游戏! ');
  285. }
  286. if ($imeil) {
  287. $BannedInfo = model('GameBanned')->where(['game_id' => array('in', [0, $gameid]), 'banned_type' => 'imeil', 'banned_device' => $imeil])->find();
  288. if (!empty($BannedInfo)) {
  289. log_message(json_encode([$userinfo, $gameid, $imeil, $device, $channelId]), 'log', LOG_PATH . 'login/');
  290. $template = '【封禁提示】设备登录:账号:' .$userinfo['username'].' imeil:'.$imeil;
  291. curlDD($template, Env::get('dingtalk.notice_weelfar_url'), true);
  292. $this->jsonResult('', 0, '该设备已被禁止登录此游戏! ');
  293. }
  294. }
  295. // 渠道禁止判断
  296. if (isFrozenOption($channelId, $gameid, 'member_login')) {
  297. $this->jsonResult('', 0, '您所在渠道已经被禁止登录此游戏! ');
  298. }
  299. //游戏防沉迷限制
  300. $restrictInfo = model('GameRestrict')->where(['game_id' => $gameid, 'restrict_type' => 'preventhook'])->find();
  301. if ($restrictInfo) {
  302. $isPreventHook = intval($restrictInfo['restrict_status']);
  303. } else {
  304. $settingModel = new Setting;
  305. $isPreventHook = intval($settingModel::getSetting('CHILD_LIMIT'));
  306. }
  307. $subaccountModel = model('Subaccount');
  308. $offline_time = null;
  309. $gameAccountInfo = $subaccountModel->where(['game_id' => $gameid, 'member_id' => $userinfo['id']])->find();
  310. if ($isPreventHook == 2) {
  311. // vendor('authSdk.Authentication', '.class.php');
  312. // $auth = new \Authentication();
  313. // 已实名认证用户做防沉迷判断
  314. $membersTwoInfo = model('MembersTwo')->where(['userid' => $userinfo['id']])->find();
  315. $gameInfo = model('Game')->where(['id' => $gameid])->find();
  316. if ($gameInfo['game_auth_type'] == 1) { //中宣部实名认证
  317. // // 判断其他子账户是否已实名,是的话,使用其他账户的实名信息。
  318. // if(!$gameAccountInfo || !$gameAccountInfo['idcard_num']){
  319. // $shimingInfo = $subaccountModel->where(['member_id' => $userinfo['id'], 'auth_type' => 1, 'auth_status' => 3])->find();
  320. // if($shimingInfo){
  321. // $zxResult = $auth->check(trim($gameInfo['game_bizid']), $gameAccountInfo['member_id'] . '-' . $gameAccountInfo['id'], $shimingInfo['real_name'], $shimingInfo['idcard_num']);
  322. // if($zxResult['errcode'] == 0 && isset($zxResult['data']['result']['pi'])){
  323. // if(!$gameAccountInfo){
  324. // //生成子账号记录
  325. // $gameAccountInfo = $subaccountModel->create([
  326. // 'auth_type' => 1,
  327. // 'real_name' => $shimingInfo['real_name'],
  328. // 'idcard_num' => $shimingInfo['idcard_num'],
  329. // 'auth_status' => 3,
  330. // 'auth_pi' => $zxResult['data']['result']['pi'],
  331. // 'member_id' => $userinfo['id'],
  332. // 'game_id' => $gameid,
  333. // 'createtime' => NOW_TIMESTAMP,
  334. // ]);
  335. // }else{
  336. // $gameAccountInfo->auth_type = 1;
  337. // $gameAccountInfo->real_name = $shimingInfo['real_name'];
  338. // $gameAccountInfo->idcard_num = $shimingInfo['idcard_num'];
  339. // $gameAccountInfo->auth_status = 3;
  340. // $gameAccountInfo->auth_pi = $zxResult['data']['result']['pi'];
  341. // $gameAccountInfo->last_auth_time = time();
  342. // $gameAccountInfo->save();
  343. // }
  344. //
  345. // // 插入玩家历史记录
  346. // Db::table('cy_member_history')->insert([
  347. // 'userid' => $userinfo['id'],
  348. // 'password' => $shimingInfo['real_name'] . ' ' . $shimingInfo['idcard_num'] . ' ' . $shimingInfo['sub_username'],
  349. // 'mobile' => '',
  350. // 'ip' => request()->ip(),
  351. // 'create_time' => time(),
  352. // ]);
  353. // }
  354. // }
  355. // }
  356. if ($gameAccountInfo) {
  357. if ($gameAccountInfo['auth_status'] == 3) {
  358. $membersTwoInfo['realname'] = trim($gameAccountInfo['real_name']);
  359. $membersTwoInfo['idcard'] = trim($gameAccountInfo['idcard_num']);
  360. } else if ($gameAccountInfo['auth_status'] == 1) {
  361. $membersTwoInfo['realname'] = '';
  362. $membersTwoInfo['idcard'] = '';
  363. } else {
  364. $membersTwoInfo['realname'] = '';
  365. $membersTwoInfo['idcard'] = '';
  366. }
  367. } else {
  368. $membersTwoInfo['realname'] = '';
  369. $membersTwoInfo['idcard'] = '';
  370. }
  371. }
  372. if ($membersTwoInfo && !empty($membersTwoInfo['realname']) && !empty($membersTwoInfo['idcard']) && $membersTwoInfo['realname'] <> -1 && $membersTwoInfo['idcard'] <> -1) {
  373. if (!isMeetAgeByIDCard($membersTwoInfo['idcard'], 18, 120)) {
  374. // 节假日
  375. $holiday = $this->getHoliday(date("Ymd"));
  376. if ($holiday) {
  377. if (!(date("H:i") > "20:00" && date("H:i") < "21:00")) {
  378. $this->jsonResult('', 0, '未成年用户,仅可在周五、周六、周日和法定节假日每日20时至21时进行游戏,其他时间均无法进行游戏 ');
  379. } else {
  380. $offline_time = strtotime(date("Y-m-d") . " 21:00");
  381. }
  382. } else {
  383. $date = date("w");
  384. if (in_array($date, [0, 5, 6])) {
  385. if (!(date("H:i") > "20:00" && date("H:i") < "21:00")) {
  386. $this->jsonResult('', 0, '未成年用户,仅可在周五、周六、周日和法定节假日每日20时至21时进行游戏,其他时间均无法进行游戏 ');
  387. } else {
  388. $offline_time = strtotime(date("Y-m-d") . " 21:00");
  389. }
  390. } else {
  391. $this->jsonResult('', 0, '未成年用户,仅可在周五、周六、周日和法定节假日每日20时至21时进行游戏,其他时间均无法进行游戏 ');
  392. }
  393. }
  394. }
  395. }
  396. }
  397. $logininfoModel = new Logininfo();
  398. $member_channel_game_rel = model('MemberChannelGame');
  399. $nowTime = NOW_TIMESTAMP;
  400. /**
  401. * 所属渠道:
  402. * 1. 根据注册的渠道,注册渠道没有则根据客户端传递的;
  403. */
  404. $bandChannelId = $channelId; // 默认客户端传递的渠道
  405. if(!empty($gameAccountInfo['channel_id'])){
  406. $bandChannelId = $gameAccountInfo['channel_id'];
  407. }
  408. /**
  409. * 注册子账户以及所属渠道绑定
  410. * 1. 查询对应 安卓/IOS/H5 其他端游戏绑定的渠道号;
  411. */
  412. $getBandGameId = getBandGameId($gameid);
  413. if($getBandGameId){
  414. $getBandChannelId = Db::table('cy_member_channel_game_rel')->where(['member_id' => $userinfo['id'], 'game_id' => ['in', $getBandGameId]])->order('mcgr_id asc')->value('channel_id');
  415. if (!empty($getBandChannelId)) {
  416. $bandChannelId = $getBandChannelId;
  417. }
  418. }
  419. // 启动事务
  420. Db::startTrans();
  421. try {
  422. // 用户&游戏 绑定数据
  423. $info = $member_channel_game_rel->where(['member_id' => $userinfo['id'], 'game_id' => $gameid])->find();
  424. $userId = $userinfo['id'];
  425. $gameId = $gameid;
  426. // 首次登录-游戏渠道注册
  427. if (empty($info)) {
  428. $info = $member_channel_game_rel->create([
  429. 'member_id' => $userId,
  430. 'channel_id' => $bandChannelId,
  431. 'game_id' => $gameId,
  432. 'mcgr_createtime' => NOW_TIMESTAMP,
  433. 'update_time' => NOW_TIMESTAMP,
  434. 'mcgr_imeil' => $imeil,
  435. 'mcgr_ip' => request()->ip()
  436. ]);
  437. // 插入玩家游戏渠道绑定记录
  438. $channelName = model('Channel')->where(['id' => $bandChannelId])->value('name');
  439. $gameInfo = model('Common/Game')->where(['id' => $gameId])->field('id,name,type')->find();
  440. Db::table('cy_member_history')->insert([
  441. 'userid' => $userId,
  442. 'channel' => $gameInfo['name'] . "," . $channelName,
  443. 'ip' => request()->ip(),
  444. 'create_time' => time()
  445. ]);
  446. // 用于首充发放 (用于首次登录)
  447. // (new Coin())->autoSend($gameId, $bandChannelId, $userId);
  448. } else {
  449. // 更新游戏最后登录时间
  450. $member_channel_game_rel->where(['member_id' => $userId, 'game_id' => $gameId])->update(['update_time' => time()]);
  451. }
  452. //为了兼容旧SDK保存memkey,新SDK没有用到这个值,旧SDK关闭后可以删除该代码
  453. // if (!trim($userinfo['nickname'])) {
  454. // $userNickName = random(3) . $userinfo['id'];
  455. // $this->membersModel->where(['id' => $userinfo['id']])->update(['memkey' => md5($userinfo['username'] . $userinfo['password'] . rand(0, 1000)), 'login_time' => $nowTime, 'nickname' => $userNickName]);
  456. // } else {
  457. // $this->membersModel->where(['id' => $userinfo['id']])->update(['memkey' => md5($userinfo['username'] . $userinfo['password'] . rand(0, 1000)), 'login_time' => $nowTime]);
  458. // }
  459. /**
  460. * 子账户信息
  461. * 1. 有则根据查询;无则创建子账户;
  462. * 2. 关联游戏使用主账户的ID+正式/测试的标识;
  463. */
  464. $sub_username = '';
  465. if(!empty($gameAccountInfo['sub_username'])){
  466. $sub_username = $gameAccountInfo['sub_username'];
  467. $subData = ['update_time' => $nowTime, 'last_imeil' => $imeil];
  468. $subaccountModel->save($subData, ['member_id' => $userinfo['id'], 'game_id' => $gameid ]);
  469. }else {
  470. // 指定的几款游戏 不需要注册,账号从cy_members 取
  471. // $settingModel = new Setting();
  472. // $accountArr = explode(',', $settingModel->getSetting('ANDROID_IOS_ACCOUNT'));
  473. //
  474. // if (in_array($gameid, $accountArr)) {
  475. // $sub_username = $userinfo['username'];
  476. // } elseif ($gameid > 220) {
  477. // $sub_username = $userinfo['id'];
  478. // } else {
  479. // //旧SDK的玩家,绑定关系表有记录时
  480. // if (!empty($info)) {
  481. // $sub_username = $userinfo['username'];
  482. // } //旧SDK的channel_id=0或者默认渠道的玩家
  483. // elseif ($logininfoModel->where(['userid' => $userinfo['id'], 'gameid' => $gameid])->find()) {
  484. // $sub_username = $userinfo['username'];
  485. // } else {
  486. // $sub_username = strtolower(random(20));
  487. // //保证子账号名唯一性
  488. // while ($subaccountModel->field('id')->where(['sub_username' => $sub_username])->find()) {
  489. // $sub_username = strtolower(random(20));
  490. // }
  491. // }
  492. // }
  493. // $sub_username .= '_'.$gameid.Env::get('sdk_mark_type');
  494. $sub_username = $userinfo['id'].'_'.APP_STATUS;
  495. // 正式服指定游戏的userid不能有英文
  496. if(in_array($gameid, [652, 653, 654, 655])){
  497. $sub_username = $userinfo['id'];
  498. }
  499. //生成子账号记录
  500. if (isset($gameAccountInfo['id']) && isset($gameAccountInfo['idcard_num'])) {
  501. $subData = [
  502. 'sub_username' => $sub_username,
  503. 'channel_id' => $bandChannelId,
  504. 'update_time' => $nowTime,
  505. 'last_imeil' => $imeil,
  506. ];
  507. $subaccountModel->save($subData, [
  508. 'member_id' => $userinfo['id'],
  509. 'game_id' => $gameid,
  510. ]);
  511. } else {
  512. $gameAccountInfo = $subaccountModel->create([
  513. 'member_id' => $userinfo['id'],
  514. 'game_id' => $gameid,
  515. 'channel_id' => $bandChannelId,
  516. 'sub_username' => $sub_username,
  517. 'create_time' => $nowTime,
  518. 'update_time' => $nowTime,
  519. 'last_imeil' => $imeil,
  520. ]);
  521. }
  522. }
  523. // 更新常用设备列表
  524. try {
  525. $memberDevice = new MemberDevice();
  526. $memberDevice->addDevice($userinfo['id'], $gameid, $imeil, $device, false, false);
  527. } catch (\Exception $e) {
  528. // 设备记录更新失败不影响登录流程
  529. trace('设备记录更新失败:' . $e->getMessage(), 'error');
  530. }
  531. $logData['sub_id'] = $gameAccountInfo['id'];
  532. $logData['userid'] = $userinfo['id'];
  533. $logData['gameid'] = $gameid;
  534. $logData['imeil'] = $imeil;
  535. $logData['device'] = $device;
  536. $logData['reg_time'] = $userinfo['reg_time'];
  537. $logData['fromflag'] = $userinfo['fromflag'];
  538. $logData['channel_id'] = $bandChannelId;
  539. $logData['login_time'] = $nowTime;
  540. $logData['ip'] = request()->ip();
  541. //登录日志
  542. $logininfoModel->limitInsert($logData);
  543. $platform = ($device == 3 ? 1 : 0);
  544. //收集设备信息
  545. $this->saveDevices($gameid, $imeil, $platform);
  546. $this->membersModel->save(['update_time' => $nowTime, 'login_time' => $nowTime], ['id' => $userinfo['id']]);
  547. // 提交事务
  548. Db::commit();
  549. } catch (\Exception $e) {
  550. // 回滚事务
  551. Db::rollback();
  552. $this->jsonResult('', 0, '登录失败:' . $e->getMessage());
  553. }
  554. // 查询出帐号在用户中心的openid,下面使用openid交互
  555. // $mgMemberInfo = Db::connect('db_config_resource_center')->table('mg_member')->field('mem_openid')->where(['mem_login_name'=>$userinfo['username'],'pl_id'=>2])->find();
  556. // $signStr = "username=".$mgMemberInfo['mem_openid']."&appkey=".$this->appInfo['appkey']."&logintime=".$nowTime;
  557. // $returnData['sign'] = md5($signStr);
  558. // $returnData['memkey'] = md5($mgMemberInfo['mem_openid'].$userinfo['password'].rand(0,1000)); //登录生成用户key
  559. // $returnData['login_time'] = $nowTime;
  560. // $returnData['openid'] = $mgMemberInfo['mem_openid'];
  561. //token的随机码
  562. $token_random = random(8);
  563. $token = auth_code($userinfo['id'] . '|' . $userinfo['username'] . '|' . $gameid . '|' . $sub_username . '|' . $token_random . '|sdk|v3', "ENCODE", Env::get($this->authKey));
  564. // $imeil 做为唯一登录标识
  565. Cache::store('redis')->set($token, $imeil, 60 * 60 * 24 * 15);
  566. // redis中玩家登录安全控制的随机码
  567. Cache::store('redis')->set('token|sdk|' . $userinfo['id'] . '|' . $gameid, $token_random, 60 * 60 * 24 * 15);
  568. //用户推广信息保存
  569. // setChannelId($userinfo['id'], $bandChannelId);
  570. $returnData['token'] = $token;
  571. $returnData['username'] = $userinfo['username']; //主账号名
  572. $returnData['sub_username'] = $sub_username; //子账号名
  573. $returnData['offline_time'] = $offline_time;
  574. // ## JWT:仅版本号大于 v3.6.6 的客户端返回 ##
  575. if (!empty($this->version) && version_compare($this->version, '3.6.8', '>')) {
  576. $jwtKey = trim((string) Env::get('jwt.jwt_key', ''));
  577. $jwtExpTime = (int) Env::get('jwt.exp_time', 0);
  578. $returnData['jwt_token'] = '';
  579. if ($jwtKey === '' || $jwtExpTime <= 0) {
  580. trace('JWT配置缺失或错误,请检查jwt.jwt_key和jwt.exp_time', 'error');
  581. } else {
  582. $jwtIssuedAt = time();
  583. $jwtUserData = [
  584. 'member_id' => $userinfo['id'],
  585. 'username' => $userinfo['username'],
  586. 'game_id' => $gameid,
  587. 'sub_id' => $gameAccountInfo['id'],
  588. 'channel_id' => $bandChannelId,
  589. 'iat' => $jwtIssuedAt,
  590. 'exp' => $jwtIssuedAt + $jwtExpTime,
  591. ];
  592. $returnData['jwt_token'] = JwtToken::encode($jwtUserData, $jwtKey);
  593. }
  594. }
  595. file_put_contents(RUNTIME_PATH . '/register.txt', var_export($returnData, true) . PHP_EOL, FILE_APPEND);
  596. if ($isPreventHook == 2) {
  597. // 已实名认证用户做防沉迷判断
  598. $membersTwoInfo = model('MembersTwo')->where(['userid' => $userinfo['id']])->find();
  599. $gameInfo = model('Game')->where(['id' => $gameid])->find();
  600. if ($gameInfo['game_auth_type'] == 1) { //中宣部实名认证
  601. $gameAccountInfo = model('Subaccount')->where(['game_id' => $gameid, 'member_id' => $userinfo['id']])->find();
  602. if ($gameAccountInfo) {
  603. if ($gameAccountInfo['auth_status'] == 3) {
  604. $membersTwoInfo['realname'] = trim($gameAccountInfo['real_name']);
  605. $membersTwoInfo['idcard'] = trim($gameAccountInfo['idcard_num']);
  606. } else if ($gameAccountInfo['auth_status'] == 1) {
  607. $membersTwoInfo['realname'] = '';
  608. $membersTwoInfo['idcard'] = '';
  609. } else {
  610. $membersTwoInfo['realname'] = '';
  611. $membersTwoInfo['idcard'] = '';
  612. }
  613. } else {
  614. $membersTwoInfo['realname'] = '';
  615. $membersTwoInfo['idcard'] = '';
  616. }
  617. vendor('authSdk.Authentication', '.class.php');
  618. $auth = new \Authentication();
  619. if (!$membersTwoInfo['realname'] || !$membersTwoInfo['idcard']) { //未实名
  620. $result = $auth->loginout(trim($gameInfo['game_bizid']), $token, 1, 2, $imeil);
  621. if ($result['errcode'] == 0) {}
  622. } else { //已实名
  623. $result = $auth->loginout(trim($gameInfo['game_bizid']), $token, 1, 0, $imeil, $gameAccountInfo['auth_pi']);
  624. if ($result['errcode'] == 0) {}
  625. }
  626. }
  627. }
  628. //
  629. // try {
  630. // //2022-10-13 抖音推送
  631. // $extend = [
  632. // 'Oaid' => '',
  633. // 'Idfa' => '',
  634. // 'Androidid' => '',
  635. // 'Imei' => '',
  636. // 'PayAmount' => 0,
  637. // 'Ip' => request()->ip()
  638. // ];
  639. // $tiktokService = new TiktokService();
  640. // $tiktokService->push('tiktok.retention_days', $userinfo['id'], $gameid, $bandChannelId, $extend);
  641. // } catch (Exception $e) {
  642. // $template = '抖音登录推送异常 userid' . $userinfo['id'] . $e->getMessage();
  643. // $ddurl = Env::get('warning_url');
  644. // $result = curlDD($template, $ddurl, true);
  645. // }
  646. $this->jsonResultUnescape($returnData, 1, '登录成功');
  647. }
  648. /**
  649. * 退出登录
  650. *
  651. */
  652. public function logout()
  653. {
  654. $logoutModel = new Logoutinfo();
  655. $username = $this->input('username'); //用户名
  656. $imeil = $this->input('imeil'); //手机imeil码
  657. $gameid = $this->input('gameid'); //游戏ID
  658. $device = $this->input('device'); //设备
  659. if (empty($username)) {
  660. $this->jsonResult('', 0, '用户名不能为空');
  661. }
  662. //游戏ID不能为空
  663. if (empty($gameid)) {
  664. $this->jsonResult('', 0, '游戏ID不能为空');
  665. }
  666. if (empty($device)) {
  667. $this->jsonResult('', 0, '没有注册设备来源');
  668. }
  669. $data = [
  670. 'username' => $username,
  671. 'gameid' => $gameid,
  672. 'imeil' => $imeil,
  673. 'device' => $device,
  674. 'logout_time' => time()
  675. ];
  676. $logoutModel->insert($data);
  677. //用户信息
  678. $userinfo = $this->membersModel->field('id,reg_time,fromflag,flag,nickname')->where(['id' => $this->input('userid')])->find();
  679. if (empty($userinfo)) {
  680. $this->jsonResult('', 0, '账号不存在');
  681. }
  682. session(null);
  683. Cache::store('redis')->rm($this->input('token'));
  684. Cache::store('redis')->rm('token|sdk|' . $this->input['userid'] . '|' . $gameid);
  685. //游戏防沉迷限制
  686. $restrictInfo = model('GameRestrict')->where(['game_id' => $gameid, 'restrict_type' => 'preventhook'])->find();
  687. if ($restrictInfo) {
  688. $isPreventHook = intval($restrictInfo['restrict_status']);
  689. } else {
  690. $settingModel = new Setting;
  691. $isPreventHook = intval($settingModel::getSetting('CHILD_LIMIT'));
  692. }
  693. if ($isPreventHook == 2) {
  694. // 已实名认证用户做防沉迷判断
  695. $membersTwoInfo = model('MembersTwo')->where(['userid' => $userinfo['id']])->find();
  696. $gameInfo = model('Game')->where(['id' => $gameid])->find();
  697. if ($gameInfo['game_auth_type'] == 1) { //中宣部实名认证
  698. $gameAccountInfo = model('Subaccount')->where(['game_id' => $gameid, 'member_id' => $userinfo['id']])->find();
  699. if ($gameAccountInfo) {
  700. if ($gameAccountInfo['auth_status'] == 3) {
  701. $membersTwoInfo['realname'] = trim($gameAccountInfo['real_name']);
  702. $membersTwoInfo['idcard'] = trim($gameAccountInfo['idcard_num']);
  703. } else if ($gameAccountInfo['auth_status'] == 1) {
  704. $membersTwoInfo['realname'] = '';
  705. $membersTwoInfo['idcard'] = '';
  706. } else {
  707. $membersTwoInfo['realname'] = '';
  708. $membersTwoInfo['idcard'] = '';
  709. }
  710. } else {
  711. $membersTwoInfo['realname'] = '';
  712. $membersTwoInfo['idcard'] = '';
  713. }
  714. vendor('authSdk.Authentication', '.class.php');
  715. $auth = new \Authentication();
  716. if (!$membersTwoInfo['realname'] || !$membersTwoInfo['idcard']) { //未实名
  717. $result = $auth->loginout(trim($gameInfo['game_bizid']), $this->input('token'), 0, 2, $imeil);
  718. // var_dump($result);
  719. if ($result['errcode'] == 0) {
  720. }
  721. } else { //已实名
  722. $result = $auth->loginout(trim($gameInfo['game_bizid']), $this->input('token'), 0, 0, $imeil, $gameAccountInfo['auth_pi']);
  723. // var_dump($result);
  724. if ($result['errcode'] == 0) {
  725. }
  726. }
  727. }
  728. }
  729. $this->jsonResult('', 1, '退出成功');
  730. }
  731. /**
  732. * 校验是否登录[自动登录]
  733. */
  734. public function checkToken()
  735. {
  736. if (temporary()) {
  737. $this->jsonResult('', 0, '禁止登录');
  738. }
  739. if (!empty($this->version) && version_compare($this->version, '3.6.8', '>') && $this->input['token_version'] == "") {
  740. $this->jsonResult('', 0, '登录失效,请重新登录!');
  741. }
  742. $channel_id = $this->input('channel_id'); //渠道ID
  743. $gameid = $this->input('gameid'); //游戏ID
  744. $device = $this->input('device'); //设备 (v3.0.2 新增参数)
  745. $imeil = $this->input('imeil');
  746. //海外游戏ip限制
  747. if (in_array($gameid, config('haiwai_game_ids'))) {
  748. $res = (new IpLimit())->validateIp(request()->ip(), $this->input['username']);
  749. if ($res != 1) {
  750. $this->jsonResult('', 0, '国内用户禁止登录');
  751. }
  752. }
  753. if (empty($channel_id)) {
  754. $this->jsonResult('', 0, '渠道ID不能为空');
  755. }
  756. if (!$game = model('Common/Game')->where(['id' => $gameid])->find()) {
  757. $this->jsonResult('', 0, '游戏信息不存在');
  758. }
  759. if ($game['cooperation_status'] == 3) {
  760. $this->jsonResult('', 0, '游戏已下架不存在');
  761. }
  762. if ($game['is_login'] == 1) {
  763. // 游戏登录白名单
  764. if(Db::name('cy_game_user_white')->where(['game_id' => $gameid, 'username' => $this->input['username']])->count() == 0){
  765. $gameInfo = Db::table('cy_gameinfo')->where(['game_id' => $gameid])->field('ban_login_msg')->find();
  766. $ban_login_msg = '当前游戏禁止登录!';
  767. if(!empty($gameInfo['ban_login_msg'])){
  768. $ban_login_msg = $gameInfo['ban_login_msg'];
  769. }
  770. $this->jsonResult('', 0, $ban_login_msg);
  771. }
  772. }
  773. //用户信息
  774. $userinfo = $this->membersModel->field('id,reg_time,fromflag,flag,nickname,channel_id,mobile')->where(['id' => $this->input('userid')])->find();
  775. // 封禁仙剑安卓包的主播包登陆
  776. if(!in_array($this->input['username'], ['zbgzzdaj', 'zbcobpyl'])){
  777. if($channel_id == 100 && $gameid == 266){
  778. $this->jsonResult('', 0, '您所在渠道已经被禁止登录此游戏!! ');
  779. }
  780. }
  781. if (empty($userinfo)) {
  782. $this->jsonResult('', 0, '账号不存在');
  783. } // 判断一下当前账号是否被冻结
  784. elseif (1 == $userinfo['flag']) {
  785. Cache::store('redis')->rm($this->input('token'));
  786. $this->jsonResult('', 0, '您的账号已被冻结,请联系客服QQ:' . CUSTOMER_SERVICE_QQ);
  787. } // 渠道禁止判断
  788. elseif (isFrozenOption($channel_id, $gameid, 'member_login')) {
  789. Cache::store('redis')->rm($this->input('token'));
  790. $this->jsonResult('', 0, '您所在渠道已经被禁止登录此游戏! ');
  791. }
  792. // ## 风控策略(与 index 登录保持一致)
  793. $fkData = [
  794. 'username' => $this->input['username'], // username
  795. 'ip' => request()->ip(), // ip
  796. 'imei' => $imeil, // imei
  797. 'mobile' => $userinfo['mobile'], // 注册手机号
  798. ];
  799. $result = (new FkStrategiesService())->processEvent($fkData); // 登录
  800. if ($result['status']) {
  801. $this->jsonResult('', 0, '您的账号已被风控冻结,请联系客服QQ:' . CUSTOMER_SERVICE_QQ);
  802. }
  803. //判断游戏是否冻结IP或者IMEI
  804. $LoginIp = request()->ip();
  805. $BannedInfo = model('GameBanned')->where(['game_id' => array('in', [0, $gameid]), 'banned_type' => 'ip', 'banned_device' => $LoginIp])->find();
  806. if (!empty($BannedInfo)) {
  807. log_message(json_encode([$userinfo, $gameid, $imeil, $device, $LoginIp]), 'log', LOG_PATH . 'login/');
  808. $template = '【封禁提示】IP禁止登录:账号:' .$userinfo['username'].' ip:'.$LoginIp;
  809. curlDD($template, Env::get('notice_weelfar_url'), true);
  810. $this->jsonResult('', 0, '您的IP已被禁止登录此游戏! ');
  811. }
  812. if ($imeil) {
  813. $BannedInfo = model('GameBanned')->where(['game_id' => array('in', [0, $gameid]), 'banned_type' => 'imeil', 'banned_device' => $imeil])->find();
  814. if (!empty($BannedInfo)) {
  815. log_message(json_encode([$userinfo, $gameid, $imeil, $device]), 'log', LOG_PATH . 'login/');
  816. $template = '【封禁提示】设备登录:账号:' .$userinfo['username'].' imeil:'.$imeil;
  817. curlDD($template, Env::get('notice_weelfar_url'), true);
  818. $this->jsonResult('', 0, '该设备已被禁止登录此游戏! ');
  819. }
  820. }
  821. //游戏防沉迷限制
  822. $restrictInfo = model('GameRestrict')->where(['game_id' => $gameid, 'restrict_type' => 'preventhook'])->find();
  823. if ($restrictInfo) {
  824. $isPreventHook = intval($restrictInfo['restrict_status']);
  825. } else {
  826. $settingModel = new Setting;
  827. $isPreventHook = intval($settingModel::getSetting('CHILD_LIMIT'));
  828. }
  829. $offline_time = null;
  830. if ($isPreventHook == 2) {
  831. // 已实名认证用户做防沉迷判断
  832. $membersTwoInfo = model('MembersTwo')->where(['userid' => $userinfo['id']])->find();
  833. if ($membersTwoInfo && !empty($membersTwoInfo['realname']) && !empty($membersTwoInfo['idcard']) && $membersTwoInfo['realname'] <> -1 && $membersTwoInfo['idcard'] <> -1) {
  834. if (!isMeetAgeByIDCard($membersTwoInfo['idcard'], 18, 120)) {
  835. //if (!(date('H:i') > '08:00' && date('H:i') < '22:00')) {
  836. // $this->jsonResult('', 0, '您未满18周岁,22:00~8:00无法登录 ');
  837. // }
  838. // 节假日
  839. $holiday = $this->getHoliday(date("Ymd"));
  840. if ($holiday) {
  841. if (!(date("H:i") > "20:00" && date("H:i") < "21:00")) {
  842. $this->jsonResult('', 0, '未成年用户,仅可在周五、周六、周日和法定节假日每日20时至21时进行游戏,其他时间均无法进行游戏 ');
  843. } else {
  844. $offline_time = strtotime(date("Y-m-d") . " 21:00");
  845. }
  846. } else {
  847. $date = date("w");
  848. if (in_array($date, [0, 5, 6])) {
  849. if (!(date("H:i") > "20:00" && date("H:i") < "21:00")) {
  850. $this->jsonResult('', 0, '未成年用户,仅可在周五、周六、周日和法定节假日每日20时至21时进行游戏,其他时间均无法进行游戏 ');
  851. } else {
  852. $offline_time = strtotime(date("Y-m-d") . " 21:00");
  853. }
  854. } else {
  855. $this->jsonResult('', 0, '未成年用户,仅可在周五、周六、周日和法定节假日每日20时至21时进行游戏,其他时间均无法进行游戏 ');
  856. }
  857. }
  858. }
  859. }
  860. }
  861. $logininfoModel = new Logininfo();
  862. if (empty($device)) {
  863. $platform = model('Common/GameInfo')->where(['game_id' => $gameid])->value('platform');
  864. if ($platform == 1)
  865. $device = 3; //IOS
  866. elseif ($platform == 0)
  867. $device = 2; //安卓
  868. else
  869. $device = 1; //PC
  870. }
  871. $gameAccountInfo = (new Subaccount())->where(['game_id' => $gameid, 'member_id' => $userinfo['id']])->find();
  872. if (1 == $gameAccountInfo['flag']) {
  873. $this->jsonResult('', -120, '您的子账号已被冻结,请联系客服QQ:' . CUSTOMER_SERVICE_QQ);
  874. }
  875. $logData['sub_id'] = $gameAccountInfo['id'];
  876. $logData['userid'] = $userinfo['id'];
  877. $logData['gameid'] = $gameid;
  878. $logData['imeil'] = $imeil;
  879. $logData['device'] = $device;
  880. $logData['reg_time'] = $userinfo['reg_time'];
  881. $logData['fromflag'] = $userinfo['fromflag'];
  882. $logData['channel_id'] = $gameAccountInfo['channel_id'];
  883. $logData['login_time'] = NOW_TIMESTAMP;
  884. $logData['ip'] = request()->ip();
  885. //登录日志
  886. $logininfoModel->limitInsert($logData);
  887. // 用户推广信息保存
  888. // setChannelId($userinfo['id'], $gameAccountInfo['channel_id']);
  889. //更新最近登录时间
  890. if (!trim($userinfo['nickname'])) {
  891. $userNickName = random(3) . $userinfo['id'];
  892. $this->membersModel->where(['id' => $userinfo['id']])->update(['login_time' => NOW_TIMESTAMP, 'nickname' => $userNickName]);
  893. } else {
  894. $this->membersModel->where(['id' => $userinfo['id']])->update(['login_time' => NOW_TIMESTAMP]);
  895. }
  896. // 更新子账户时间
  897. (new Subaccount())->where(['game_id' => $gameid, 'member_id' => $userinfo['id']])->update(['update_time' => NOW_TIMESTAMP]);
  898. $this->jsonResult(['is_login' => 1, "offline_time" => $offline_time], 1, '有效token');
  899. }
  900. /**
  901. * 普通用户登录处理
  902. */
  903. public function third()
  904. {
  905. // if (temporary()) {
  906. // $this->jsonResult('', 0, '禁止登录');
  907. // }
  908. $username = $this->input('username'); //用户名
  909. $imeil = trim($this->input('imeil')); //手机imeil码
  910. $gameid = $this->input('gameid'); //游戏ID
  911. $device = $this->input('device'); //设备
  912. $channelId = $this->input('channel_id'); //当前登录的渠道ID
  913. $type_id = $this->input('type_id'); // 当前登录的渠道ID:1=微信, 2=qq, 3=抖音
  914. $oaid = $this->input('oaid', '');
  915. $dy_channel_id = $this->input('dy_channel_id', 0);
  916. // log_message(json_encode(input()), 'log', LOG_PATH . 'third/');
  917. //海外游戏ip限制
  918. if (in_array($gameid, config('haiwai_game_ids'))) {
  919. $res = (new IpLimit())->validateIp(request()->ip(), $username);
  920. if ($res != 1) {
  921. $this->jsonResult('', 0, '国内用户禁止登录');
  922. }
  923. }
  924. if (empty($username)) {
  925. $this->jsonResult('', 0, '用户名不能为空');
  926. }
  927. //游戏ID不能为空
  928. if (empty($gameid)) {
  929. $this->jsonResult('', 0, '游戏ID不能为空');
  930. }
  931. if (empty($device)) {
  932. $this->jsonResult('', 0, '没有注册设备来源');
  933. }
  934. if (empty($imeil)) {
  935. $this->jsonResult('', 0, '设备imeil异常');
  936. }
  937. if (empty($channelId)) {
  938. $this->jsonResult('', 0, '渠道不能为空');
  939. }
  940. //判断渠道
  941. $channelInfo = (new Channel)->where(['status' => 1, 'id' => $channelId])->find();
  942. if (!$channelInfo) {
  943. $this->jsonResult('', 0, '渠道信息不存在');
  944. } else if ($channelInfo['level'] <> 3) {
  945. $this->jsonResult('', 0, '非推广员渠道,不能进行推广,请联系客服');
  946. }
  947. if (!$game = model('Common/Game')->where(['id' => $gameid])->find()) {
  948. $this->jsonResult('', 0, '游戏信息不存在');
  949. }
  950. if ($game['cooperation_status'] == 3) {
  951. $this->jsonResult('', 0, '游戏已下架不存在');
  952. }
  953. // 渠道禁止判断
  954. if (isFrozenOption($channelId, $gameid, 'member_login')) {
  955. $this->jsonResult('', 0, '您所在渠道已经被禁止登录此游戏!! ');
  956. }
  957. $fromflag = 1;
  958. if (!in_array($type_id, [1, 2, 3])) {
  959. $this->jsonResult('', 0, '请求类型有误!');
  960. }
  961. if ($type_id == 1) { // 微信
  962. $userinfo = $this->membersModel->where(['wx_uid' => $username])->find();
  963. } else if ($type_id == 2) { // qq
  964. $userinfo = $this->membersModel->where(['wx_uid' => $username])->find();
  965. } else if ($type_id == 3) { // 抖音
  966. $userinfo = $this->membersModel->where(['dy_uid' => $username])->find();
  967. $fromflag = 3;
  968. }
  969. if ($userinfo) {
  970. if (1 == $userinfo['flag']) {
  971. $this->jsonResult('', 0, '您的账号已被冻结,请联系客服QQ:' . CUSTOMER_SERVICE_QQ);
  972. }
  973. $channelId = $userinfo['channel_id'];
  974. //用户登录公共部分处理
  975. $this->loginProcess($userinfo, $gameid, $imeil, $device, $channelId);
  976. } else {
  977. $username_third = strtolower(random(11));
  978. while ($this->membersModel->field('id')->where(['username' => $username_third])->find()) {
  979. $username_third = strtolower(random(11));
  980. }
  981. $data = [
  982. 'username' => $username_third,
  983. 'password' => auth_code('a12345fewdcv2', "ENCODE", Env::get($this->aesKey)),
  984. 'device' => $this->input('device'),
  985. 'gameid' => $gameid,
  986. 'imeil' => $imeil,
  987. 'channel_id' => $this->input('channel_id'),
  988. 'deviceinfo' => $this->input('deviceinfo'),
  989. 'mobile' => '',
  990. 'is_local' => 0,
  991. 'reg_time' => time(),
  992. 'login_time' => time(),
  993. 'ip' => request()->ip(),
  994. 'nickname' => random(8),
  995. 'fromflag' => $fromflag
  996. ];
  997. if ($type_id == 1) { // 微信
  998. $data['wx_uid'] = $username;
  999. } else if ($type_id == 2) { // qq
  1000. $data['qq_uid'] = $username;
  1001. } else if ($type_id == 3) { // 微信
  1002. $data['dy_uid'] = $username;
  1003. }
  1004. // 启动事务
  1005. Db::startTrans();
  1006. try {
  1007. $member_id = $this->membersModel->insertGetId($data);
  1008. if ($member_id) {
  1009. // 插入玩家历史记录
  1010. Db::table('cy_member_history')->insert([
  1011. 'userid' => $member_id,
  1012. 'password' => $data['password'],
  1013. 'mobile' => $data['mobile'],
  1014. 'ip' => request()->ip(),
  1015. 'create_time' => time()
  1016. ]);
  1017. $realname = '';
  1018. $idcard = '';
  1019. //插入用户扩展记录
  1020. Db::table('cy_memberstwo')->insert([
  1021. 'userid' => $member_id,
  1022. 'username' => $data['username'],
  1023. 'realname' => $realname,
  1024. 'idcard' => $idcard,
  1025. 'create_time' => time()
  1026. ]);
  1027. //绑定抖音channel 和 平台内的channel
  1028. // $dy_channel_info = Db::table("mw_dy_channel_rel")
  1029. // ->where("channel_id", $data['channel_id'])
  1030. // ->where("dy_channel_id", $dy_channel_id)->find();
  1031. // if (empty($dy_channel_info)) {
  1032. // $dy_channel_rel = [
  1033. // 'channel_id' => $data['channel_id'],
  1034. // 'dy_channel_id' => $dy_channel_id,
  1035. // 'create_time' => NOW_TIMESTAMP,
  1036. // 'update_time' => NOW_TIMESTAMP,
  1037. // ];
  1038. // Db::table("mw_dy_channel_rel")->insert($dy_channel_rel);
  1039. // }
  1040. // 提交事务
  1041. Db::commit();
  1042. // 登录处理
  1043. $this->loginProcess(array_merge($data, ['id' => $member_id, 'gameid' => $gameid, 'oaid' => $oaid]), $gameid, $imeil, $device, $channelId);
  1044. } else {
  1045. throw new Exception("注册失败!");
  1046. }
  1047. } catch (\Exception $e) {
  1048. // 回滚事务
  1049. Db::rollback();
  1050. $this->jsonResult('', 0, '注册失败!' . $e->getMessage());
  1051. }
  1052. }
  1053. exit;
  1054. }
  1055. }