def convertToMsgPack(self, keys): msg = TyContext.MsgPack() for key in keys: value = self.getRequestParam(key) if value != None: msg.setParam(key, value) return msg
def notifyItemListChange(self, gameId, userId): mo = TyContext.MsgPack() mo.setCmd('item_list') mo.setParam('userId', userId) mo.setParam('gameId', gameId) self.msg = mo self.sendUdpToServerType(mo, userId, 3)
def handel_msg(self, tasklet, msg): mo = TyContext.MsgPack() mo.setCmd(self.cmdname) try: action = msg.getParam('action') mo.setResult('action', action) handler = self.handlers.get(action) if handler: handler(msg, mo) else: mo.setError(1, 'action not found !') except: TyContext.ftlog.exception() mo.setError(1, TyContext.ftlog.format_exc()) mo.setKey('prockey', TyContext.TYGlobal.prockey()) TyContext.ftlog.info('_server_hot_cmd_ response :', mo) if tasklet.protocol and msg.getParam('noresponse') != 1: # 这里出异常会把整个进程卡死,为了安全,多加点异常处理 try: data = TyContext.MsgLine.packstr(tasklet.msgline.udpId, 0, mo.pack()) tasklet.protocol.writeMessage(data, tasklet.udpaddress) except: TyContext.ftlog.exception() try: mo.setError(1, TyContext.ftlog.format_exc()) data = TyContext.MsgLine.packstr(tasklet.msgline.udpId, 0, mo.pack()) tasklet.protocol.writeMessage(data, tasklet.udpaddress) except: TyContext.ftlog.exception()
def notifyUserInfoChange(self, gameId, userId): mo = TyContext.MsgPack() mo.setCmd('user_info') mo.setParam('userId', userId) mo.setParam('gameId', gameId) clientId = TyContext.UserSession.get_session_clientid(userId) if clientId != None: mo.setParam('clientId', clientId) self.msg = mo self.sendUdpToServerType(mo, userId, 2) else: TyContext.ftlog.error('the user sessionClientId is none', userId)
def doPayRequst(self, rpaht): mo = TyContext.MsgPack() params = TyContext.RunHttp.convertArgsToDict() mobile = params.get('mobile', '') platformOrderId = params.get('platformOrderId', '') imsi = params.get('imsi', '') imei = params.get('imei', '') chargeInfo = self.get_charge_info_data(platformOrderId) price = chargeInfo.get('chargeTotal') config = GameItemConfigure(chargeInfo.get('appId')).get_game_channel_configure_by_package('wyxt', chargeInfo[ 'packageName'], chargeInfo[ 'mainChannel']) if not config: package = "com.tuyou.doudizhu.main" channel = 'wyxt' appId = '9999' config = GameItemConfigure(appId).get_game_channel_configure_by_package('wyxt', package, channel) config = config.get('app_config_%s' % price, {}) if not config: mo.setResult('info', '计费点未配置,请检查') mo.setResult('code', 1) return mo postParams = { 'mobile': mobile, 'channelid': config.get('channel_id'), 'app_name': config.get('app_name'), 'itemid': config.get('itemid'), 'imsi': imsi, 'p_price': config.get('price'), 'imei': imei, 'callbackdata': platformOrderId, } try: response, _ = TyContext.WebPage.webget(self.get_order_url, postParams) except: mo.setResult('info', '支付请求失败,请稍后重试') mo.setResult('code', 1) return mo if 'ok' in response: mo.setResult('info', '支付请求成功') mo.setResult('code', 0) else: mo.setResult('info', '支付请求失败,请稍后重试') mo.setResult('code', 1) return mo
def doSetUserInfo(cls, rparams, mo, needReturn=True): TyContext.ftlog.info(cls.__name__, 'doSetUserInfo->rparams=', rparams, 'needReturn=', needReturn) userId = rparams.get('userId', 0) if userId <= 0: return nickname = rparams.get('name', '') sex = str(rparams.get('sex', '')) headurl = rparams.get('headurl', '') address = rparams.get('address', '') idcardno = rparams.get('idcardno', '') truename = rparams.get('truename', '') phonenumber = rparams.get('phonenumber', '') lang = rparams.get('lang', None) country = rparams.get('country', None) signature = rparams.get('signature', None) agreeAddFriend = rparams.get('agreeAddFriend', None) email = rparams.get('email', None) snsinfo = rparams.get('snsinfo', None) datas = [] if len(address) > 0: datas.append('address') datas.append(address) if len(idcardno) > 0: datas.append('idcardno') datas.append(idcardno) if len(truename) > 0: datas.append('truename') datas.append(truename) if len(phonenumber) > 0: datas.append('phonenumber') datas.append(phonenumber) if lang != None: datas.append('lang') datas.append(lang) if country != None: datas.append('country') datas.append(country) if signature != None: datas.append('signature') datas.append(TyContext.KeywordFilter.replace(signature)) if agreeAddFriend != None: if agreeAddFriend == '0' or agreeAddFriend == '1': datas.append('agreeAddFriend') datas.append(int(agreeAddFriend)) if email != None: datas.append('email') datas.append(email) if snsinfo != None: datas.append('snsinfo') datas.append(snsinfo) if len(sex) > 0 and sex in ('0', '1'): datas.append('sex') datas.append(sex) oldSex = TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'sex') if oldSex == None: oldSex = sex if int(oldSex) != int(sex): BeautyCertifyService.onUserSexChanged(userId, oldSex, sex) TyContext.ftlog.debug('nickname=[', nickname, ']') oldname = TyContext.RedisUser.execute(userId, 'HGET', 'user:'******'name') ''' if nickname == "LikaiAndZengxinxin" and TyContext.TYGlobal.corporation() == "pineapple": pass ''' if len(nickname) > 0: newNameIs360Default = Account360.isDefault360Username(nickname) if newNameIs360Default: TyContext.ftlog.debug('nickname=[', nickname, '] oldname=[', oldname, '] sex=[', sex, ']') if not oldname or Account360.isDefault360Username(oldname): if sex not in ('0', '1'): sex = TyContext.RedisUser.execute( userId, 'HGET', 'user:'******'sex') TyContext.ftlog.debug('nickname=[', nickname, '] oldname=[', oldname, '] oldsex=[', sex, ']') nickname = UsernameGenerator.getInstance().generate(sex) # 设定 else: # 保持原名字 nickname = None else: # 设定 pass if nickname != None: # todo for 104 test add by tcz mo_tmp = TyContext.MsgPack() UsernameGenerator.change_old_user_name(nickname, userId, mo_tmp) if str(mo_tmp.getResult('code')) != '0': mo.setResult('code', mo_tmp.getResult('code')) mo.setResult('info', mo_tmp.getResult(('info'))) return datas.append('name') datas.append(nickname) # 需要根据不同的游戏ID做屏蔽是否不再允许再次更改.(appId 1-19)appId 为 12和15仍可以通过此接口修改名称(大菠萝,海外德州) accessAppId = TyContext.Configure.get_global_item_json( 'change_nickname_appId', [12, 15]) appId = int(rparams.get('appId', '0')) if not appId in accessAppId and oldname != nickname and needReturn: TyContext.RedisUser.execute(userId, 'HINCRBY', 'user:'******'set_name_sum', 1) if len(headurl) > 0: UserPhotoService.setUserPhoto(userId, UserPhoto.PHOTO_TYPE_AVATAR, headurl) if len(datas) > 0: TyContext.RedisUser.execute(userId, 'HMSET', 'user:' + str(userId), *datas) if needReturn: cls.__set_user_info_return__(rparams, mo)