|
- --- 金币场相关PHP请求接口
- local PHPCmd = require("luaScript.Protocol.Coin.CoinPhpCmd")
- local CoinData = require("luaScript.Views.Coin.Data.CoinData")
- local CoinEvents = require("luaScript.Views.Coin.Constant.CoinEvents")
- local CoinDefined = require("luaScript.Views.Coin.Constant.CoinDefined")
- local CoinProtocolPhp = class("CoinProtocolPhp")
-
- --- CoinProtocolPhp:ctor
- function CoinProtocolPhp:ctor()
- self.phpUrl = getGlobalPhpUrl()
-
- CoinData.getInstance():reset() -- 第一次初始化实例
- end
-
- --- CoinProtocolPhp:requestGameServerConfig 请求获取游戏等级配置
- function CoinProtocolPhp:requestGameServerConfig()
- local params = {
- action = PHPCmd.PHP_GAME_SERVER_CONFIG,
- app = getAppId(),
- uid = app.user.loginInfo.uid,
- gameVer = ""
- }
-
- for _, gameId in pairs(GAME_IDS) do
- if gameId ~= GAME_IDS.More then
- local ver = app.subGameManager:isInstaller(gameId) and app.subGameManager.GameVersions[gameId] or -1
- params.gameVer = params.gameVer .. gameId .. "," .. ver .. "|"
- end
- end
-
- print("CoinProtocolPhp:requestGameServerConfig() ", table.tostring(params))
- httpPost(
- self.phpUrl,
- params,
- function(status, response)
- if status ~= "successed" then
- return
- end
- local data = json.decode(response)
- if not (data and data.code == 200 and data.result) then
- return
- end
-
- local result = data.result
- logD("CoinProtocolPhp:requestGameServerConfig response :", table.tostring(result))
- local gameData = {}
- gameData.ruleList = {}
- local rankImgType = {}
- for gameid, content in pairs(result) do
- gameData.ruleList[tonumber(gameid)] = content
- for gameRank, v in pairsByKeys(content) do
- local list = string.sub(gameRank, -1)
- local first = string.sub(gameRank, 0, 1)
- local gameRule = tonumber(list)
- first = tonumber(first)
- if gameRule then
- local isSame = false
- for k, rule in ipairs(gameData.ruleList[tonumber(gameid)]) do
- if rule == gameRule then
- isSame = true
- break
- end
- end
- local isSameImg = false
- for k, rule in ipairs(rankImgType) do
- if k == first then
- isSameImg = true
- break
- end
- end
- if not isSame then
- if gameData.ruleList[tonumber(gameid)] and gameData.ruleList[tonumber(gameid)][gameRank] then
- gameData.ruleList[tonumber(gameid)][gameRank].ruleID = gameRule
- end
- end
-
- if not isSameImg then
- rankImgType[first] = v.icon
- end
- end
- end
- end
- logD("CoinProtocolPhp:requestGameServerConfig response22 :", table.tostring(gameData))
- CoinData.getInstance():setGameData(gameData)
-
- --下载图片
- logD("需要下载的图片列表:rankImgType:", table.tostring(rankImgType))
-
- for k, url in pairs(rankImgType) do
- local fileName = "coingame" .. k .. ".png"
- local fullPath = cc.FileUtils:getInstance():getWritablePath() .. fileName
- if not cc.FileSystem:fileExists(fullPath) then
- dowloadImageFile(url, fileName, nil)
- else
- logD(fileName .. "已下载过,无须重复下载!")
- end
- end
- app:dispatchEvent({name = CoinEvents.EVENT_RESPONSE_GAME_SERVER_CONFIG})
- end
- )
- end
-
-
- -- 请求金币游戏活动
- function CoinProtocolPhp:requestCoinGameActivity(id)
- local appVersion = getAppVersionNum()
-
- local params =
- {
- action = PHPCmd.PHP_DAY_FULI,
- apkver = appVersion,
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- }
-
- print("CoinProtocolPhp:requestCoinGameActivity() ", table.tostring(params))
- httpPost(self.phpUrl, params, function (status, response)
- if status == "successed" then
- local data = json.decode(response)
- if data and data.result then
- print("CoinProtocolPhp:requestCoinGameActivityResponse() ", table.tostring(data.result))
- --数据解析,解析为:每日福利,免费金币两个模块。其中每日福利需要排序显示
- local coinGameActivity = data.result
-
- local shareFreeTimes = 0
- for k,v in pairs(data.result) do
- --免费分享的次数
- if v.type == CoinDefined.COIN_GAME_ACTIVITY.TYPE_FREE_COIN then
- shareFreeTimes = toNumber(v.need) - toNumber(v.progrss)
- end
- if v.type == CoinDefined.COIN_GAME_ACTIVITY.TYPE_SHARE_GAME or v.type == CoinDefined.COIN_GAME_ACTIVITY.TYPE_FREE_COIN then
- if v.ext then
- if v.ext.share_pic ~= "" then
- local fileName = getImageNameFromUrl(v.ext.share_pic)
- local fullPath = cc.FileUtils:getInstance():getWritablePath()..fileName
- if not cc.FileSystem:fileExists(fullPath) then
- getImageFromUrlWithTime(v.ext.share_pic, fileName, nil, nil)
- else
- logD(fileName.."已下载过,无须重复下载!");
- end
- v.ext.share_pic = fileName
- end
- end
- end
- end
- coinGameActivity.shareFreeTimes = shareFreeTimes;
- CoinData.getInstance():setGameActivityData(coinGameActivity)
- --logD("requestCoinGameActivity:",table.tostring(self.coinGameActivity))
- app:dispatchEvent({name = CoinEvents.EVENT_RESPONSE_GAME_ACTIVITY_CONFIG,response = data.result});
- end
- end
- end)
- end
-
- function CoinProtocolPhp:requestTaskJiangLi(type,callback)
- local params =
- {
- action = PHPCmd.PHP_DAY_GET_TASK_PRIZE,
- token = app.user.loginInfo.token,
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- type = type,
- }
-
- print("CoinProtocolPhp:requestTaskJiangLi() ", table.tostring(params))
- httpPost(self.phpUrl, params, function (status, response)
- if status == "successed" then
- local data = json.decode(response)
- if data and data.result then
- dump(data,"requestTaskJiangLi")
- if callback then
- callback(data)
- end
- end
- end
- end)
- end
- return CoinProtocolPhp
|