|
- -- PHP文档地址,用户名:dd 密码:ddtech
- -- http://120.76.238.236:8999/wiki/index.php?title=%E9%A6%96%E9%A1%B5
- local ProtocolPhp = class("ProtocolPhp")
-
- local UserCmd = {
- PHP_USER_LOGIN = "user.login", -- 登录PHP
- PHP_USER_KEEPALIVE = "user.keepalive", -- 保持会话
- PHP_SHOP_INFO = "shop.info", -- 商城列表
- PHP_SHOP_BUY = "shop.buy", -- 购买商品
- PHP_SHOP_ORDER = "order.unified", -- 获取订单号
- PHP_SHOP_RECEIPT = "order.receipt", -- 支付成功后发送给服务器验证订单
- PHP_ZHANJI_INFO = "gamb.info", -- 战绩数据
- PHP_ZHANJI_LIST = "gamb.lists", -- 战绩总数据
- PHP_ZHANJI_DETAIL = "gamb.deatailall", -- 单局战绩数据
- PHP_GET_DIAMOND_SPECIAL = "user.propsInfo", -- 获取专用房卡
- PHP_REPORT_GAME_VER = "report.games", --上报子游戏版本
-
- PHP_LAXIN_MAIN = "invite.inviter", --拉新人主命令
- PHP_LAXIN_SUB_FIRST_SHARE = "invite.getPrize", --拉新每日首次分享
- PHP_LAXIN_SUB_RIGISTER_PLAY_AWARD = "invite.receiveInviter", --拉新注册玩牌奖励
- PHP_LAXIN_SUB_GET_MONEY = "invite.withdraw", --邀请红包提现/召回红包提现
- PHP_LAXIN_SUB_EXCHANGE = "invite.exchange", --邀请红包兑换
- PHP_LAXIN_SUB_PIC_LINK = "invite.getShareImg", --请求分享的下载图片
- PHP_GET_KEFU = "kefu.kf5", --获取客服地址
- PHP_REDDOT = "reddot.getUserReddot", -- 获取红点
- PHP_READ_MESSAGE = "reddot.setUserReddot", -- 读取红点消息
- PHP_REPORT_SOCIAL = "report.social", -- 上报第三方账号的绑定情况
-
- PHP_GET_ALLOW_CLUB = "chaguanset.getallowchaguan", -- 查询屏蔽茶馆邀请状态
- PHP_SET_ALLOW_CLUB = "chaguanset.setallowchaguan", -- 设置屏蔽茶馆邀请状态
- }
-
- local function getImageNameByUrl(url)
- local url2 = string.gsub(url, "//", "/")
- local tt = string.split(url2, "/")
- local imageName = tt[#tt]
- return imageName
- end
-
- function ProtocolPhp:ctor()
- -- 添加分发事件的组件
- cc.GameObject.extend(self)
- self:addComponent(require("luaScript.cc.components.behavior.EventProtocol"):new()):exportMethods()
-
- self.phpUrl = getGlobalPhpUrl()
-
- -- 房卡充值数据
- self.shopData = nil
-
- -- 房卡充值记录
- self.shopRecordData = nil
-
- -- 金币商城数据
-
- -- 活动数据
- self.activityData = nil
-
- -- 实名认证数据
- self.shimingData = nil
-
- -- 邀请码数据
- self.inviteCodeData = nil
-
- -- 是否登录了
- self.islogin = nil
-
- --背包数据
- self.baginfodata = nil
-
- --自己的道具数据
- self.mypropdata = nil
-
- -- 代理微信
- --[[
- self.daili =
- {
- [-1] = {"xxxx",xxxx}, -- -1 通用
- [0] = {"xxxx",xxxx}, -- 0 大厅
- [1] = {"xxxx",xxxx}, -- 子游戏1
- [2] = {"xxxx",xxxx}, -- 子游戏2
- ...
- }
- --]]
- self.daili = {}
-
- self.online = {
- twoHour = 2*60*60, --多少小时触发事件
- fiveHour = 5*60*60, --多少小时触发事件
- updateTime = 5, --多少秒记录一次
- }
-
- end
-
- function ProtocolPhp:getResolution()
- local win = cc.Director:getInstance():getWinSize()
- local resolution = string.format("%d*%d", win.width, win.height)
- return resolution
- end
-
- function ProtocolPhp:getOS()
- local osStr = "windows"
- if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_WINDOWS then
- osStr = "windows"
- elseif cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_MAC then
- osStr = "mac"
- elseif cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then
- osStr = "android"
- elseif cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_IPHONE then
- osStr = "iphone"
- elseif cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_IPAD then
- osStr = "ipad"
- end
- return osStr
- end
-
- -- 请求保持在线
- function ProtocolPhp:keepalive()
-
- local tt =
- {
- action = UserCmd.PHP_USER_KEEPALIVE,
- token = app.user.loginInfo.token,
- uid = app.user.loginInfo.uid,
- }
- logD("ProtocolPhp:keepalive()", table.tostring(tt))
- httpPost(self.phpUrl, tt, handler(self, self.onKeepAliveResponse))
- end
-
- -- 请求保持在线结果
- function ProtocolPhp:onKeepAliveResponse(status, response)
- logD("ProtocolPhp:onKeepAliveResponse()", status, response)
-
- if status ~= "successed" then
- self:login()
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- self:login()
- return
- end
-
- app.mainScene:runActions(cc.DelayTime:create(300), function()
- self:keepalive()
- end);
- end
-
- -- 请求登录
- function ProtocolPhp:login()
-
- local tt = {}
- tt.action = UserCmd.PHP_USER_LOGIN --//接口名
- tt.app = getAppId() --//应用ID
- tt.platform_id = app.user.unionid -- 平台ID,微信登录获取的 unionid微信则为:微信授权ID
- tt.platform_type = 1 --//平台类型,1为微信
- tt.uid = app.user.loginInfo.uid --//用户ID
- tt.channel = getChannelId() --//渠道号
- tt.token = app.user.loginInfo.token --//svr生成的32字节字符串,用于唯一验证客户端有消息
- -- 后端新收集的数据
- tt.nickname = app.user.nickname or "";
- tt.headimgurl = app.user.headimgurl or "";
- tt.sex = app.user.sex or 0;
- tt.access_token = app.user.access_token or "";
- tt.refresh_token = app.user.refresh_token or "";
-
- local appVersion = getAppVersionNum()
- local resVersion = loadVersion()
- local versionInfo = string.format(appVersion.."."..resVersion )
-
- tt.version = versionInfo --//客户端版本号
- tt.device = getDeviceID(); --//设备唯一标识,如有则传,无则无需传输
- tt.mac = getWifiMAC(); --//mac地址
- tt.network = getNetworkType(); --//1:WIFI 2:2G 3:3G 4:4G
- tt.resolution = self:getResolution() --//分辨率
- tt.machine_type = getLocalizedModel() --//机型
-
- local sysVersion = getSystemVersion();
- local sysName = getSystemName();
- local osStr = string.format(sysName..sysVersion);
-
- tt.os = osStr --//移动终端设备操作系统
- logD("ProtocolPhp:login() tt = ", table.tostring(tt))
-
- -- 校验微信信息的有效性
- self:checkWxInfoValilable()
-
- httpPost(self.phpUrl, tt, handler(self, self.onLoginResponse))
- end
-
- -- 登录结果
- function ProtocolPhp:onLoginResponse(status, response)
- logD("ProtocolPhp:onLoginResponse()", status, response)
- if status ~= "successed" then
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- return
- end
-
- -- 获取广告配置
- -- self:getAdsConfig();
-
- --请求商城数据
- -- app.phpShop:getShopInfo()
-
- -- 请求获取商城购买记录
- -- app.phpShop:requestGetShopRecord();
-
- -- 请求活动数据
- -- self:requestGetActivityInfo()
-
- -- 请求实名认证数据
- -- self:requestGetShiMingInfo()
-
- -- 请求邀请码数据
- -- self:requestGetInviteCodeInfo();
-
- -- 请求实名认证数据
- app.php:requestGetShiMingInfo()
-
- --拉取游戏红点
- if app.config.ModuleConfig.IsSupportRedPoint then
- self:requestActivityRedPoint()
- end
-
- local registerTime = data.result.user.join or 0
- saveUserInfo("userRegisterTime",registerTime)
-
- local rank = data.result.game.lvl or 1
- saveUserInfo("userRank",rank)
- -- 悠闲豆
- app.user.loginInfo.curBeanNum = data.result.game.beans or 0
- -- 礼券
- app.user.loginInfo.curLiquanNum = data.result.game.coupons or 0
-
- --账号注销状态
- app.user.logOut = {}
- app.user.logOut.logOutTime = data.result.user.endtime
- app.user.logOut.status = data.result.user.cancel
- app.user.logOut.imgUrl = data.result.user.imgUrl
-
- if app.user.logOut.status == 1 then
- app:dispatchEvent({name = "LOGOUT_TIPS"});
- end
-
- local iconUrl, iconTime = convertIconUrl(app.user.logOut.imgUrl)
- local iconFile = getImageNameFromUrl(iconUrl)
- getImageFromUrlWithTime(iconUrl, iconFile, tonumber(iconTime), function(ret)
-
- end)
-
- --自己道具信息
- self.mypropdata = data.result.prop or {}
-
- self.islogin = 1
-
- self.daili = {}
-
- -- 大厅客服微信
- if data.result and data.result.agent and data.result.agent.wechat and type(data.result.agent.wechat) == "table" then
- local t = {}
- for kk,vv in pairs(data.result.agent.wechat) do
- table.insert(t, vv);
- end
- self.daili[0] = t;
- end
- -- 子游戏代理微信
- if data.result and data.result.agent and data.result.agent.games and type(data.result.agent.games) == "table" then
- for k,v in pairs(data.result.agent.games) do
- local t = {}
- for kk, vv in pairs(v) do
- table.insert(t, vv);
- end
- self.daili[tonumber(k)] = t;
- end
- end
-
-
- --启动支付插件
- app.plugin:startIosPay()
-
- --登录时获取道具配置
- app.serverConfigs:requestClientConfig()
-
- -- 发送登录成功的事件
- app:dispatchEvent({name = "PHP_LGIN_SUCCESSED"});
-
- self:dispatchEvent({name = "getwetChatConfigResponse"})
-
- self.currTime = os.time()
-
- app.mainScene:runDelay(300, function()
- self:keepalive();
- end)
- end
-
- function ProtocolPhp:resetCheckOnline()
- self.isCheckTime = false
- self:checkOnline()
- end
-
- function ProtocolPhp:checkOnline()
- if self.isCheckTime then
- return
- end
- self.isCheckTime = true
-
- self.onlineTData = self:loadGameInfoFromFile()
- self.curDay = os.date("%Y%m%d");
- if self.onlineTData and self.onlineTData[self.curDay] then
- self.curTimeElapse = self.onlineTData[self.curDay].time or 0
- else
- self.curTimeElapse = 0;
- end
-
- local function showTime()
- if isWin32Platform() then
- local hour = math.floor(self.curTimeElapse/3600)
- local min = math.floor((self.curTimeElapse - hour * 3600)/60)
- local sec = math.floor(self.curTimeElapse - hour * 3600 - min * 60)
- local str = string.format("用户已经在线:%d小时%d分%d秒",hour,min,sec);
- local view = app:getCurrentView()
- local name = view and view.__cname
- if name == "MainView" or name == "LoginView" then
- showTooltip(str)
- else
- showTooltip("消息:用户在房间了!")
- end
- end
- end
-
- local action = cc.RepeatForever:create(cc.Sequence:create(cc.DelayTime:create(self.online.updateTime), cc.CallFunc:create(function()
- self:checkIsAdult()
- end)))
-
- action:setTag(20200408)
- app.mainScene:runActions(action)
- end
-
- function ProtocolPhp:checkIsAdult()
- self.curTimeElapse = self.curTimeElapse + self.online.updateTime
- --每到达一个60秒的倍数保存一次在线时间。
- if self.curTimeElapse % 60 == 0 then
- self:saveGameInfoToFile(self.curDay,self.curTimeElapse)
- end
-
- local view = app:getCurrentView()
- local name = view and view.__cname
-
- if self.curTimeElapse >= self.online.fiveHour then
- if self.shimingData.card == "" and name == "MainView" or name == "LoginView" then
- if toNumber(self.shimingData.certification) ~= -1 and not app.php.inShiMingView then
- local view = import("luaScript.Views.Main.NoticeShiMingTip"):new()
- view:setAnchorPoint(cc.p(0.5,0.5))
- app:showWaitDialog(view,0)
- app.mainScene:stopActionByTag(20200408)
- self:saveGameInfoToFile(self.curDay,self.curTimeElapse)
- return
- end
- end
- end
-
- if self.curTimeElapse >= self.online.twoHour and self.shimingData.card ~= "" then
- if self:getIsYoungPeople() and name == "MainView" or name == "LoginView" then
- if toNumber(self.shimingData.isAdult) ~= -1 then
- app.mainScene:stopActionByTag(20200408)
- self:saveGameInfoToFile(self.curDay,self.curTimeElapse)
- local hour
- if app.php.online.fiveHour % 3600 == 0 then
- hour = math.floor(app.php.online.twoHour/3600)
- else
- hour = string.format("%.2f",app.php.online.twoHour/3600)
- end
- local tip = "您好,因为您是未成年用户,您的游戏时长已超过"..tostring(hour).."小时,为了保证您的身心健康请退出游戏休息一下吧!"
- local function okCallBack()
- cc.Application:getInstance():shutdown();
- end
- showConfirmDialog(tip,okCallBack)
- return
- end
- end
- end
- end
-
- function ProtocolPhp:getIsYoungPeople()
- local card = self.shimingData.card..""
- local birthYear = string.sub(card,7,10)
- local curYear = os.date("%Y");
- local distance = math.abs(curYear - birthYear)
- return distance < 18
- end
-
- -- 从本地读取今天已经在线的游戏时长
- function ProtocolPhp:loadGameInfoFromFile()
- local locString = loadStringFromFile("onlineData.json")
- if not locString or locString == "" then
- return nil
- end
- local locData = json.decode(locString)
- if locData then
- return locData
- end
- return nil
- end
-
- -- 记录某一天的在线时长,每一分钟记录一次
- function ProtocolPhp:saveGameInfoToFile(curDay,curTimeElapse)
- if not curDay or not curTimeElapse then
- return
- end
- local tt = {}
- tt[curDay] = {
- time = curTimeElapse,
- }
- local locString = json.encode(tt)
- saveStringToFile(locString,"onlineData.json")
- end
-
- -- 获取活动数据
- function ProtocolPhp:requestGetActivityInfo()
- local tt =
- {
- action= "tasks.getList",
- uid = app.user.loginInfo.uid,
- apkver = getAppVersion(),
- app = getAppId(),
- --token = app.user.loginInfo.token,
- }
- logD("ProtocolPhp:requestGetActivityInfo()", table.tostring(tt))
- httpPost(self.phpUrl, tt, handler(self, self.onGetActivityInfoResponse))
- end
-
- function ProtocolPhp:onGetActivityInfoResponse(status, response)
- logD("ProtocolPhp:onGetActivityInfoResponse()", status, response)
- if status ~= "successed" then
- logE("活动数据拉取失败")
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- logE("活动数据错误")
- return
- end
- logD("ProtocolPhp:onGetActivityInfoResponse() data = ", table.tostring(data))
-
- self.activityData = data.result
-
- app:dispatchEvent({name = "onGetActivityInfoResponse"})
- app:dispatchEvent({name = "onGetHongBaoKaInfoResponse"})
- end
-
- -- 获取背包数据
- function ProtocolPhp:requestGetBagInfo(ptype)
- if not ptype then
- ptype = 0
- end
- local tt =
- {
- action= "prop.knapsack",
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- token = app.user.loginInfo.token,
- prop_type = ptype
- }
- app.waitDialogManager:showWaitNetworkDialog();
- logD("ProtocolPhp:requestGetActivityInfo() data = ", table.tostring(tt))
- httpPost(self.phpUrl, tt, handler(self, self.onGetBagInfoResponse))
- end
-
- function ProtocolPhp:onGetBagInfoResponse(status, response)
- app.waitDialogManager:closeWaitNetworkDialog();
- logD("ProtocolPhp:onGetBagInfoResponse()", status, response)
- if status ~= "successed" then
- logE("背包数据拉取失败")
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- logE("背包数据错误")
- return
- end
- logD("ProtocolPhp:onGetBagInfoResponse() data = ", table.tostring(data))
-
- self.baginfodata = data.result.list
-
- app:dispatchEvent({name = "onGetBagInfoResponse"})
- end
-
-
- function ProtocolPhp:requestBagOperate(pid,ptype,gid)
- if not gid then
- gid = 0
- end
- local params =
- {
- action = "prop.setup",
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- token = app.user.loginInfo.token,
- prop_id = pid,
- type = ptype,
- gid = gid,
- }
- app.waitDialogManager:showWaitNetworkDialog();
- httpPost(self.phpUrl, params, handler(self, self.onBagOperateResponse))
- end
-
- function ProtocolPhp:onBagOperateResponse(status, response)
- if status ~= "successed" then
- return
- end
- local ttResposne = json.decode(response)
- if not ttResposne then
- return
- end
- app.waitDialogManager:closeWaitNetworkDialog();
- -- 200成功
- if ttResposne.code == 200 then
- logD("onBagOperateResponse:",table.tostring(ttResposne));
- self.mypropdata = ttResposne.result
- app:dispatchEvent({name = "onBagOperateResponse"});
- else
- showTooltip("商品使用失败!");
- end
- end
-
-
- -- 获取实名认证数据
- function ProtocolPhp:requestGetShiMingInfo()
- local tt =
- {
- action= "identity.get",
- uid = app.user.loginInfo.uid,
- }
- httpPost(self.phpUrl, tt, handler(self, self.onGetShiMingInfoResponse))
- end
-
- function ProtocolPhp:onGetShiMingInfoResponse(status, response)
- logD("ProtocolPhp:onGetShiMingInfoResponse()", status, response)
- if status ~= "successed" then
- logE("实名认证拉取失败")
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- logE("实名认证数据错误")
- return
- end
- logD("ProtocolPhp:onGetShiMingInfoResponse() data = ", table.tostring(data))
-
- self.shimingData = data.result;
-
- if self.shimingData.certification~= -1 then
- self.online.fiveHour = self.shimingData.certification
- end
-
- if self.shimingData.isAdult ~= -1 then
- self.online.twoHour = self.shimingData.isAdult
- end
-
- self:checkOnline()
-
- app:dispatchEvent({name = "onGetShiMingInfoResponse"})
- end
-
- -- 请求实名认证
- function ProtocolPhp:requestBindShiMing(name, identity)
- local tt =
- {
- action= "identity.auth",
- uid = app.user.loginInfo.uid,
- card = identity,
- name = name,
- appId = getAppId()
- }
-
- logD("发送绑定身份证数据:"..table.tostring(tt))
-
- app.waitDialogManager:showWaitNetworkDialog("认证中....");
- httpPost(self.phpUrl, tt, function(status, response)
- self:onBindShiMingResponse(status, response, name, identity)
- end)
- end
-
- -- 请求实名认证结果
- function ProtocolPhp:onBindShiMingResponse(status, response, name, identity)
-
- app.waitDialogManager:closeWaitNetworkDialog();
-
- logD("ProtocolPhp:onBindShiMingResponse()", status, response)
- if status ~= "successed" then
- logE("实名认证失败")
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- logE("实名认证数据错误")
- local errStr =
- {
- [1100] = "参数错误",
- [1101] = "您填写的姓名跟身份证不匹配,请重新填写",
- [1102] = "已验证",
- [1103] = "您填写的姓名跟身份证不匹配,请重新填写",
- [1104] = "查询失败!",
- }
- showTooltip(errStr[data.code] or "未知错误 "..tostring(data.code))
- return
- end
- logD("ProtocolPhp:onBindShiMingResponse() data = ", table.tostring(data))
-
- self.shimingData = {}
- self.shimingData.name = name
- self.shimingData.card = identity
- self.shimingData.isAdult = data.result.isAdult
- --如果是未成年,实名认证后,重置在线时长
- if self:getIsYoungPeople() then
- self.curTimeElapse = 0
- self:saveGameInfoToFile(self.curDay,0)
- self:resetCheckOnline()
- end
-
- app:dispatchEvent({name = "onBindShiMingResponse"})
- end
-
- -- 获取邀请码数据
- function ProtocolPhp:requestGetInviteCodeInfo()
- local tt =
- {
- action= "invite.check",
- app = getAppId(),
- uid = app.user.loginInfo.uid,
- token = app.user.loginInfo.token,
- }
- httpPost(self.phpUrl, tt, handler(self, self.onGetInviteCodeInfoResponse))
- end
-
- function ProtocolPhp:onGetInviteCodeInfoResponse(status, response)
- logD("ProtocolPhp:onGetInviteCodeInfoResponse()", status, response)
- if status ~= "successed" then
- logE("邀请码数据拉取失败")
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- logE("邀请码数据错误")
- return
- end
- logD("ProtocolPhp:onGetInviteCodeInfoResponse() data = ", table.tostring(data))
-
- self.inviteCodeData = data.result;
-
- app:dispatchEvent({name = "onGetInviteCodeInfoResponse"})
- end
-
- -- 请求绑定邀请码
- function ProtocolPhp:requestBindInviteCode(inviteCode)
- local tt =
- {
- action= "invite.bind",
- app = getAppId(),
- uid = app.user.loginInfo.uid,
- token = app.user.loginInfo.token,
- code = inviteCode,
- }
- httpPost(self.phpUrl, tt, function(status, response)
- self:onBindInviteCodeResponse(status, response, inviteCode)
- end)
- end
-
- function ProtocolPhp:onBindInviteCodeResponse(status, response, inviteCode)
- logD("ProtocolPhp:onBindInviteCodeResponse()", status, response)
- if status ~= "successed" then
- logE("绑定邀请码失败1")
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- logE("绑定邀请码失败2")
- if data and data.error then
- showTooltip(data.error)
- end
- return
- end
- logD("ProtocolPhp:onBindInviteCodeResponse() data = ", table.tostring(data))
-
- self.inviteCodeData.code = inviteCode
-
- if data.result and data.result.card then
- app.user.loginInfo.curCardNum = data.result.card
- end
-
- app:dispatchEvent({name = "onBindInviteCodeResponse", data = data.result})
- end
-
- -- 获取广告配置
- function ProtocolPhp:getAdsConfig()
- local ttParams =
- {
- action = "slide.ads",
- app = getAppId(),
- uid = app.user.loginInfo.uid,
- apkver = getAppVersion(),
- }
- httpPost(self.phpUrl, ttParams, handler(self, self.getAdsConfigResponse))
- end
- --[[
- "code":200,
- "error":"",
- "result":{
- //排序ID url:图片地址 code:跳转地址 cmd为跳转界面,params为定义参数,特定界面使用。如:1为创建房间,params:{"jushu":20,"mode":"classic"} 局数为20局,模式为经典场
- 1:{"url":"www.xxx.com/x.png","jump":{"cmd":1,"param":{"xx":"xx"}}},
- 2:{"url":"www.xxx.com/x.png","jump":{"cmd":1,"param":{"xx":"xx"}}},
- 3:{"url":"www.xxx.com/x.png","jump":{"cmd":1,"param":{"xx":"xx"}}}
- },
- ]]
- function ProtocolPhp:getAdsConfigResponse(status, response)
- local ret, ttResult = checkPhpResponse(status, response)
- if not ret then
- logD("ProtocolPhp:getAdsConfigResponse() status = ", table.tostring(status))
- logD("ProtocolPhp:getAdsConfigResponse() response = ", table.tostring(response))
- --showPHPFailedResult(tostring(ttResult))
- return
- end
- logD("ProtocolPhp:getAdsConfigResponse()", table.tostring(ttResult))
-
- local imageCount = 0;
- local function onDownloadImageEnd()
- imageCount = imageCount - 1
- if imageCount <= 0 then
- self:dispatchEvent({name = "getAdsConfigResponse"})
- end
- end
-
- self.listAds = {}
- for k, v in pairs(ttResult) do
- local jump = v.jump;
- local url,time = convertIconUrl(v.url)
- local fileName = getImageNameFromUrl(url)
-
- imageCount = imageCount + 1
- getImageFromUrlWithTime(url, fileName, time, onDownloadImageEnd)
-
- table.insert(self.listAds, {idx = k, url = url, fileName = fileName, jump = jump})
- end
-
- logD("ProtocolPhp:getAdsConfigResponse()", table.tostring(self.mapAds))
- end
-
- -- 获取绑定手机的验证码
- function ProtocolPhp:requestBindPhoneProvingCode(phoneNumber)
- local params =
- {
- action = "sms.authToken",
- uid = app.user.loginInfo.uid,
- phone = tostring(phoneNumber),
- app = getAppId(),
- }
- httpPost(self.phpUrl, params, handler(self, self.onBindPhoneProvingCodeResponse))
- end
-
- function ProtocolPhp:onBindPhoneProvingCodeResponse(status, response)
- if status ~= "successed" then
- return
- end
- local ttResposne = json.decode(response)
- if not ttResposne then
- return
- end
- -- 200成功,5001手机号为空,5002手机格式错误
- if ttResposne.code ~= 200 then
- local tt =
- {
- [5001] = "手机号不能为空",
- [5002] = "手机格式错误",
- }
- showTooltip(tt[ttResposne.code] or "errCode = " .. tostring(ttResposne.code))
- return
- end
- showTooltip("验证码已发送,请注意查收短信")
- end
-
- -- 请求分享奖励
- function ProtocolPhp:requestGetShareReward()
- local params =
- {
- action = "missions.setshareflag",
- uid = app.user.loginInfo.uid,
- token = app.user.loginInfo.token,
- app = getAppId(),
- }
- httpPost(self.phpUrl, params, handler(self, self.onGetShareRewardResponse))
- end
-
- function ProtocolPhp:onGetShareRewardResponse(status, response)
- if status ~= "successed" then
- return
- end
- local ttResposne = json.decode(response)
- if not ttResposne then
- return
- end
- --result.flag 1操作成功0参数错误-1已设置-2服务器错误请重试
- --result.card 总房卡,成功时才返回
- --result.add 增加的房卡数
- if ttResposne.result then
- if ttResposne.result.flag == 1 then
- if ttResposne.result.card then
- app.user.loginInfo.curCardNum = ttResposne.result.card
- app:dispatchEvent({name = "onGetShareRewardResponse", data = ttResposne.result})
- end
- elseif ttResposne.result.flag == -1 then
- app:dispatchEvent({name = "onGetShareRewardResponse", data = ttResposne.result})
- --showTooltip("今日已领取过奖励!")
- else
- print("ProtocolPhp:onGetShareRewardResponse error code:", ttResposne.result.flag)
- end
- end
- end
-
- -- 请求每日登陆奖励
- function ProtocolPhp:requestDailyLoginReward()
- local params =
- {
- action = "missions.logintake",
- uid = app.user.loginInfo.uid,
- token = app.user.loginInfo.token,
- app = getAppId(),
- }
- httpPost(self.phpUrl, params, handler(self, self.onDailyLoginRewardResponse))
- end
-
- function ProtocolPhp:onDailyLoginRewardResponse(status, response)
- app.waitDialogManager:closeWaitNetworkDialog();
- if status ~= "successed" then
- return
- end
- local ttResposne = json.decode(response)
- if not ttResposne then
- return
- end
- --result.flag 1操作成功0参数错误-1已设置-2服务器错误请重试
- --result.card 总房卡,成功时才返回
- --result.add 增加的房卡数
- --result.cday 连续签到的天数
- if ttResposne.result then
- if ttResposne.result.flag == 1 then
- if ttResposne.result.card then
- app.user.loginInfo.curCardNum = ttResposne.result.card
- app:dispatchEvent({name = "onGetDailyaloginRewardResponse", data = ttResposne.result})
- end
- if ttResposne.result.coupons then
- app.user.loginInfo.curLiquanNum = ttResposne.result.coupons
- app:dispatchEvent({name = "onGetDailyaQianDaoRewardResponse", data = ttResposne.result})
- end
- elseif ttResposne.result.flag == -1 then
- showTooltip("今日已经签到过了!")
- end
- end
- end
- --请求分享奖励
- function ProtocolPhp:requestQianDaoShare(callback)
- local userInfo = json.decode(app.user.userInfo);
- local params =
- {
- action = "tasks.logintake",
- uid = app.user.loginInfo.uid,
- token = app.user.loginInfo.token,
- app = getAppId(),
- }
- logD("ProtocolPhp:requestQianDaoShare", table.tostring(params))
- --app.waitDialogManager:showWaitNetworkDialog();
- httpPost(self.phpUrl, params, function (status, strResponse)
- --app.waitDialogManager:closeWaitNetworkDialog();
- if strResponse then
- local data = json.decode(strResponse)
- dump(data,"requestQianDaoShare")
- if data then
- if data.result.coupons then
- app.user.loginInfo.curLiquanNum = data.result.coupons
- end
- if callback then
- callback(data)
- end
- end
-
- end
- end)
- end
-
- --请求红包券兑换记录
- function ProtocolPhp:requestGetHongBaoKaRecord()
- local tt =
- {
- action= "coupon.couponslog",
- uid = app.user.loginInfo.uid,
- type = 1,
- token = app.user.loginInfo.token,
- app = getAppId(),
- }
- httpPost(self.phpUrl, tt, handler(self, self.onGetHongBaoKaRecordResponse))
- end
-
- function ProtocolPhp:onGetHongBaoKaRecordResponse(status, response)
- logD("ProtocolPhp:onGetHongBaoKaRecordResponse()", status, response)
-
- if status ~= "successed" then
- logE("获取充值记录失败")
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- logE("充值记录数据错误")
- return
- end
- logD("ProtocolPhp:onGetHongBaoKaRecordResponse() data = ", table.tostring(data))
-
- self.hongbaokaRecordData = data.result.list;
-
- app:dispatchEvent({name = "onGetHongBaoKaRecordResponse"});
- end
-
-
- --请求红包券获取记录
- function ProtocolPhp:requestDuiHuanHongBaoKaRecord()
- local tt =
- {
- action= "coupon.couponslog",
- uid = app.user.loginInfo.uid,
- type = 2,
- token = app.user.loginInfo.token,
- app = getAppId(),
- }
- httpPost(self.phpUrl, tt, handler(self, self.onDuiHuanHongBaoKaRecordResponse))
- end
-
- function ProtocolPhp:onDuiHuanHongBaoKaRecordResponse(status, response)
- logD("ProtocolPhp:onDuiHuanHongBaoKaRecordResponse()", status, response)
-
- if status ~= "successed" then
- logE("获取充值记录失败")
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- logE("充值记录数据错误")
- return
- end
- logD("ProtocolPhp:onDuiHuanHongBaoKaRecordResponse() data = ", table.tostring(data))
-
- self.duihuanhongbaokaRecordData = data.result.list;
-
- app:dispatchEvent({name = "onDuiHuanHongBaoKaRecordResponse"});
- end
-
- --- ProtocolPhp:requestHongBaoQuanData 获取红包券数据
- function ProtocolPhp:requestHongBaoQuanData()
- local params =
- {
- action = "coupon.index",
- uid = app.user.loginInfo.uid,
- token = app.user.loginInfo.token,
- app = getAppId(),
- }
- httpPost(self.phpUrl, params, handler(self, self.onResponseHongBaoQuanInfo))
- end
-
- --- ProtocolPhp:onResponseHongBaoQuanInfo 获取红包券数据
- -- @param status
- -- @param response
- function ProtocolPhp:onResponseHongBaoQuanInfo(status,response)
- logD("ProtocolPhp:onResponseHongBaoQuanInfo()", status, response)
- if status ~= "successed" then
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- return
- end
- logD("ProtocolPhp:onResponseHongBaoQuanInfo() data = ", table.tostring(data))
-
- self.hongbaoquanData = data.result;
-
- if data.result.coupons then
- app.user.loginInfo.curLiquanNum = data.result.coupons
- end
-
- app:dispatchEvent({name = "onResponseHongBaoQuanInfo"})
- end
-
- --- ProtocolPhp:requestWithdarw 请求提现红包券
- -- @param wallet
- -- @param callback
- function ProtocolPhp:requestWithdarw(wallet,callback)
- if not wallet then
- return
- end
- local params =
- {
- action = "coupon.withdarw",
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- token = app.user.loginInfo.token,
- wallet = wallet,
- }
- httpPost(self.phpUrl, params, function (status, strResponse)
- --app.waitDialogManager:closeWaitNetworkDialog();
- if strResponse then
- local data = json.decode(strResponse)
- dump(data,"ProtocolPhp:onResponseWithdarw()")
- if data then
- if data.result.coupons then
- app.user.loginInfo.curLiquanNum = data.result.coupons
- end
- if callback then
- callback(data)
- end
- end
-
- end
- end)
- end
-
- --- ProtocolPhp:requestExchange 请求红包券兑换钻石
- -- @param ZuanShiNum 钻石数
- function ProtocolPhp:requestExchange(ZuanShiNum)
- if not ZuanShiNum then
- return
- end
- local params =
- {
- action = "coupon.exchange",
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- token = app.user.loginInfo.token,
- num = ZuanShiNum,
- }
- httpPost(self.phpUrl, params, handler(self, self.onResponseExchange))
- end
-
- --- ProtocolPhp:onResponseExchange 请求红包券兑换结果回复
- -- @param status Describe the parameter
- -- @param response Describe the parameter
- function ProtocolPhp:onResponseExchange(status,response)
- logD("ProtocolPhp:onResponseExchange()", status, response)
- if status ~= "successed" then
- return
- end
-
- local data = json.decode(response)
- if not data or type(data) ~= "table" or data.code ~= 200 then
- app:dispatchEvent({name = "onResponseExchangeShiBai"})
- return
- end
- logD("ProtocolPhp:onResponseExchange() data = ", table.tostring(data))
-
- if data.result.coupons then
- app.user.loginInfo.curLiquanNum = data.result.coupons
- end
-
- if data.result.card then
- app.user.loginInfo.curCardNum = data.result.card
- end
- app:dispatchEvent({name = "onResponseExchange",data = data.result} )
- end
-
- --- ProtocolPhp:requestZhengDianJiangli 请求领取整点奖励
- function ProtocolPhp:requestZhengDianJiangli()
- local params =
- {
- action = "tasks.getPrize",
- type = 11,
- uid = app.user.loginInfo.uid,
- token = app.user.loginInfo.token,
- app = getAppId(),
- }
- httpPost(self.phpUrl, params, handler(self, self.onResponseZhengDianJiangli))
- end
- --- ProtocolPhp:onResponseZhengDianJiangli 请求领取正点奖励回复
- -- @param status 状态
- -- @param response
- function ProtocolPhp:onResponseZhengDianJiangli(status, response)
- if status ~= "successed" then
- return
- end
- local ttResposne = json.decode(response)
- if not ttResposne then
- return
- end
- if ttResposne.result then
- if ttResposne.result.coupons then
- app.user.loginInfo.curLiquanNum = ttResposne.result.coupons
- app:dispatchEvent({name = "onResponseGetJiangli", data = ttResposne.result})
- end
- end
- end
- --- ProtocolPhp:requestGetDuiZhanJiangli 请求领取对战奖励
- -- @param JLType 奖励类型
- -- @param callback 回调
- function ProtocolPhp:requestGetDuiZhanJiangli(JLType,callback)
- local params =
- {
- action = "tasks.getPrize",
- type = JLType,
- uid = app.user.loginInfo.uid,
- token = app.user.loginInfo.token,
- app = getAppId(),
- }
- httpPost(self.phpUrl, params, function (status, strResponse)
- --app.waitDialogManager:closeWaitNetworkDialog();
- if strResponse then
- local data = json.decode(strResponse)
- dump(data,"requestGetDuiZhanJiangli")
- if data then
- if data.result.coupons then
- app.user.loginInfo.curLiquanNum = data.result.coupons
- end
- if callback then
- callback(data)
- end
- end
-
- end
- end)
- end
-
- --请求战绩
- function ProtocolPhp:requestZhanjiInfo(zhanjiType)
- local phpAddress = self.phpUrl
- self.fangjianInfo = nil
- self.zhanjiDetail = nil
- self.zhanjiInfoItem = nil
- local tt =
- {
- action= UserCmd.PHP_ZHANJI_LIST,
- app = getAppId(),
- uid = app.user.loginInfo.uid,
- gameid = 2,
- version = getAppVersion(),
- mode = zhanjiType, -- -1:所有游戏
- }
-
- log("ProtocolPhp:requestZhanjiInfo_sendInfo", table.tostring(tt))
-
- httpPost(phpAddress, tt, handler(self, self.responseZhanjiInfo));
- end
-
- function ProtocolPhp:responseZhanjiInfo(status, response)
- --数据结构
- --[[data.result =
- {
- ["gamb"] = {
- ["936"] = {
- ["baseChips"] = 1/3,
- ["detail"] = {
- ["1"] = {
- ["1"] = {
- ["endtime"] = 1511939735,
- ["flag"] = 0,
- ["logid"] = 45,
- ["score"] = {
- ["1014682"] = 6,
- },
- },
- },
- },
- ["endtime"] = 1511940053,
- ["fbound"] = 10,
- ["gameid"] = 3,
- ["gamerule"] = 0,
- ["nbound"] = 10,
- ["roomid"] = 749868,
- ["tgamb"] = {
- ["1014682"] = {
- ["l"] = 0,
- ["w"] = 10,
- },
- },
- ["tscore"] = {
- ["1014682"] = 17,
- },
- },
- }
- ["user"] = {
- ["1014682"] = {
- ["h"] = ,
- ["n"] = 游客1014682,
- ["s"] = 1,
- },
- },
- }--]]
- print("ProtocolPhp:responseZhanjiInfo = "..table.tostring(response))
- if status == "successed" and response then
- local data = json.decode(response)
-
- if not data then
- print(response)
- app:dispatchEvent({name = "zhanjiCallback"});
- return
- end
-
- --返回码检查
- if tonumber(data.code) ~= 200 then
- print("data.code :"..data.code)
- app:dispatchEvent({name = "zhanjiCallback"});
- return
- end
-
- --显示错误信息
- if tostring(data.error) ~= "" then
- print("requestZhanjiInfo error", table.tostring(data.error));
- app:dispatchEvent({name = "zhanjiCallback"});
- return
- end
-
- --数据校验
- if not data.result or type(data.result) ~= "table" then
- app:dispatchEvent({name = "zhanjiCallback"});
- return;
- end
-
- local resultT = {};
- for logId, logInfo in pairs(data.result) do
- logInfo.logid = logId
- table.insert(resultT, logInfo)
- end
-
- table.sort(resultT, function(a, b) return tonumber(a.endtime) > tonumber(b.endtime); end)
-
- print("ProtocolPhp:responseZhanjiInfo = "..table.tostring(resultT))
-
- self.fangjianInfo = {}
- self.zhanjiDetail = {}
- self.zhanjiInfoItem = {}
- self.playerInfo = {};
-
- for k, v in ipairs(resultT) do
- local zhanjiInfoT = {}
- zhanjiInfoT.roomid = v.roomid --房间号
- zhanjiInfoT.fbound = v.fbound --完成的局数
- zhanjiInfoT.nbound = v.nbound --需要完成的局数
- zhanjiInfoT.endtime = v.endtime --完成时间,unix时间戳
- zhanjiInfoT.gameid = v.gameid --游戏ID
- zhanjiInfoT.baseChips = v.baseChips --底分
- zhanjiInfoT.gamerule = v.gamerule --游戏玩法
-
- --牌局输赢情况
- local paijuInfo = {};
- for paiK,paiV in pairs(v.tgamb) do
- local paiInfoT = {}
- paiInfoT.w = paiV.w --赢次数
- paiInfoT.l = paiV.l --输次数
- paijuInfo[paiK] = paiInfoT;
- end
- zhanjiInfoT.tgamb = paijuInfo;
-
- --用户总积分
- local scoreCountInfo = {}
- for scK,scV in pairs(v.tscore) do
- scoreCountInfo[scK] = scV;
- end
- zhanjiInfoT.tscore = scoreCountInfo;
-
- if not self.fangjianInfo then
- self.fangjianInfo = {}
- end
-
- self.fangjianInfo[v.logid] = zhanjiInfoT;
-
- --每轮详细信息
- local detailInfo = {};
- local idx = 1;
- for dK,dV in pairsByKeys(v.detail) do
- for kk,vv in pairsByKeys(dV) do
- local detailT = {}
- detailT.logid = vv.logid --此次小局结束的日志id
- detailT.endtime = vv.endtime --结束时间
- detailT.flag = vv.flag --结束原因
- --单局下的积分
- local scoreT = {}
- for sK,sV in pairs(vv.score) do
- scoreT[sK] = sV
- end
- detailT.score = scoreT;
- detailInfo[idx] = detailT;
- idx = idx + 1;
- end
- end
- if not self.zhanjiDetail then
- self.zhanjiDetail = {}
- end
- self.zhanjiDetail[v.logid] = detailInfo;
-
- --玩家信息
- local pInfo = {};
- for uK,uV in pairsByKeys(v.userinfo) do
- local playerT = {}
- --头像
- local nlen = string.len(uV.head)
- if nlen == 0 then
- playerT.head = ""
- else
- playerT.head = uV.head
- end
- --昵称
- local nlen = string.len(uV.name)
- if nlen == 0 then
- playerT.name = ""
- else
- playerT.name = uV.name
- end
- pInfo[uK] = playerT
- end
- self.playerInfo[v.roomid] = pInfo;
- end
-
- app:dispatchEvent({name = "zhanjiInfo"});
- else
- print("战绩数据获取失败 status = ",table.tostring(status))
- print(response)
- end
- end
-
- function ProtocolPhp:initShareZhanJiToUrl(callback)
- app.serverConfigs:requestClientConfig(function()
- local zhanjiUrl = app.serverConfigs.clientConfig.webgamb or RomSetting.ZhanJiUrl
- if callback then
- callback(zhanjiUrl)
- end
- end)
- end
-
- --获取专用房卡
- -- 返回参数:
- -- {
- -- code: 200,
- -- error: "",
- -- result: {
- -- propsInfo: [
- -- {
- -- id: "2050", // game_id*1000+50为指定游戏的专用房卡
- -- type: "50", // 50为通用房卡;
- -- game_id: 2, // 指定游戏
- -- startTime: "2018-10-23", // 开始有效
- -- endTime: "2018-11-23", // 结束有效
- -- roomcard: "20" // 剩余房卡
- -- }
- -- ]
- -- }
- -- }
- function ProtocolPhp:requestDiamondSpecial(callback)
- local phpAddress = self.phpUrl
- -- self.fangjianInfo = nil
- -- self.zhanjiDetail = nil
- -- self.zhanjiInfoItem = nil
- local tt =
- {
- action= UserCmd.PHP_GET_DIAMOND_SPECIAL,
- app = getAppId(),
- uid = app.user.loginInfo.uid,
- token = app.user.loginInfo.token,
- -- gameid = 2,
- -- version = getAppVersion(),
- -- mode = zhanjiType, -- -1:所有游戏
- }
-
- log("ProtocolPhp:requestDiamondSpecial", table.tostring(tt))
-
- httpPost(phpAddress, tt, function (status, response)
- log("ProtocolPhp:requestDiamondSpecial callback", table.tostring(response))
- if response then
- local jsonResponse = json.decode(response)
- if tonumber(jsonResponse.code) == 200 then
- if jsonResponse.result and jsonResponse.result.propsInfo then
- if callback then callback(jsonResponse.result.propsInfo) end
- else
- if callback then callback({}) end
- end
- end
- end
- end);
- end
-
- -- 邀请新玩家初始化的数据
- function ProtocolPhp:requestLaXinInitData()
- local userInfo = json.decode(app.user.userInfo);
- local tt =
- {
- action= UserCmd.PHP_LAXIN_MAIN,
- uid = app.user.loginInfo.uid,
- nickname = userInfo.nickname,
- app = getAppId(),
- token = app.user.loginInfo.token,
- }
- logD("ProtocolPhp:requestLaXinInitData", table.tostring(tt))
- app.waitDialogManager:showWaitNetworkDialog();
- httpPost(self.phpUrl, tt, function (status, strResponse)
- logD("ProtocolPhp:requestLaXinInitData response", strResponse)
- app.waitDialogManager:closeWaitNetworkDialog();
- if strResponse then
- local response = json.decode(strResponse)
- dump(response)
- if tonumber(response.code) == 200 then
- app:dispatchEvent({name = "HallInviteNewFirend", ret = response.result})
- else
- showTooltip("拉取邀请新玩家数据失败:errCode:",response.code);
- end
- end
- end)
- end
-
-
- function ProtocolPhp:requestLaXinFirstShare(callback)
- local userInfo = json.decode(app.user.userInfo);
- local tt =
- {
- action= UserCmd.PHP_LAXIN_SUB_FIRST_SHARE,
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- token = app.user.loginInfo.token,
- type = 5001,
- }
- logD("ProtocolPhp:requestLaXinFirstShare", table.tostring(tt))
- --app.waitDialogManager:showWaitNetworkDialog();
- httpPost(self.phpUrl, tt, function (status, strResponse)
- --app.waitDialogManager:closeWaitNetworkDialog();
- if strResponse then
- local data = json.decode(strResponse)
- dump(data,"requestLaXinFirstShare")
- if data then
- if callback then
- callback(data)
- end
- end
-
- end
- end)
- end
-
- function ProtocolPhp:requestLaXinRigisterShare(mType,id,callback)
- local userInfo = json.decode(app.user.userInfo);
- local tt =
- {
- action= UserCmd.PHP_LAXIN_SUB_RIGISTER_PLAY_AWARD,
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- token = app.user.loginInfo.token,
- id = id,
- type = mType,
- }
- logD("ProtocolPhp:requestLaXinRigisterShare", table.tostring(tt))
- --app.waitDialogManager:showWaitNetworkDialog();
- httpPost(self.phpUrl, tt, function (status, strResponse)
- --app.waitDialogManager:closeWaitNetworkDialog();
- if strResponse then
- local data = json.decode(strResponse)
- dump(data,"requestLaXinRigisterShare")
- if data and type(data) == "table" then
- if callback then
- callback(data)
- end
- end
- end
- end)
- end
-
- function ProtocolPhp:requestLaXinGetMoney(mType,callback)
- local userInfo = json.decode(app.user.userInfo);
- local tt =
- {
- action= UserCmd.PHP_LAXIN_SUB_GET_MONEY,
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- token = app.user.loginInfo.token,
- type = mType,--5005邀请奖5105召回奖
- }
- logD("ProtocolPhp:requestLaXinGetMoney", table.tostring(tt))
- --app.waitDialogManager:showWaitNetworkDialog();
- httpPost(self.phpUrl, tt, function (status, strResponse)
- --app.waitDialogManager:closeWaitNetworkDialog();
- if strResponse then
- local data = json.decode(strResponse)
- dump(data,"requestLaXinGetMoney")
- if data then
- if callback then
- callback(data)
- end
- end
-
- end
- end)
- end
-
- function ProtocolPhp:requestLaXinExchange(mType,callback)
- local userInfo = json.decode(app.user.userInfo);
- local tt =
- {
- action= UserCmd.PHP_LAXIN_SUB_EXCHANGE,
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- token = app.user.loginInfo.token,
- type = mType,--5005邀请奖5015召回奖
- }
- logD("ProtocolPhp:requestLaXinGetMoney", table.tostring(tt))
- --app.waitDialogManager:showWaitNetworkDialog();
- httpPost(self.phpUrl, tt, function (status, strResponse)
- --app.waitDialogManager:closeWaitNetworkDialog();
- if strResponse then
- local data = json.decode(strResponse)
- dump(data,"requestLaXinGetMoney")
- if data then
- if callback then
- callback(data)
- end
- end
-
- end
- end)
- end
-
- function ProtocolPhp:requestLaXinDownPic(callBack)
- local userInfo = json.decode(app.user.userInfo);
- local tt =
- {
- action= UserCmd.PHP_LAXIN_SUB_PIC_LINK,
- uid = app.user.loginInfo.uid,
- nickname = userInfo.nickname,
- app = getAppId(),
- type = 1,
- token = app.user.loginInfo.token,
- }
- logD("ProtocolPhp:requestLaXinDownPic", table.tostring(tt))
- httpPost(self.phpUrl, tt, function (status, strResponse)
- if strResponse then
- local data = json.decode(strResponse)
- dump(data,"requestLaXinDownPic")
- if data then
- if callBack then
- callBack(data.result.shareImg)
- end
- end
-
- end
- end)
- end
-
- function ProtocolPhp:checkWxInfoValilable()
- logD("ProtocolPhp:checkWxInfoValilable()");
- if not isAndroidPlatform() and not isIOSPlatform() then
- logD("ProtocolPhp:checkWxInfoValilable() return by not android and not ios");
- return
- end
- if not app.user.refresh_token or string.len(app.user.refresh_token) < 10 then
- logD("ProtocolPhp:checkWxInfoValilable() return by invalid refresh_token, refresh_token = ", tostring(app.user.refresh_token));
- return
- end
-
- local PluginConfig = require("preload.PluginConfig")
- local appId = PluginConfig.WeiXin.appId
- local appKey = PluginConfig.WeiXin.appKey
-
- --local url_refresh_token = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s"
- local url_refresh_token = "https://api.weixin.qq.com/sns/oauth2/refresh_token"
- local tt =
- {
- appid = appId,
- grant_type = "refresh_token",
- refresh_token = app.user.refresh_token
- }
- logD("ProtocolPhp:checkWxInfoValilable() tt = ", table.tostring(tt));
-
- httpPost(url_refresh_token, tt, function (status, response)
- logD("ProtocolPhp:checkWxInfoValilable() response = ", tostring(response))
- if response and string.len(response) > 10 then
- local jsonResponse = json.decode(response)
- if jsonResponse then
- local openid = jsonResponse.openid
- local access_token = jsonResponse.access_token
- local refresh_token = jsonResponse.refresh_token
- self:updateWxInfoLatest(openid, access_token)
- end
- end
- end);
- end
-
- function ProtocolPhp:updateWxInfoLatest(openid, access_token)
- logD("ProtocolPhp:updateWxInfoLatest()", openid, access_token);
-
- local PluginConfig = require("preload.PluginConfig")
- local appId = PluginConfig.WeiXin.appId
- local appKey = PluginConfig.WeiXin.appKey
- local permissions = "snsapi_login"
-
- -- "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID"
- local user_info_url = "https://api.weixin.qq.com/sns/userinfo"
- local tt =
- {
- openid = openid,
- access_token = access_token
- }
- logD("ProtocolPhp:updateWxInfoLatest() tt = ", table.tostring(tt));
-
- httpPost(user_info_url, tt, function (status, response)
- logD("ProtocolPhp:updateWxInfoLatest() response = ", tostring(response))
- if response and string.len(response) > 10 then
- local jsonResponse = json.decode(response)
- if jsonResponse then
- if app.user.openid == jsonResponse.openid and app.user.unionid == jsonResponse.unionid then
- if app.user.sex ~= jsonResponse.sex or app.user.nickname ~= jsonResponse.nickname or app.user.headimgurl ~= jsonResponse.headimgurl then
- logD("ProtocolPhp:updateWxInfoLatest() need update wxInfo")
- if isDevMode() then
- showTooltip("need update wxInfo")
- end
-
- app.user.sex = jsonResponse.sex
- app.user.nickname = jsonResponse.nickname
- app.user.headimgurl = jsonResponse.headimgurl
- -- 更新内存中的数据
- app.user:updateUserInfo();
- -- 删除本地的玩家头像
- updatePlayerHeadImage(app.user.loginInfo.uid, app.user.headimgurl)
- -- 更新本地保存的数据
- local tt = {}
- tt.forceCover = true
- app.user:dispatchEvent({name = "updateWxUserInfo",response = tt})
- else
- logD("ProtocolPhp:updateWxInfoLatest() doesn't need update wxInfo")
- if isDevMode() then
- --showTooltip("doesn't need update wxInfo")
- end
- end
- end
- end
- end
- end);
- end
-
- function ProtocolPhp:requestReportGameVer(gameId,ver)
- local userInfo = json.decode(app.user.userInfo);
- local tt =
- {
- action= UserCmd.PHP_REPORT_GAME_VER,
- uid = app.user.loginInfo.uid,
- gameid =gameId,
- app = getAppId(),
- ver = ver
- }
- logD("ProtocolPhp:requestReportGameVer", table.tostring(tt))
- httpPost(self.phpUrl, tt, function (status, strResponse)
- -- if strResponse then
- -- local data = json.decode(strResponse)
- -- dump(data,"requestReportGameVer")
- -- end
- end)
- end
-
-
- function ProtocolPhp:requestKeFuUrl(callback)
- local phpAddress = self.phpUrl
-
- local tt =
- {
- action= UserCmd.PHP_GET_KEFU,
- app = getAppId(),
- uid = app.user.loginInfo.uid,
- token = app.user.loginInfo.token,
- nickname = app.user.nickname,
- phone = app.user.phonenum,
- sex = app.user.sex == 1 and "男" or "女",
- email = "",
- }
-
- logD("ProtocolPhp:requestKeFuUrl", table.tostring(tt))
-
- httpPost(phpAddress, tt, function (status, response)
- logD("ProtocolPhp:requestKeFuUrl callback", table.tostring(response))
- if response then
- local jsonResponse = json.decode(response)
- if tonumber(jsonResponse.code) == 200 then
- if jsonResponse.result and jsonResponse.result.kefuUrl then
- if callback then callback(jsonResponse.result.kefuUrl) end
- else
- if callback then callback() end
- end
- end
- end
- end);
- end
-
-
- function ProtocolPhp:requestActivityRedPoint()
- local params =
- {
- action = UserCmd.PHP_REDDOT,
- token = app.user.loginInfo.token,
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- }
-
- logD("ProtocolPhp:requestActivityRedPoint() ", table.tostring(params))
- httpPost(self.phpUrl, params, function (status, response)
- if status == "successed" then
-
- local data = json.decode(response)
- logD("ProtocolPhp:requestActivityRedPoint response() ", table.tostring(data))
- if data and data.result then
- self.activityRedPoint = data.result.info;
- app.msgManager:init();
- --dump(data.result,"onActivityRedPoint")
- app:dispatchEvent({name = "onActivityRedPoint",response = data.result.info});
- end
- end
- end)
- end
-
- function ProtocolPhp:requestReadRedPoint(messType)
- local params =
- {
- action = UserCmd.PHP_READ_MESSAGE,
- token = app.user.loginInfo.token,
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- type = messType,
- value = 0,
- }
-
- print("ProtocolPhp:requestReadRedPoint() ", 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.result,"onReadRedPoint")
- app:dispatchEvent({name = "onReadRedPoint",response = data.result});
- app:dispatchEvent({name = "onActivityRedPoint"});
- end
- end
- end)
- end
-
- function ProtocolPhp:requestCheckForbidClubInvite()
- local params =
- {
- action = UserCmd.PHP_GET_ALLOW_CLUB,
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- }
- app.waitDialogManager:showWaitNetworkDialog("请稍候...")
- logD("ProtocolPhp:requestCheckForbidClubInvite() ", table.tostring(params))
- httpPost(self.phpUrl, params, function (status, response)
- app.waitDialogManager:closeAllNetWait()
- if status == "successed" then
- local data = json.decode(response)
- if data and data.result then
- logD("ProtocolPhp:requestCheckForbidClubInviteResponse() ", table.tostring(data))
- app:dispatchEvent({name = "onCheckForbidClubInvite",response = data.result});
- end
- end
- end)
- end
-
- function ProtocolPhp:requestSetForbidClubInvite(allow)
- local params =
- {
- action = UserCmd.PHP_SET_ALLOW_CLUB,
- uid = app.user.loginInfo.uid,
- app = getAppId(),
- isallow = allow,
- }
- app.waitDialogManager:showWaitNetworkDialog("请稍候...")
- logD("ProtocolPhp:requestSetForbidClubInvite() ", table.tostring(params))
- httpPost(self.phpUrl, params, function (status, response)
- app.waitDialogManager:closeAllNetWait()
- if status == "successed" then
- logD("ProtocolPhp:requestSetForbidClubInviteResponse() ", table.tostring(response))
- local data = json.decode(response)
- if data and data.result then
- showTooltip("设置成功!")
- end
- end
- end)
- end
-
- return ProtocolPhp
|