lua網路資料請求過程
阿新 • • 發佈:2019-02-15
1.ResponseController 註冊訊息 -- 定向抽卡 commandFuncMap[ CommandTypes.ClarityDrawState ] = function( commandId, buffer ) local data = ClarityDrawStateResponse:create() data:readFromBuffer( buffer ) return data end -- 請求抽卡 commandFuncMap[ CommandTypes.ClarityDrawStart ] = function( commandId, buffer ) local data = ClarityDrawStartResponse:create() data:readFromBuffer( buffer ) if data.errorNo == ErrorNo.NO_ERROR then PropService:updatePropList( data.propChange ) PlayerService:updateMoney( data.moneyChange ) end return data end 2.向伺服器傳送請求 function MainScene:levelCallBack( sender, type ) local msg = LevelGiftRewardRequest:create() NetManager:sendHttpRequest( msg, true ) end 3.得到伺服器返回的資料data commandId == CommandTypes.LevelGiftReward then if data.errorNo == ErrorNo.NO_ERROR then local dialog = ActivityFastView:create( self, data.levelGiftItem ) UIManager:openDialog( dialog ) UI.setVisible( self.levelTips, false ) end 4.從伺服器返回得到的data資料中的東西顯示在介面上。 function ActivityFastView:create( parent, activityList ) local view = ActivityFastView:new() view:__init( parent, activityList ) return view end