def doGetUserInfo(cls, rparams, mo): TyContext.ftlog.info(cls.__name__, 'doGetUserInfo->rparams=', rparams) userId = rparams['userId'] if userId > 0: TyContext.MySqlSwap.checkUserDate(userId) AccountHelper.restore_avatar_verify_set(userId) # 获取玩家基本信息 userEmail, userName, coin, userPurl, userSex, userSnsId, bindMobile = \ TyContext.RedisUser.execute(userId, 'HMGET', 'user:'******'email', 'name', 'diamond', 'purl', 'sex', 'snsId', 'bindMobile') # 获取玩家绑定类型 userType = 0 if bindMobile != None and len(str(bindMobile)) == 11: userType = userType | 1 if userEmail != None and len(userEmail) > 0: userType = userType | 2 if userSnsId != None and len(str(userSnsId)) > 0: userType = userType | 4 mo.setResult('userType', userType) baseinfo = { 'userId': userId, 'userName': TyContext.KeywordFilter.replace(unicode(userName)), 'coin': coin, 'userPurl': cls.__filter_qhimg__(userPurl), 'userSex': userSex, 'userType': userType } baseinfo = json.dumps(baseinfo) mo.setResult('code', 0) mo.setResult('info', baseinfo) else: mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '参数错误') return
def doBindBySnsId(cls, rparams, mo): TyContext.ftlog.info(cls.__name__, 'doBindBySnsId->rparams=', rparams) userId = rparams['userId'] snsId = rparams['snsId'] if snsId.startswith('360'): if Account360.doGetUserInfo(rparams, snsId) != True: mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '360登录验证失败!') return else: snsId = rparams['snsId'] # 绑定过程,不改变用户昵称 if 'name' in rparams: del rparams['name'] elif snsId.startswith('wx:'): if not AccountWeixin.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'wx登录验证失败!') # TyContext.BiReport.report_bi_sdk_login( # TyContext.BIEventId.SDK_LOGIN_BY_SNSID_FAIL, 0, # rparams['appId'], rparams['clientId'], snsId, # AccountConst.CODE_USER_SNS_GETINFO_ERROR) return else: snsId = rparams['snsId'] userIdBound = TyContext.RedisUserKeys.execute('GET', 'snsidmap:' + snsId) if userIdBound: TyContext.MySqlSwap.checkUserDate(userIdBound) AccountHelper.restore_avatar_verify_set(userIdBound) mo.setResult('code', 0) mo.setResult('info', '绑定成功') mo.setResult('binduserstyle', 2) AccountLogin.__do_login_done__(rparams, userIdBound, mo, AccountConst.USER_TYPE_SNS) return # V3版一个tyid可以绑定多个snsId TyContext.MySqlSwap.checkUserDate(userId) AccountHelper.restore_avatar_verify_set(userId) TyContext.RedisUser.execute( userId, 'HMSET', 'user:'******'snsId', snsId, 'isbind', AccountConst.USER_TYPE_SNS, 'bindTime', datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) TyContext.RedisUserKeys.execute('SET', 'snsidmap:' + snsId, userId) mo.setResult('code', 0) mo.setResult('binduserstyle', 1) mo.setResult('info', '绑定成功') AccountLogin.__do_login_done__(rparams, userId, mo, AccountConst.USER_TYPE_SNS) cls.__bind_success_callback_(rparams['appId'], 'bindsnsid', { 'appId': rparams['appId'], 'userId': userId, 'snsId': snsId })
def __find_userid_by_snsid__(cls, snsId): uid = TyContext.RedisUserKeys.execute('GET', 'snsidmap:' + str(snsId)) if not uid or uid <= 0: return 0 try: TyContext.MySqlSwap.checkUserDate(uid) AccountHelper.restore_avatar_verify_set(uid) return uid except: TyContext.ftlog.error('__find_userid_by_snsid__ failed get cold data') return 0
def _find_userid_by_qid(cls, qid): uid = TyContext.RedisUserKeys.execute('GET', 'snsidmap:' + str(qid)) if not uid or uid <= 0: return 0 try: TyContext.MySqlSwap.checkUserDate(uid) AccountHelper.restore_avatar_verify_set(uid) return uid except: TyContext.ftlog.error( 'TuYouSLL _find_userid_by_qid can not find' ' user for qid', qid) return 0
def __find_userid_by_devid_map_v3__(cls, deviceId): if deviceId == '528c8e6cd4a3c6598999a0e9df15ad32': return 0 uid = TyContext.RedisUserKeys.execute('GET', 'devidmap3:' + str(deviceId)) if not uid or uid <= 0: return 0 try: TyContext.MySqlSwap.checkUserDate(uid) AccountHelper.restore_avatar_verify_set(uid) return uid except: TyContext.ftlog.error('__find_userid_by_devid_map_v3__ failed get cold data') return 0
def _find_userid_by_qid(cls, qid): uid = TyContext.RedisUserKeys.execute('GET', 'snsidmap:' + str(qid)) if not uid or uid <= 0: return 0 try: from tysdk.entity.user_common.account_helper import AccountHelper TyContext.MySqlSwap.checkUserDate(uid) AccountHelper.restore_avatar_verify_set(uid) return uid except: TyContext.ftlog.error( 'Account360 _find_userid_by_qid can not find' ' user for qid', qid) return 0
def __find_userid_by_tyid__(cls, tuyooId, rparams=None): if tuyooId and tuyooId > 0: if rparams: # 黑名单 forbid_data = TyContext.Configure.get_global_item_json("forbid_device_info", {}) if cls.__check_forbid_device(tuyooId, forbid_data, rparams): TyContext.ftlog.error("AccountLogin->checkLoginDevice failed userId=", tuyooId, 'rparams=', rparams, 'forbid_data=', forbid_data) return 0 # 白名单 forbid_data = TyContext.Configure.get_global_item_json("forbid_device_whitelist", {}) if cls.__check_forbid_device(tuyooId, forbid_data, rparams): rparams = None if not TyContext.MySqlSwap.checkUserDate(tuyooId, rparams=rparams): return 0 AccountHelper.restore_avatar_verify_set(tuyooId) if False and rparams: chip, _mdevid, _sessionDevId, _sessionIccid, _sessionIdfa, _uuid, _mac = \ TyContext.RedisUser.execute(tuyooId, 'HMGET', 'user:'******'chip', 'mdevid', 'sessionDevId', 'sessionIccid', 'sessionIdfa', 'uuid', 'mac') if chip and chip >= 10000000: result = [] deviceId = rparams.get('deviceId', '') iccid = rparams.get('iccid') idfa = rparams.get('idfa') uuid = rparams.get('uuid') mac = rparams.get('mac') result.append(deviceId and deviceId == _mdevid) result.append(deviceId and deviceId == _sessionDevId) result.append(iccid and iccid == str(_sessionIccid)) result.append(idfa and idfa == _sessionIdfa) result.append(uuid and uuid == _uuid) result.append(mac and mac == _mac) if not reduce(lambda x, y: x or y, result): TyContext.ftlog.error("AccountLogin->checkLoginDevice failed userId=", tuyooId, 'rparams=', rparams, '_mdevid=', _mdevid, '_sessionDevId=', _sessionDevId, '_sessionIccid=', _sessionIccid, '_sessionIdfa=', _sessionIdfa, '_uuid=', _uuid, '_mac=', _mac) return 0 return tuyooId return 0
def fillUserLoginInfoV3(cls, params, mo, userId, isLogin, isCreate): # 兼容客户端之前的用户未能在创建时传入imsi imsi = TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'imsi') if not imsi: if 'imsi' in params and params['imsi']: TyContext.RedisUser.execute(userId, 'HSET', 'user:'******'imsi', params['imsi']) TyContext.ftlog.debug('fillUserLoginInfoV3 in imsi', imsi, 'params[imsi]', params['imsi']) clientIp = TyContext.RunHttp.get_client_ip() # IMPORTANT!! used by GDSS statistics TyContext.ftlog.info('fillUserLoginInfoV3 in userId=', userId, 'isLogin='******'isCreate=', isCreate, 'clientId=', params['clientId'], 'clientIp=', clientIp, 'gameId=', params['appId'], 'params=', params) appId = params['appId'] cls.updateUserSessionInfo(appId, userId, params) # 查询用户基本信息 mo.setResult('code', AccountConst.CODE_USER_SUCCESS) mo.setResult('userId', userId) mo.setResult('appId', appId) # 查询用户基本信息 uname, authorCode, email = TyContext.AuthorCode.creatUserAuthorCodeNew( userId) mo.setResult('authorCode', authorCode) mo.setResult('userName', TyContext.KeywordFilter.replace(unicode(uname))) mo.setResult('userEmail', unicode(email)) if isCreate: mo.setResult('isCreate', 1) else: mo.setResult('isCreate', 0) # 获取玩家绑定类型 userType = 0 bindMobile, userEmail, userSnsId, userDBPwd, changePwdCount, log_report, exception_report = TyContext.RedisUser.execute( userId, 'HMGET', 'user:'******'bindMobile', 'email', 'snsId', 'password', 'changePwdCount', 'log_report', 'exception_report') if log_report != 1: log_report = 0 if exception_report != 1: exception_report = 0 if bindMobile != None and len(str(bindMobile)) == 11: userType = userType | 1 if userEmail != None and len(userEmail) > 0: userType = userType | 2 if userSnsId != None and len(str(userSnsId)) > 0: userType = userType | 4 mo.setResult('userType', userType) if userSnsId and len(userSnsId) > 0: mo.setResult('snsId', userSnsId) mo.setResult('userPwd', unicode(userDBPwd)) mo.setResult('mobile', unicode(bindMobile)) # 获取玩家修改密码次数 if changePwdCount == None: changePwdCount = 0 mo.setResult('changePwdCount', changePwdCount) mo.setResult('log_report', log_report) mo.setResult('exception_report', exception_report) checkcode = '' if appId < 10000: # 途游自己的游戏 cls.__append_tcp_infos__(appId, userId, params['clientId'], mo) clientId = params.get('clientId', 'unknow') AccountHelper.append_ios_idfa_flg(userId, appId, clientId, mo) cls.__append_logclient_infos__(userId, clientId, mo) else: checkcode = TyContext.AuthorCode.makeLoginCode( userId, appId, authorCode) mo.setResult('usercode', checkcode) # 为了兼容使用新登录老支付,当这种结合过期后,删除authInfo字段 ainfo = { 'authcode': authorCode, 'account': email, 'uid': userId, 'usercode': checkcode } ainfo = json.dumps(ainfo) mo.setResult('authInfo', ainfo)
def _check_userid_forbidden(cls, userId, rparams, loginType): if userId <= 0: return False, None, None deviceName = rparams.get('deviceName', '') # '[0-9a-f]{8} phoneType = rparams.get('phoneType', '') # '3' clientSystem = rparams.get('clientSystem', '') # 'IOS' createTime = TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'createTime') # 2014-10-11 23:25:46.960885 if clientSystem == 'IOS' and re.match('[0-9a-f]{8}', deviceName) and createTime: begTime = time.mktime(time.strptime('2016-01-01 0:0:0.0', '%Y-%m-%d %H:%M:%S.%f')) endTime = time.mktime(time.strptime('2016-04-30 23:59:59.0', '%Y-%m-%d %H:%M:%S.%f')) try: createTime = time.mktime(time.strptime(createTime, '%Y-%m-%d %H:%M:%S.%f')) except: begTime, createTime, endTime = 0, 0, 0 if begTime < createTime < endTime: TyContext.ftlog.info('_check_userid_forbidden deviceName failed:', 'userId', userId, 'rparams', rparams) raise Exception("forbidden userid") clientId = rparams.get('clientId', '') deviceId = rparams.get('deviceId', '') appId = rparams.get('appId') try: # 获取白名单的clientid is_check_waived = TyContext.Configure.get_global_item_int('clientid.waived.confirm', 1) if is_check_waived: all_waived_clientids = TyContext.Configure.get_configure_json('clientid.number.map', {}) # TyContext.ftlog.debug('_check_userid_forbidden all_waived_clientids ', all_waived_clientids) if all_waived_clientids: clientIdNum = all_waived_clientids.get(clientId) if clientIdNum is None: TyContext.ftlog.info('_check_userid_forbidden not waived:', ' clientId', clientId, 'userId', userId) # raise Exception("forbidden clientid") info = TyContext.Configure.get_global_item_str('clientid_forbidden_info') tips = TyContext.Configure.get_global_item_str('clientid_forbidden_tips') return True, (info + tips).encode('utf8'), {'info': info.encode('utf8'), 'tips': tips.encode('utf8')} if clientId and TyContext.RedisForbidden.execute( 'EXISTS', 'forbidden:cid:' + str(clientId)): TyContext.ftlog.info('_check_userid_forbidden forbiddenuser:'******' clientId', clientId, 'userId', userId) raise Exception("forbidden clientid") if TyContext.RedisForbidden.execute('EXISTS', 'forbidden:uid:%d' % (userId)): TyContext.ftlog.info('_check_userid_forbidden forbiddenuser: userId', userId) raise Exception("forbidden userid") if deviceId and TyContext.RedisForbidden.execute('EXISTS', 'forbidden:devid:' + str(deviceId)): TyContext.ftlog.info('_check_userid_forbidden forbiddendevice:' ' deviceId', deviceId, 'userId', userId) raise Exception("forbidden deviceid") if appId and AccountHelper.check_user_forbidden_chip(userId, appId): TyContext.ftlog.info('_check_userid_forbidden forbidden chip:' ' appId', appId, 'userId', userId) raise Exception("forbidden too much chip") except Exception as e: info = TyContext.Configure.get_global_item_str('user_forbidden_info') info = info.format(userId=userId) tips = TyContext.Configure.get_global_item_str('user_forbidden_tips') return True, (info + tips).encode('utf8'), \ {'info': info.encode('utf8'), 'tips': tips.encode('utf8')} return False, None, None