|
|
@ -1,198 +1,148 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
namespace Base\Service;
|
|
|
|
namespace Base\Service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Base\Tool\TaskClient;
|
|
|
|
|
|
|
|
use Think\Log;
|
|
|
|
|
|
|
|
use Base\Tool\Redis;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @todo 未完成
|
|
|
|
* @todo 未完成
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class UserService
|
|
|
|
class UserService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public function isBan($ip, $deviceNum)
|
|
|
|
public function loginSdk($params)
|
|
|
|
{
|
|
|
|
|
|
|
|
$ban = M('device_bans','tab_')->select(['id'])->where(['tag' => ['in', [$ip, $deviceNum]]])->limit(1)->find();
|
|
|
|
|
|
|
|
if (empty($ban)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function login()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
|
|
|
|
if ($this->loginLimit($params)) {
|
|
|
|
$user = json_decode(base64_decode(file_get_contents("php://input")), true);
|
|
|
|
$this->resetLoginLimit();
|
|
|
|
#判断数据是否为空
|
|
|
|
return ['status' => false, 'message' => '登录人数过多,请稍后再试'];
|
|
|
|
if (empty($user)) {
|
|
|
|
|
|
|
|
$this -> set_message(1001, "fail", "登录数据不能为空");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$account = $params['account'] ?? '';
|
|
|
|
$account = $params['account'];
|
|
|
|
$password = $params['password'] ?? '';
|
|
|
|
$password = $params['password'];
|
|
|
|
$gameId = $params['game_id'] ?? 0;
|
|
|
|
$gameId = $params['game_id'];
|
|
|
|
|
|
|
|
$sdkVersion = $params['sdk_version'];
|
|
|
|
$sdkVersion = $params['sdk_version'];
|
|
|
|
$deviceNum = $params['unique_code'];
|
|
|
|
$deviceNum = $params['unique_code'] ?? '';
|
|
|
|
|
|
|
|
$clientIp = get_client_ip();
|
|
|
|
$ip = get_client_ip();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->isBan($ip, $user['unique_code'])) {
|
|
|
|
|
|
|
|
$this->set_message(1004, "fail", "设备已被禁用");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$game = M('game', 'tab_')->where(['game_id' => $gameId])->find();
|
|
|
|
$game = M('game', 'tab_')->where(['game_id' => $gameId])->find();
|
|
|
|
$user = M('user', 'tab_')->where(['account' => $account])->find();
|
|
|
|
$result = $this->doLogin($account, $password, $game, ['client_ip' => $clientIp, 'device_num' => $deviceNum]);
|
|
|
|
if (empty($user)) {
|
|
|
|
if (!$result['status']) {
|
|
|
|
$this->set_message(1005, "fail", "账号或密码错误");
|
|
|
|
$this->resetLoginLimit();
|
|
|
|
|
|
|
|
return ['status' => false, 'message' => $result['message']];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = $result['data']['user'];
|
|
|
|
|
|
|
|
|
|
|
|
$userApi = new MemberApi();
|
|
|
|
$noticeCount = $this->getNoticeCount();
|
|
|
|
$result = $userApi->login_sdk($account, $password, 1, $gameId, $game['game_name'], $sdkVersion, $deviceNum);
|
|
|
|
$this->addUserPlay($user, $game, $clientIp);
|
|
|
|
|
|
|
|
|
|
|
|
$res_msg = array();
|
|
|
|
$response = [
|
|
|
|
switch ($result) {
|
|
|
|
'status' => 200,
|
|
|
|
|
|
|
|
'return_code' => 'success',
|
|
|
|
case - 1:
|
|
|
|
'return_msg' => '登录成功',
|
|
|
|
// $log['remarks'] = '扶持号被禁用';
|
|
|
|
'user_id' => $user['id'],
|
|
|
|
// log_action($log);
|
|
|
|
'account' => $user['account'],
|
|
|
|
$this -> set_message(1005, "fail", "密码错误");
|
|
|
|
'nickname' => $user['nickname'] ? $user['nickname'] : $user['account'],
|
|
|
|
break;
|
|
|
|
'sex' => $user['sex'] ? $user['sex'] : 0,
|
|
|
|
case - 2:
|
|
|
|
'is_platform' => $user['is_platform'],
|
|
|
|
// $log['remarks'] = '密码错误';
|
|
|
|
'token' => $result['data']['token'],
|
|
|
|
// log_action($log);
|
|
|
|
'user_token' => $result['data']['user_token'],
|
|
|
|
$this -> set_message(1005, "fail", "密码错误");
|
|
|
|
'OTP_token' => think_encrypt(json_encode(array('uid' => $user['id'], 'time' => time())), 1),
|
|
|
|
break;
|
|
|
|
'is_uc' => 0,
|
|
|
|
default:
|
|
|
|
'is_open_small_account' => C('IS_OPEN_SMALL_ACCOUNT'),
|
|
|
|
if (is_array($result)) {
|
|
|
|
'url' => 'http://' . str_replace(array('http://'), '', C('WEB_SITE')) . '/mobile.php',
|
|
|
|
$user["user_id"] = $result['user_id'];
|
|
|
|
'small_list' => [],
|
|
|
|
$user['puid'] = 0;
|
|
|
|
'ios_packagename' => C('WEB_IOS_PACKAGENAME'),
|
|
|
|
$this -> add_user_play($user);
|
|
|
|
'android_packagename' => C('WEB_AND_PACKAGENAME'),
|
|
|
|
$platform = $this -> get_platform($user['user_id']);
|
|
|
|
'site_status' => C('SDK_SITE_STATUS'),
|
|
|
|
$small_list = $this -> small_list($user['user_id'], $user['game_id']);
|
|
|
|
'head_img' => !empty($user['head_img']) ? $user['head_img'] : '',
|
|
|
|
$small_list[] = array('is_platform' => $platform, 'user_id' => $user['user_id'], 'account' => $user['account'], 'user_account' => $user['account']);
|
|
|
|
'unread_count' => $noticeCount,
|
|
|
|
$user_res = M('User', 'tab_') -> where(['account' => $user['account']]) -> find();
|
|
|
|
'notice_count' => $noticeCount,
|
|
|
|
$unread_count = 0;
|
|
|
|
'request_count' => 0,
|
|
|
|
$time = time();
|
|
|
|
];
|
|
|
|
$notice = M('notice', 'tab_')->where('start_time < ' . $time . ' AND game_id = ' . $user['game_id']. ' AND (end_time = 0 OR end_time >' . $time . ')')->getField('id',true);
|
|
|
|
|
|
|
|
if(!empty($notice))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$unread_count += count($notice);
|
|
|
|
|
|
|
|
$where['notice_id'] = ['in', implode(',', $notice)];
|
|
|
|
|
|
|
|
$where['user_id'] = $user['user_id'];
|
|
|
|
|
|
|
|
$where['is_read'] = 1;
|
|
|
|
|
|
|
|
$notice_read_count = M('notice_read', 'tab_')->where($where)->count();
|
|
|
|
|
|
|
|
$unread_count -= $notice_read_count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$unread_count += M('share_record', 'tab_') -> where(['invite_id' => $user['user_id'], 'award_coin' => ['gt', 0], 'read' => 0]) -> count();
|
|
|
|
|
|
|
|
$unread_count += M('point_record', 'tab_') -> where(['type_id' => 6, 'user_id' => $user['user_id'], 'point' => ['gt', 0], 'read' => 0]) -> count();
|
|
|
|
|
|
|
|
$notice_count = $unread_count;
|
|
|
|
|
|
|
|
$buddies_request = get_buddies_unagree_count($user['user_id']);
|
|
|
|
|
|
|
|
$unread_count += $buddies_request;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userToken = $result['user_token'];
|
|
|
|
|
|
|
|
$res_msg = array(
|
|
|
|
|
|
|
|
"status" => 200,
|
|
|
|
|
|
|
|
"return_code" => "success",
|
|
|
|
|
|
|
|
"return_msg" => "登录成功",
|
|
|
|
|
|
|
|
"user_id" => $user["user_id"],
|
|
|
|
|
|
|
|
"account" => $user["account"],
|
|
|
|
|
|
|
|
"nickname" => $user_res["nickname"] ? $user_res["nickname"] : $user["account"],
|
|
|
|
|
|
|
|
"sex" => $user_res["sex"] ? $user_res["sex"] : 0,
|
|
|
|
|
|
|
|
"is_platform" => $platform,
|
|
|
|
|
|
|
|
"token" => $result['token'],
|
|
|
|
|
|
|
|
"user_token" => $userToken,
|
|
|
|
|
|
|
|
"OTP_token" => think_encrypt(json_encode(array('uid' => $user["user_id"], 'time' => time())), 1),
|
|
|
|
|
|
|
|
'is_uc' => 0,
|
|
|
|
|
|
|
|
"is_open_small_account" => C('IS_OPEN_SMALL_ACCOUNT'),
|
|
|
|
|
|
|
|
'url' => 'http://' . str_replace(array('http://'), '', C('WEB_SITE')) . '/mobile.php',
|
|
|
|
|
|
|
|
'small_list' => $small_list,
|
|
|
|
|
|
|
|
'ios_packagename' => C('WEB_IOS_PACKAGENAME'),
|
|
|
|
|
|
|
|
'android_packagename' => C('WEB_AND_PACKAGENAME'),
|
|
|
|
|
|
|
|
'site_status' => C('SDK_SITE_STATUS'),
|
|
|
|
|
|
|
|
'head_img' => !empty($user_res['head_img']) ? $user_res['head_img'] : '',
|
|
|
|
|
|
|
|
'unread_count' => $unread_count,
|
|
|
|
|
|
|
|
'notice_count' => $notice_count,
|
|
|
|
|
|
|
|
'request_count' => $buddies_request,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 通知后台 TASK_URLhttp://47.111.118.107:9501
|
|
|
|
|
|
|
|
$url = C('TASK_URL')."/game-event/login";
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
post_async($url, [
|
|
|
|
|
|
|
|
'form_params' => [
|
|
|
|
|
|
|
|
'game_id' => $user["game_id"],
|
|
|
|
|
|
|
|
'user_id' => $user["user_id"],
|
|
|
|
|
|
|
|
'login_time' => time()
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
} catch(\Exception $e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// $log['remarks'] = '未知错误';
|
|
|
|
|
|
|
|
// log_action($log);
|
|
|
|
|
|
|
|
$this -> set_message(1028, "fail", "未知错误");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
$this->resetLoginLimit();
|
|
|
|
break;
|
|
|
|
return ['status' => true, 'message' => '登录成功', 'data' => $data];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function isBan($ip, $deviceNum)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$ban = M('device_bans','tab_')->select(['id'])->where(['tag' => ['in', [$ip, $deviceNum]]])->limit(1)->find();
|
|
|
|
|
|
|
|
if (empty($ban)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$log['uid'] = $user['user_id'];
|
|
|
|
return true;
|
|
|
|
// log_action($log);
|
|
|
|
|
|
|
|
echo base64_encode(json_encode($res_msg));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function doLogin($user, $game, $clientIp, $deviceNum)
|
|
|
|
protected function doLogin($account, $password, $game, $params = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
$clientIp = $params['client_ip'] ?? get_client_ip();
|
|
|
|
|
|
|
|
$deviceNum = $params['device_num'] ?? '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->isBan($clientIp, $deviceNum)) {
|
|
|
|
|
|
|
|
return ['status' => false, 'message' => '设备已被禁用'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$user = M('user', 'tab_')->where(['account' => $account])->find();
|
|
|
|
|
|
|
|
|
|
|
|
/* 获取用户数据 */
|
|
|
|
/* 获取用户数据 */
|
|
|
|
if (empty($user) || $user['lock_status'] != 1 && $user['check_status'] != 1) {
|
|
|
|
if (empty($user) || $user['lock_status'] != 1 && $user['check_status'] != 1) {
|
|
|
|
return null;
|
|
|
|
return ['status' => false, 'message' => '账号或密码错误'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (think_ucenter_md5($password, UC_AUTH_KEY) === $user['password']) {
|
|
|
|
if (think_ucenter_md5($password, UC_AUTH_KEY) === $user['password']) {
|
|
|
|
return null;
|
|
|
|
return ['status' => false, 'message' => '账号或密码错误'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$userData = [];
|
|
|
|
$testResource = M('test_resource','tab_')->select(['device_number'])->where('user_id=%s and apply_status=2', $user['id'])->find(); //测试资源(扶持号)
|
|
|
|
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) {
|
|
|
|
if ($testResource) {
|
|
|
|
|
|
|
|
if ($this->isIpWarning($user, $testResource, $deviceNum)) {
|
|
|
|
|
|
|
|
$this->ipWarningLog($user, $testResource, $deviceNum);
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($this->isDeviceError($user, $testResource, $deviceNum)) {
|
|
|
|
if ($this->isDeviceError($user, $testResource, $deviceNum)) {
|
|
|
|
$userData['last_device_number'] = $deviceNum;
|
|
|
|
$userData['last_device_number'] = $deviceNum;
|
|
|
|
$userData['lock_status'] = 0 ;
|
|
|
|
$userData['lock_status'] = 0 ;
|
|
|
|
$this->deviceErrorLog($user, $testResource, $deviceNum);
|
|
|
|
$this->deviceErrorLog($user, $testResource, $deviceNum);
|
|
|
|
return null;
|
|
|
|
return ['status' => false, 'message' => '该账号已被禁用'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->isIpWarning($user, $testResource, $deviceNum)) {
|
|
|
|
|
|
|
|
$this->ipWarningLog($user, $testResource, $deviceNum);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$userData["id"] = $uid;
|
|
|
|
$result = $this->getLoginToken($user, $game, $password);
|
|
|
|
$userData["login_time"] = NOW_TIME;
|
|
|
|
if (!$result) {
|
|
|
|
$userData["login_ip"] = $clientIp;
|
|
|
|
return ['status' => false, 'message' => '系统异常'];
|
|
|
|
$userData["last_login_ip"] = $clientIp;
|
|
|
|
}
|
|
|
|
$userData["last_device_number"] = $deviceNum;
|
|
|
|
[$token, $userToken] = $result;
|
|
|
|
$userData["token"] = $this->generateToken($uid,$account,$password);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userData = [];
|
|
|
|
|
|
|
|
if (!$user['device_number']) {
|
|
|
|
|
|
|
|
$userData['device_number'] = $deviceNum;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$userData['login_time'] = NOW_TIME;
|
|
|
|
|
|
|
|
$userData['login_ip'] = $clientIp;
|
|
|
|
|
|
|
|
$userData['last_login_ip'] = $clientIp;
|
|
|
|
|
|
|
|
$userData['last_device_number'] = $deviceNum;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!$user['fgame_id']) {
|
|
|
|
|
|
|
|
$userData['fgame_id'] = $game['id'];
|
|
|
|
|
|
|
|
$userData['fgame_name'] = $game['game_name'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$userData['token'] = $token;
|
|
|
|
|
|
|
|
$status = M('user', 'tab_')->where(['id' => $user['id']])->save($userData);
|
|
|
|
|
|
|
|
if ($status) {
|
|
|
|
|
|
|
|
return ['status' => false, 'message' => '登录异常'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$userToken = 0;
|
|
|
|
$this->addUserLoginRecord($user, $game, $clientIp, $deviceNum);
|
|
|
|
if($testResource) { //扶持号
|
|
|
|
$this->addGameUserLoginRecord($user, $game, $clientIp, $deviceNum);
|
|
|
|
if($user['device_number'] && $unique_code && $user['device_number'] != $unique_code){ //#当前登录设备信息与历史登录设备信息不一致,触发账户冻结
|
|
|
|
|
|
|
|
$this->sdklogin_device_error($user,$test_resource,$unique_code);
|
|
|
|
if (!$user['device_type']) {
|
|
|
|
$this->sdklogin_ip_error($user,$test_resource,get_client_ip());
|
|
|
|
$this->oaDeviceTypeUpdate($user, $game);
|
|
|
|
return -1;//扶持号被禁用
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$token = $this->sdklogin_update($user,$account,$password,$user['fgame_id'],$game_id,$game_name,$unique_code,$userToken); //更新用户登录信息
|
|
|
|
|
|
|
|
$this->user_login_record2($user,$type,$game_id,$game_name,$sdk_version);
|
|
|
|
|
|
|
|
$this->sdklogin_ip_error($user,$test_resource,get_client_ip());
|
|
|
|
|
|
|
|
return array("user_id"=>$user['id'],"token"=>$token, "user_token" => $userToken); //登录成功,返回用户ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$token = $this->sdklogin_update($user,$account,$password,$user['fgame_id'],$game_id,$game_name,$unique_code,$userToken); //更新用户登录信息
|
|
|
|
|
|
|
|
$this->user_login_record2($user,$type,$game_id,$game_name,$sdk_version);
|
|
|
|
|
|
|
|
return array("user_id"=>$user['id'],"token"=>$token, "user_token" => $userToken); //登录成功,返回用户ID
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
|
|
|
'user' => $user,
|
|
|
|
|
|
|
|
'token' => $token,
|
|
|
|
|
|
|
|
'user_token' => $userToken,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
return ['status' => true, 'message' => '登录异常', 'data' => $data];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function isDeviceError($user, $testResource, $deviceNum)
|
|
|
|
protected function isDeviceError($user, $testResource, $deviceNum)
|
|
|
@ -215,15 +165,15 @@ class UserService
|
|
|
|
$data['promote_id'] = $testResource['promote_id'];
|
|
|
|
$data['promote_id'] = $testResource['promote_id'];
|
|
|
|
$data['promote_account'] = $testResource['promote_account'];
|
|
|
|
$data['promote_account'] = $testResource['promote_account'];
|
|
|
|
$data['type'] = 2;
|
|
|
|
$data['type'] = 2;
|
|
|
|
$data['detail'] = "登录设备号异常,本次异常设备号:" . $deviceNum . ",历史登录设备号:" . $user['device_number'];
|
|
|
|
$data['detail'] = '登录设备号异常,本次异常设备号:' . $deviceNum . ',历史登录设备号:' . $user['device_number'];
|
|
|
|
$data['create_time'] = NOW_TIME;
|
|
|
|
$data['create_time'] = NOW_TIME;
|
|
|
|
M('protect_log','tab_')->add($data);
|
|
|
|
M('protect_log','tab_')->add($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function isIpWarning($user, $testResource, $deviceNum)
|
|
|
|
protected function isIpWarning($user, $testResource, $deviceNum)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$newResult = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$clientIp);
|
|
|
|
$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']);
|
|
|
|
$oldResult = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$user['login_ip']);
|
|
|
|
$newResult = json_decode($newResult, true);
|
|
|
|
$newResult = json_decode($newResult, true);
|
|
|
|
$oldResult = json_decode($oldResult, true);
|
|
|
|
$oldResult = json_decode($oldResult, true);
|
|
|
|
if($newResult['data']['city'] != $oldResult['data']['city']) {
|
|
|
|
if($newResult['data']['city'] != $oldResult['data']['city']) {
|
|
|
@ -245,7 +195,7 @@ class UserService
|
|
|
|
$data['promote_id'] = $testResource['promote_id'];
|
|
|
|
$data['promote_id'] = $testResource['promote_id'];
|
|
|
|
$data['promote_account'] =$testResource['promote_account'];
|
|
|
|
$data['promote_account'] =$testResource['promote_account'];
|
|
|
|
$data['type'] = 1;
|
|
|
|
$data['type'] = 1;
|
|
|
|
$data['detail'] = "登录IP异常,本次异常IP:" . $clientIp . ",历史登录IP:" . $user['login_ip'];
|
|
|
|
$data['detail'] = '登录IP异常,本次异常IP:' . $clientIp . ',历史登录IP:' . $user['login_ip'];
|
|
|
|
$data['create_time'] = NOW_TIME;
|
|
|
|
$data['create_time'] = NOW_TIME;
|
|
|
|
M('protect_log','tab_')->add($data);
|
|
|
|
M('protect_log','tab_')->add($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -256,112 +206,80 @@ class UserService
|
|
|
|
return $token;
|
|
|
|
return $token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function sdklogin_update($user, $account, $password, $user_fgame_id, $game_id, $game_name, $unique_code='', &$userToken=''){
|
|
|
|
protected function getLoginToken($user, $game, $password)
|
|
|
|
$model = M('User','tab_');
|
|
|
|
{
|
|
|
|
$uid = $user['id'];
|
|
|
|
$token = $this->generateToken($user['id'], $user['account'], $password);
|
|
|
|
$data["id"] = $uid;
|
|
|
|
$userToken = $this->generateToken($user['id'], $user['account'], $password) . uniqid() . rand(1000, 9999);
|
|
|
|
$data["login_time"] = NOW_TIME;
|
|
|
|
$record = M('user_token','tab_')->where(['user_id' => $user['id'], 'game_id' => $game['id']])->find();
|
|
|
|
$data["login_ip"] = get_client_ip();
|
|
|
|
if (!$record) {
|
|
|
|
// $data["device_number"] = $unique_code;
|
|
|
|
M('user_token', 'tab_')->add([
|
|
|
|
$data["last_login_ip"] = $user['login_ip'];
|
|
|
|
'user_id' => $user['id'],
|
|
|
|
$data["last_device_number"] = $user['device_number'] ? $user['device_number'] : '';
|
|
|
|
'game_id' => $game['id'],
|
|
|
|
$data["token"] = $this->generateToken($uid,$account,$password);
|
|
|
|
'relation_game_id' => $game['relation_game_id'],
|
|
|
|
|
|
|
|
|
|
|
|
M('user_token','tab_')->startTrans();
|
|
|
|
|
|
|
|
$userToken = $this->generateToken($uid,$account,$password).uniqid().rand(1000, 9999);
|
|
|
|
|
|
|
|
$relationGameId = M('game', 'tab_')->where([
|
|
|
|
|
|
|
|
'id' => $game_id
|
|
|
|
|
|
|
|
])->getField('relation_game_id');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$userTokens = M('user_token','tab_')->where([
|
|
|
|
|
|
|
|
'user_id' => $uid,
|
|
|
|
|
|
|
|
'game_id' => $game_id
|
|
|
|
|
|
|
|
])->find();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$userTokens) {
|
|
|
|
|
|
|
|
$r = M('user_token', 'tab_')->add([
|
|
|
|
|
|
|
|
'user_id' => $uid,
|
|
|
|
|
|
|
|
'game_id' => $game_id,
|
|
|
|
|
|
|
|
'relation_game_id' => $relationGameId,
|
|
|
|
|
|
|
|
'user_token' => $userToken,
|
|
|
|
'user_token' => $userToken,
|
|
|
|
'login_cnt' => 1,
|
|
|
|
'login_cnt' => 1,
|
|
|
|
'create_time' => time(),
|
|
|
|
'create_time' => time(),
|
|
|
|
'update_time' => time()
|
|
|
|
'update_time' => time()
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
if (!$r) {
|
|
|
|
|
|
|
|
M('user_token','tab_')->rollback();
|
|
|
|
M('user_token', 'tab_')->where([
|
|
|
|
$msg = array(
|
|
|
|
'user_id' => $user['id'],
|
|
|
|
"status" => 5,
|
|
|
|
'relation_game_id' => $game['relation_game_id']
|
|
|
|
"return_code" => 5,
|
|
|
|
|
|
|
|
"return_msg" => "数据出错",
|
|
|
|
|
|
|
|
"msg" => '1'
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
echo base64_encode(json_encode($msg));
|
|
|
|
|
|
|
|
exit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$r = M('user_token', 'tab_')->where([
|
|
|
|
|
|
|
|
'user_id' => $uid,
|
|
|
|
|
|
|
|
'relation_game_id' => $relationGameId
|
|
|
|
|
|
|
|
])->save([
|
|
|
|
])->save([
|
|
|
|
'user_token' => $userToken,
|
|
|
|
'user_token' => $userToken,
|
|
|
|
'login_cnt' => $userTokens['login_cnt'] + 1,
|
|
|
|
'login_cnt' => $record['login_cnt'] + 1,
|
|
|
|
'update_time' => time()
|
|
|
|
'update_time' => time()
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
if ($r === false) {
|
|
|
|
|
|
|
|
M('user_token','tab_')->rollback();
|
|
|
|
|
|
|
|
$msg = array(
|
|
|
|
|
|
|
|
"status" => 5,
|
|
|
|
|
|
|
|
"return_code" => 5,
|
|
|
|
|
|
|
|
"return_msg" => "数据出错2",
|
|
|
|
|
|
|
|
"msg" => '1'
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
echo base64_encode(json_encode($msg));
|
|
|
|
|
|
|
|
exit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$r = M('user_token', 'tab_')->where([
|
|
|
|
M('user_token', 'tab_')->where([
|
|
|
|
'user_id' => $uid,
|
|
|
|
'user_id' => $uid,
|
|
|
|
'game_id|relation_game_id' => $relationGameId
|
|
|
|
'game_id|relation_game_id' => $game['relation_game_id']
|
|
|
|
])->save([
|
|
|
|
])->save([
|
|
|
|
'user_token' => $userToken,
|
|
|
|
'user_token' => $userToken,
|
|
|
|
'login_cnt' => $userTokens['login_cnt'] + 1,
|
|
|
|
'login_cnt' => $record['login_cnt'] + 1,
|
|
|
|
'update_time' => time()
|
|
|
|
'update_time' => time()
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
if ($r === false) {
|
|
|
|
|
|
|
|
M('user_token','tab_')->rollback();
|
|
|
|
|
|
|
|
exit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
M('user_token','tab_')->commit();
|
|
|
|
return [$token, $userToken];
|
|
|
|
|
|
|
|
}
|
|
|
|
if($user_fgame_id){
|
|
|
|
|
|
|
|
$model->save($data);
|
|
|
|
public function oaDeviceTypeUpdate($user, $game)
|
|
|
|
}else{
|
|
|
|
{
|
|
|
|
$data['fgame_id']=$game_id;
|
|
|
|
$gameServer = substr($game['game_name'], -10, 9);
|
|
|
|
$data['fgame_name']=$game_name;
|
|
|
|
if($gameServer == '安卓版'){
|
|
|
|
$model->save($data);
|
|
|
|
$arr['device_type'] = 'Android';
|
|
|
|
$device_type = M('User','tab_')->where(['id' => $user['id']])->getField('device_type');
|
|
|
|
} elseif($gameServer == '苹果版') {
|
|
|
|
if(empty($device_type)){
|
|
|
|
$arr['device_type'] = 'IOS';
|
|
|
|
$gameServer = substr($game_name, -10, 9);
|
|
|
|
|
|
|
|
if($gameServer == '安卓版'){
|
|
|
|
|
|
|
|
$arr['device_type'] = 'Android';
|
|
|
|
|
|
|
|
} elseif($gameServer == '苹果版') {
|
|
|
|
|
|
|
|
$arr['device_type'] = 'IOS';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$arr['time'] = time();
|
|
|
|
|
|
|
|
$arr['account'] = $account;
|
|
|
|
|
|
|
|
ksort($arr);
|
|
|
|
|
|
|
|
reset($arr);
|
|
|
|
|
|
|
|
$sign = md5(http_build_query($arr) . C('GET_INFO_KEY'));
|
|
|
|
|
|
|
|
$arr['sign'] = $sign;
|
|
|
|
|
|
|
|
$reData = curl_post('http://oa.76ba.com/api/wanmeng/deviceTypeUpdate',$arr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data["token"];
|
|
|
|
$arr['time'] = time();
|
|
|
|
|
|
|
|
$arr['account'] = $user['account'];
|
|
|
|
|
|
|
|
ksort($arr);
|
|
|
|
|
|
|
|
reset($arr);
|
|
|
|
|
|
|
|
$sign = md5(http_build_query($arr) . C('GET_INFO_KEY'));
|
|
|
|
|
|
|
|
$arr['sign'] = $sign;
|
|
|
|
|
|
|
|
$reData = curl_post('http://oa.76ba.com/api/wanmeng/deviceTypeUpdate', $arr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function addUserLoginRecord($user, $game, $clientIp, $deviceNum){
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
|
|
|
'user_id' => $user['id'],
|
|
|
|
|
|
|
|
'user_account' => $user['account'],
|
|
|
|
|
|
|
|
'user_nickname' => $user['nickname'],
|
|
|
|
|
|
|
|
'game_id' => $game['id'],
|
|
|
|
|
|
|
|
'promote_id' => $user['promote_id'],
|
|
|
|
|
|
|
|
'game_name' => $game['game_name'],
|
|
|
|
|
|
|
|
'sdk_version' => $game['sdk_version'],
|
|
|
|
|
|
|
|
'type' => 1,
|
|
|
|
|
|
|
|
'server_id' => null,
|
|
|
|
|
|
|
|
'server_name' => null,
|
|
|
|
|
|
|
|
'login_time' => NOW_TIME,
|
|
|
|
|
|
|
|
'login_ip' => $clientIp,
|
|
|
|
|
|
|
|
'lpuid' => $user['puid'],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
return M('user_login_record','tab_')->add($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function saveUserGameLoginRecord($user, $game, $clientIp, $deviceNum){
|
|
|
|
protected function addUserGameLoginRecord($user, $game, $clientIp, $deviceNum){
|
|
|
|
$data = [
|
|
|
|
$data = [
|
|
|
|
'user_id' => $user['id'],
|
|
|
|
'user_id' => $user['id'],
|
|
|
|
'user_account' => $user['account'],
|
|
|
|
'user_account' => $user['account'],
|
|
|
@ -379,4 +297,91 @@ class UserService
|
|
|
|
];
|
|
|
|
];
|
|
|
|
return M('user_game_login_record','tab_')->add($data);
|
|
|
|
return M('user_game_login_record','tab_')->add($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function dispatchLoginEvent($params)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$client = new TaskClient();
|
|
|
|
|
|
|
|
$client->post('/game-event/login', $params);
|
|
|
|
|
|
|
|
} catch(\Exception $e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function addUserPlay($user, $game, $clientIp)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$user_play = M('user_play', 'tab_');
|
|
|
|
|
|
|
|
$map['game_id'] = $game['id'];
|
|
|
|
|
|
|
|
$map['user_id'] = $user['id'];
|
|
|
|
|
|
|
|
$map['sdk_version'] = $game['sdk_version'];
|
|
|
|
|
|
|
|
$userPlay = M('user_play', 'tab_')->where($map)->find();
|
|
|
|
|
|
|
|
if (empty($userPlay)) {
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
$data['user_id'] = $user['user_id'];
|
|
|
|
|
|
|
|
$data['user_account'] = $user['account'];
|
|
|
|
|
|
|
|
$data['user_nickname'] = $user['nickname'];
|
|
|
|
|
|
|
|
$data['game_id'] = $user['game_id'];
|
|
|
|
|
|
|
|
$data['game_appid'] = $user['game_appid'];
|
|
|
|
|
|
|
|
$data['game_name'] = $game['game_name'];
|
|
|
|
|
|
|
|
$data['server_id'] = 0;
|
|
|
|
|
|
|
|
$data['server_name'] = '';
|
|
|
|
|
|
|
|
$data['role_id'] = 0;
|
|
|
|
|
|
|
|
$data['parent_id'] = $user['parent_id'];
|
|
|
|
|
|
|
|
$data['parent_name'] = $user['parent_name'];
|
|
|
|
|
|
|
|
$data['role_name'] = '';
|
|
|
|
|
|
|
|
$data['role_level'] = 0;
|
|
|
|
|
|
|
|
$data['bind_balance'] = 0;
|
|
|
|
|
|
|
|
$data['promote_id'] = $user['promote_id'];
|
|
|
|
|
|
|
|
$data['promote_account'] = $user['promote_account'];
|
|
|
|
|
|
|
|
$data['play_time'] = time();
|
|
|
|
|
|
|
|
$data['play_ip'] = $clientIp;
|
|
|
|
|
|
|
|
$data['sdk_version'] = $game['sdk_version'];
|
|
|
|
|
|
|
|
$data['ppuid'] = $user['puid'] == '' ? 0 : $user['puid'];
|
|
|
|
|
|
|
|
$data['check_time'] = time();
|
|
|
|
|
|
|
|
$data['create_time'] = time();
|
|
|
|
|
|
|
|
$userPlay->add($data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function getNoticeCount()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$noticeCount = 0;
|
|
|
|
|
|
|
|
$time = time();
|
|
|
|
|
|
|
|
$noticeIds = M('notice', 'tab_')
|
|
|
|
|
|
|
|
->where('start_time < ' . $time . ' AND game_id = ' . $user['game_id']. ' AND (end_time = 0 OR end_time >' . $time . ')')
|
|
|
|
|
|
|
|
->getField('id',true);
|
|
|
|
|
|
|
|
if(!empty($noticeIds))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$noticeCount += count($noticeIds);
|
|
|
|
|
|
|
|
$where['notice_id'] = ['in', implode(',', $noticeIds)];
|
|
|
|
|
|
|
|
$where['user_id'] = $user['id'];
|
|
|
|
|
|
|
|
$where['is_read'] = 1;
|
|
|
|
|
|
|
|
$noticeReadCount = M('notice_read', 'tab_')->where($where)->count();
|
|
|
|
|
|
|
|
$noticeCount -= $noticeReadCount;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $noticeCount;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function loginLimit($params)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$isLoginLimit = intval(C('LOGIN_LIMIT_OPEN', null, 1));
|
|
|
|
|
|
|
|
if ($isLoginLimit == 0) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$loginLimitNum = C('LOGIN_LIMIT_NUM', null, 300);
|
|
|
|
|
|
|
|
$count = Redis::incr(Redis::KEY_LOGIN_LIMIT);
|
|
|
|
|
|
|
|
if ($count >= $loginLimitNum) {
|
|
|
|
|
|
|
|
Log::write('login_limit:' . date('Y-m-d H:i:s') . ' ---- ' . $count, 'INFO', '', C('LOG_PATH')."login_limit.log");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function resetLoginLimit()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$isLoginLimit = intval(C('LOGIN_LIMIT_OPEN', null, 1));
|
|
|
|
|
|
|
|
if ($isLoginLimit != 0) {
|
|
|
|
|
|
|
|
Redis::decr(Redis::KEY_LOGIN_LIMIT);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|