重写登录

master
ELF 5 years ago
parent 4b5e52de6c
commit 2f209494b9

@ -1,6 +1,10 @@
<?php
namespace Base\Service;
/**
*
* @todo 未完成
*/
class UserService
{
public function isBan($ip, $deviceNum)
@ -146,15 +150,31 @@ class UserService
return null;
}
$userData = [];
if (!$user['device_number']) {
$userData['device_number'] = $deviceNum;
}
$testResource = M('test_resource','tab_')->select(['device_number'])->where("user_id=%s and apply_status=2", $user['id'])->find(); //测试资源(扶持号)
if ($testResource && $user['device_number'] && $deviceNum && $user['device_number'] != $deviceNum) {
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);
}
}
$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);
$data = [];
$data['device_number'] = $unique_code ? $unique_code : '';
$data['last_device_number'] = $user['device_number'];
$data['lock_status'] = 0 ;
$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;
}
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);
}
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 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']);
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);
}
$newloginip_source = json_decode($newloginip_source,true);
$aldloginip_source = json_decode($aldloginip_source,true);
protected function generateToken($userId, $account, $password){
$str = $userId . $account . $password . NOW_TIME . sp_random_string(7);
$token = md5($str);
return $token;
}
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 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;

@ -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", "成功");
}

Loading…
Cancel
Save