def applyBeautyCertify(cls, gameId, userId): status = cls.getBeautyCertifyStatus(userId) if status.state > BeautyCertifyStatus.STATE_VERIFYING: status.state = BeautyCertifyStatus.STATE_IDLE status.gameId = 0 if status.state != BeautyCertifyStatus.STATE_IDLE: raise TyContext.FreetimeException(ERR_INVALID_STATE, '错误的状态') userCustomHead = UserPhotoService.getUserPhoto( userId, UserPhoto.PHOTO_TYPE_AVATAR) if not userCustomHead: raise TyContext.FreetimeException(ERR_NO_CUSTOM_HEAD, '没有自定义头像') cls.marginCollector.collect(gameId, userId) status.gameId = gameId userLifeHead = UserPhotoService.getUserPhoto(userId, UserPhoto.PHOTO_TYPE_LIFE) if userLifeHead: newState = BeautyCertifyStatus.STATE_PHOTOED else: newState = BeautyCertifyStatus.STATE_APPLIED cls.updateState(status, newState) cls.beautyCertifyStatusDao.save(status) return status
def checkHeadUpload(cls, checkAuthCode=True): gameId, userId = HttpUtils.checkGameRequest(checkAuthCode) base64Content = TyContext.RunHttp.getRequestParam('photoContent') if base64Content is None: raise TyContext.FreetimeException(1, 'Bad photoContent param') try: content = base64.b64decode(base64Content) except: raise TyContext.FreetimeException(1, 'Bad photoContent param') return gameId, userId, content
def revoke(cls, userId): status = cls.beautyCertifyStatusDao.load(userId) if status is None: raise TyContext.FreetimeException(ERR_REMOVED, '记录已被删除') if BeautyCertifyStatus.STATE_ACCEPTED != status.state: raise TyContext.FreetimeException(ERR_INVALID_STATE, '通过的才能撤销') TyContext.ftlog.info('BeautyCertifyService.revoke userId=', userId) cls._remove(status) beauty = cls.beautySignDao.getBeauty(status.userId) beauty &= ~BeautySignDao.BEAUTY_BIT cls.beautySignDao.setBeauty(userId, beauty)
def reject(cls, userId, reason=''): status = cls.beautyCertifyStatusDao.load(userId) if status is None: raise TyContext.FreetimeException(ERR_REMOVED, '记录已被删除') if BeautyCertifyStatus.STATE_VERIFYING != status.state: raise TyContext.FreetimeException(ERR_INVALID_STATE, '审核中的才能拒绝') TyContext.ftlog.info('BeautyCertifyService.reject userId=', userId) cls.updateState(status, BeautyCertifyStatus.STATE_REJECTED) cls.beautyCertifyStatusDao.save(status) return status
def requestVerify(cls, userId): status = cls.beautyCertifyStatusDao.load(userId) if status is None: raise TyContext.FreetimeException(ERR_REMOVED, '记录已被删除') if BeautyCertifyStatus.STATE_PHOTOED != status.state: raise TyContext.FreetimeException(ERR_INVALID_STATE, '还没有上传生活照') TyContext.ftlog.info('BeautyCertifyService.requestVerify accept=', userId) cls.updateState(status, BeautyCertifyStatus.STATE_VERIFYING, '') cls.beautyCertifyStatusDao.save(status) return status
def checkGameRequest(cls, checkAuthorCode=True): userId = TyContext.RunHttp.getRequestParamInt('userId') gameId = TyContext.RunHttp.getRequestParamInt('gameId') if userId <= 0: raise TyContext.FreetimeException(1, 'Bad userId') if gameId <= 0: gameId = TyContext.RunHttp.getRequestParamInt('appId') if gameId <= 0: raise TyContext.FreetimeException(1, 'Bad gameId') if checkAuthorCode: authorCode = TyContext.RunHttp.getRequestParam('authorCode') if not TyContext.AuthorCode.checkUserAuthorCode( userId, authorCode): raise TyContext.FreetimeException(1, 'Bad authorCode') return gameId, userId
def _default_charge_data_func(cls, chargeinfo): userId = chargeinfo['uid'] buttonId = chargeinfo['buttonId'] clientId = chargeinfo['clientId'] chargetype = chargeinfo['chargeType'] clientip = TyContext.UserSession.get_session_client_ip(userId) from tysdk.entity.pay_common.fengkong import Fengkong if Fengkong.is_ip_limited(clientip, clientId, chargetype): raise TyContext.FreetimeException( 1, '对不起,您已超出支付限制,请联系客服4008-098-000') paycodes = TyContext.Configure.get_global_item_json('paycodes', clientid=clientId) try: pdata = paycodes[chargetype]['paydata'] except Exception as e: TyContext.ftlog.error('paycodes', paycodes, 'config error for', clientId, 'buttonId', buttonId) raise for data in pdata: if data['prodid'] == buttonId: break else: raise Exception('product %s not found in paycodes(%s) config' % (buttonId, clientId)) cdata = copy.deepcopy(data) del cdata['prodid'] chargeinfo['chargeData'] = cdata
def accept(cls, userId): status = cls.beautyCertifyStatusDao.load(userId) if status is None: raise TyContext.FreetimeException(ERR_REMOVED, '记录已被删除') if BeautyCertifyStatus.STATE_VERIFYING != status.state: raise TyContext.FreetimeException(ERR_INVALID_STATE, '审核中的才能通过') TyContext.ftlog.info('BeautyCertifyService.accept userId=', userId) cls.marginCollector.back(status.gameId, status.userId) cls.updateState(status, BeautyCertifyStatus.STATE_ACCEPTED) cls.beautyCertifyStatusDao.save(status) beauty = cls.beautySignDao.getBeauty(status.userId) everBit = beauty & BeautySignDao.BEAUTY_EVER_BIT cls.beautySignDao.setBeauty( status.userId, BeautySignDao.BEAUTY_EVER_BIT | BeautySignDao.BEAUTY_BIT) if everBit == 0: cls.marginCollector.reward(status.gameId, status.userId) return status
def collect(self, gameId, userId): url = self.buildCollectUrl(gameId, userId) if not url: TyContext.ftlog.error( 'MarginCollectorImpl collect url null: ' 'gameId', gameId, 'userId', userId) return response, requestUrl = TyContext.WebPage.webget( url, {'userId': userId}) try: datas = json.loads(response) if 'error' in datas: raise TyContext.FreetimeException(ERR_MARGIN_NOT_ENOUGH, '金币不足') except: TyContext.ftlog.error( 'MarginCollectorImpl collect return ERROR, gameId=', gameId, 'userId=', userId, 'requestUrl=', url, 'response=', response) raise TyContext.FreetimeException(ERR_MARGIN_NOT_ENOUGH, '金币不足')
def load(self, userId, photoType): if photoType == UserPhoto.PHOTO_TYPE_AVATAR: return TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'purl') elif photoType == UserPhoto.PHOTO_TYPE_LIFE: return TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'lifepurl') else: raise TyContext.FreetimeException( 1, 'Unknown head type ' + str(photoType))
def save(self, userId, photoType, url): if photoType == UserPhoto.PHOTO_TYPE_AVATAR_VERIFYING: TyContext.RedisUser.execute(userId, 'HSET', 'user:'******'purl_verifying', url) elif photoType == UserPhoto.PHOTO_TYPE_AVATAR: TyContext.RedisUser.execute(userId, 'HSET', 'user:'******'purl', url) elif photoType == UserPhoto.PHOTO_TYPE_LIFE: TyContext.RedisUser.execute(userId, 'HSET', 'user:'******'lifepurl', url) else: raise TyContext.FreetimeException( 1, 'Unknown head type ' + str(photoType))
def _generateFrom(self, data): assert (isinstance(data, dict)) clitovers = {} for key, value in data.items(): cliv = ClientVersions(key) clitovers[key] = cliv for verdata in value: ver = Version.generateFrom(verdata) if ver: cliv.addVersion(ver) else: raise TyContext.FreetimeException( -1, 'Bad version data:' + str(data)) return clitovers
def savePhotoContent_nfs(cls, path, content): fullpath = cls.buildPhotoFullPath(path) dirname = os.path.dirname(fullpath) if not os.path.exists(dirname): os.makedirs(dirname, 0755) fd = None try: fd = os.open(fullpath, os.O_WRONLY | os.O_CREAT) os.write(fd, content) except: TyContext.ftlog.exception() raise TyContext.FreetimeException(1, 'Failed to save user head file') finally: if fd: os.close(fd)
def _is_clientId_forbindden_regist(cls, params): ''' 检查clienId是否被限制注册新用户 判断下是否是sns登陆,在Account_login中,增加了devidtosnsidmap, 创建用户失败后pop出去。 :param params: :return: ''' appId = cls.__get_param__(params, 'appId') clientId = cls.__get_param__(params, 'clientId') clientIdList = TyContext.Configure.get_game_item_json( appId, "forbiddenClientIds", {}) if clientId in clientIdList.get('clientIds', {}): # POP未成功创建的snsId deviceId = cls.__get_param__(params, 'deviceId') TyContext.RedisUserKeys.execute('LPOP', 'devidtosnsidmap:' + str(deviceId)) tips = clientIdList.get('fobiddenTips', "您使用的客户端版本号过低,请升级至最新版本") raise TyContext.FreetimeException(1, tips)
def charge_data(cls, chargeinfo): appId = chargeinfo['appId'] buttonId = chargeinfo['buttonId'] clientId = chargeinfo['clientId'] userId = chargeinfo['uid'] clientip = TyContext.UserSession.get_session_client_ip(userId) from tysdk.entity.pay_common.fengkong import Fengkong if Fengkong.is_ip_limited(clientip, clientId, 'ydjd'): raise TyContext.FreetimeException( 1, '对不起,您已超出支付限制,请联系客服4008-098-000') paycodes = TyContext.Configure.get_global_item_json('paycodes', clientid=clientId) if paycodes: try: pdata = paycodes['ydjd']['paydata'] for data in pdata: if data['prodid'] == buttonId: break else: raise Exception( 'product %s not found in paycodes(%s) config' % (buttonId, clientId)) cdata = copy.deepcopy(data) del cdata['prodid'] chargeinfo['chargeData'] = cdata except Exception as e: TyContext.ftlog.error( 'TuYouPayYdjd.charge_data->config error:', paycodes, 'exception:', e) raise e return paycodes = TyContext.Configure.get_global_item_json( 'ydjd_paycodes', paycode_dict) if buttonId not in paycodes[str(appId)]: TyContext.ftlog.error('TuYouPayYdjd buttonId', buttonId, 'not configured, paycodes=', paycodes) return paycode = paycodes[str(appId)][buttonId] chargeinfo['chargeData'] = {'msgOrderCode': paycode}
def remove(cls, userId): status = cls.beautyCertifyStatusDao.load(userId) if status is None: raise TyContext.FreetimeException(ERR_REMOVED, '记录已被删除') TyContext.ftlog.info('BeautyCertifyService.remove userId=', userId) cls._remove(status)
def checkUserParam(cls): userId = TyContext.RunHttp.getRequestParamInt('userId') if userId > 0: return userId else: raise TyContext.FreetimeException(1, 'Bad userId')