From 2f209494b97e1bb697953b0bed341456a2830caa Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Sun, 26 Apr 2020 15:34:47 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Base/Service/UserService.php | 132 +++++++++++------- .../Sdk/Controller/UserController.class.php | 2 +- 2 files changed, 83 insertions(+), 51 deletions(-) diff --git a/Application/Base/Service/UserService.php b/Application/Base/Service/UserService.php index dae8545b..66ccabf2 100644 --- a/Application/Base/Service/UserService.php +++ b/Application/Base/Service/UserService.php @@ -1,6 +1,10 @@ select(['device_number'])->where("user_id=%s and apply_status=2", $user['id'])->find(); //测试资源(扶持号) - if ($testResource && $user['device_number'] && $deviceNum && $user['device_number'] != $deviceNum) { - return null; + if ($testResource) { + if ($this->isDeviceError($user, $testResource, $deviceNum)) { + $userData['last_device_number'] = $deviceNum; + $userData['lock_status'] = 0 ; + $this->deviceErrorLog($user, $testResource, $deviceNum); + return null; + } + if ($this->isIpWarning($user, $testResource, $deviceNum)) { + $this->ipWarningLog($user, $testResource, $deviceNum); + } } - $data = []; - $data['device_number'] = $unique_code ? $unique_code : ''; - $data['last_device_number'] = $user['device_number']; - $data['lock_status'] = 0 ; + $userData["id"] = $uid; + $userData["login_time"] = NOW_TIME; + $userData["login_ip"] = $clientIp; + $userData["last_login_ip"] = $clientIp; + $userData["last_device_number"] = $deviceNum; + $userData["token"] = $this->generateToken($uid,$account,$password); + $userToken = 0; if($testResource) { //扶持号 @@ -175,56 +195,68 @@ class UserService } } - protected function sdklogin_device_error($user,$resource,$unique_code){ - $model = M('User','tab_'); - $uid = $user['id']; - $data["id"] = $uid; - $data["device_number"] = $unique_code ? $unique_code : ''; - $data["last_device_number"] = $user['device_number']; - $data["lock_status"] = 0 ; - $model->save($data); - $protect_data['user_id']= $uid; - $protect_data['user_account']= $resource['user_account']; - $protect_data['server_id'] = $resource['server_id']; - $protect_data['server_name']= $resource['server_name']; - $protect_data['game_id']=$resource['game_id']; - $protect_data['game_name']=$resource['game_name']; - $protect_data['nickname']=$resource['role_name']; - $protect_data['promote_id']=$resource['promote_id']; - $protect_data['promote_account']=$resource['promote_account']; - $protect_data['type']=2; - $protect_data['detail']="登录设备号异常,本次异常设备号:".$unique_code.",历史登录设备号:".$user['device_number']; - $protect_data['create_time'] = NOW_TIME; - M('protect_log','tab_')->add($protect_data); + protected function isDeviceError($user, $testResource, $deviceNum) + { + if ($testResource && $user['device_number'] && $deviceNum && $user['device_number'] != $deviceNum) { + return true; + } + return false; } - // 扶持号登录IP异常 - protected function sdklogin_ip_error($user,$resource,$ip){ - $newloginip_source = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$ip); - $aldloginip_source = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$user['login_ip']); - - $newloginip_source = json_decode($newloginip_source,true); - $aldloginip_source = json_decode($aldloginip_source,true); + protected function deviceErrorLog($user, $testResource, $deviceNum){ + $data = []; + $data['user_id'] = $user['id']; + $data['user_account'] = $testResource['user_account']; + $data['server_id'] = $testResource['server_id']; + $data['server_name'] = $testResource['server_name']; + $data['game_id'] = $testResource['game_id']; + $data['game_name'] = $testResource['game_name']; + $data['nickname'] = $testResource['role_name']; + $data['promote_id'] = $testResource['promote_id']; + $data['promote_account'] = $testResource['promote_account']; + $data['type'] = 2; + $data['detail'] = "登录设备号异常,本次异常设备号:" . $deviceNum . ",历史登录设备号:" . $user['device_number']; + $data['create_time'] = NOW_TIME; + M('protect_log','tab_')->add($data); + } - if($newloginip_source['data']['city']!=$aldloginip_source['data']['city']){ //登录城市不一致时触发IP异常 - $uid = $user['id']; - $protect_data['user_id']= $uid; - $protect_data['user_account']= $resource['user_account']; - $protect_data['server_id'] = $resource['server_id']; - $protect_data['server_name']= $resource['server_name']; - $protect_data['game_id']=$resource['game_id']; - $protect_data['game_name']=$resource['game_name']; - $protect_data['nickname']=$resource['role_name']; - $protect_data['promote_id']=$resource['promote_id']; - $protect_data['promote_account']=$resource['promote_account']; - $protect_data['type']=1; - $protect_data['detail']="登录IP异常,本次异常IP:".$ip.",历史登录IP:".$user['login_ip']; - $protect_data['create_time'] = NOW_TIME; - M('protect_log','tab_')->add($protect_data); + protected function isIpWarning($user, $testResource, $deviceNum) + { + $newResult = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$clientIp); + $oldResult = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$user['login_ip']); + $newResult = json_decode($newResult, true); + $oldResult = json_decode($oldResult, true); + if($newResult['data']['city'] != $oldResult['data']['city']) { + return true; } + return false; + } + + // 扶持号登录IP异常 + protected function ipWarningLog($user, $testResource, $clientIp){ + $data = []; + $data['user_id'] = $user['id']; + $data['user_account'] = $testResource['user_account']; + $data['server_id'] = $testResource['server_id']; + $data['server_name'] = $testResource['server_name']; + $data['game_id'] = $testResource['game_id']; + $data['game_name'] = $testResource['game_name']; + $data['nickname'] = $testResource['role_name']; + $data['promote_id'] = $testResource['promote_id']; + $data['promote_account'] =$testResource['promote_account']; + $data['type'] = 1; + $data['detail'] = "登录IP异常,本次异常IP:" . $clientIp . ",历史登录IP:" . $user['login_ip']; + $data['create_time'] = NOW_TIME; + M('protect_log','tab_')->add($data); + } + + protected function generateToken($userId, $account, $password){ + $str = $userId . $account . $password . NOW_TIME . sp_random_string(7); + $token = md5($str); + return $token; } - protected function sdklogin_update($user,$account,$password,$user_fgame_id,$game_id,$game_name,$unique_code='',&$userToken=''){ + protected function sdklogin_update($user, $account, $password, $user_fgame_id, $game_id, $game_name, $unique_code='', &$userToken=''){ $model = M('User','tab_'); $uid = $user['id']; $data["id"] = $uid; diff --git a/Application/Sdk/Controller/UserController.class.php b/Application/Sdk/Controller/UserController.class.php index ea112412..f50c691a 100644 --- a/Application/Sdk/Controller/UserController.class.php +++ b/Application/Sdk/Controller/UserController.class.php @@ -1414,7 +1414,7 @@ class UserController extends BaseController $taskClient = new TaskClient(); $taskClient->post('/game-event/save-role', $params); } catch (\Exception $e) { - // var_dump($e->getMessage()); + $this->set_message(1001, "fail", "上报数据异常"); } $this->set_message(200, "success", "成功"); }