You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1795 lines
50 KiB

  1. -- PHP文档地址,用户名:dd 密码:ddtech
  2. -- http://120.76.238.236:8999/wiki/index.php?title=%E9%A6%96%E9%A1%B5
  3. local ProtocolPhp = class("ProtocolPhp")
  4. local UserCmd = {
  5. PHP_USER_LOGIN = "user.login", -- 登录PHP
  6. PHP_USER_KEEPALIVE = "user.keepalive", -- 保持会话
  7. PHP_SHOP_INFO = "shop.info", -- 商城列表
  8. PHP_SHOP_BUY = "shop.buy", -- 购买商品
  9. PHP_SHOP_ORDER = "order.unified", -- 获取订单号
  10. PHP_SHOP_RECEIPT = "order.receipt", -- 支付成功后发送给服务器验证订单
  11. PHP_ZHANJI_INFO = "gamb.info", -- 战绩数据
  12. PHP_ZHANJI_LIST = "gamb.lists", -- 战绩总数据
  13. PHP_ZHANJI_DETAIL = "gamb.deatailall", -- 单局战绩数据
  14. PHP_GET_DIAMOND_SPECIAL = "user.propsInfo", -- 获取专用房卡
  15. PHP_REPORT_GAME_VER = "report.games", --上报子游戏版本
  16. PHP_LAXIN_MAIN = "invite.inviter", --拉新人主命令
  17. PHP_LAXIN_SUB_FIRST_SHARE = "invite.getPrize", --拉新每日首次分享
  18. PHP_LAXIN_SUB_RIGISTER_PLAY_AWARD = "invite.receiveInviter", --拉新注册玩牌奖励
  19. PHP_LAXIN_SUB_GET_MONEY = "invite.withdraw", --邀请红包提现/召回红包提现
  20. PHP_LAXIN_SUB_EXCHANGE = "invite.exchange", --邀请红包兑换
  21. PHP_LAXIN_SUB_PIC_LINK = "invite.getShareImg", --请求分享的下载图片
  22. PHP_GET_KEFU = "kefu.kf5", --获取客服地址
  23. PHP_REDDOT = "reddot.getUserReddot", -- 获取红点
  24. PHP_READ_MESSAGE = "reddot.setUserReddot", -- 读取红点消息
  25. PHP_REPORT_SOCIAL = "report.social", -- 上报第三方账号的绑定情况
  26. PHP_GET_ALLOW_CLUB = "chaguanset.getallowchaguan", -- 查询屏蔽茶馆邀请状态
  27. PHP_SET_ALLOW_CLUB = "chaguanset.setallowchaguan", -- 设置屏蔽茶馆邀请状态
  28. }
  29. local function getImageNameByUrl(url)
  30. local url2 = string.gsub(url, "//", "/")
  31. local tt = string.split(url2, "/")
  32. local imageName = tt[#tt]
  33. return imageName
  34. end
  35. function ProtocolPhp:ctor()
  36. -- 添加分发事件的组件
  37. cc.GameObject.extend(self)
  38. self:addComponent(require("luaScript.cc.components.behavior.EventProtocol"):new()):exportMethods()
  39. self.phpUrl = getGlobalPhpUrl()
  40. -- 房卡充值数据
  41. self.shopData = nil
  42. -- 房卡充值记录
  43. self.shopRecordData = nil
  44. -- 金币商城数据
  45. -- 活动数据
  46. self.activityData = nil
  47. -- 实名认证数据
  48. self.shimingData = nil
  49. -- 邀请码数据
  50. self.inviteCodeData = nil
  51. -- 是否登录了
  52. self.islogin = nil
  53. --背包数据
  54. self.baginfodata = nil
  55. --自己的道具数据
  56. self.mypropdata = nil
  57. -- 代理微信
  58. --[[
  59. self.daili =
  60. {
  61. [-1] = {"xxxx",xxxx}, -- -1 通用
  62. [0] = {"xxxx",xxxx}, -- 0 大厅
  63. [1] = {"xxxx",xxxx}, -- 子游戏1
  64. [2] = {"xxxx",xxxx}, -- 子游戏2
  65. ...
  66. }
  67. --]]
  68. self.daili = {}
  69. self.online = {
  70. twoHour = 2*60*60, --多少小时触发事件
  71. fiveHour = 5*60*60, --多少小时触发事件
  72. updateTime = 5, --多少秒记录一次
  73. }
  74. end
  75. function ProtocolPhp:getResolution()
  76. local win = cc.Director:getInstance():getWinSize()
  77. local resolution = string.format("%d*%d", win.width, win.height)
  78. return resolution
  79. end
  80. function ProtocolPhp:getOS()
  81. local osStr = "windows"
  82. if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_WINDOWS then
  83. osStr = "windows"
  84. elseif cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_MAC then
  85. osStr = "mac"
  86. elseif cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then
  87. osStr = "android"
  88. elseif cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_IPHONE then
  89. osStr = "iphone"
  90. elseif cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_IPAD then
  91. osStr = "ipad"
  92. end
  93. return osStr
  94. end
  95. -- 请求保持在线
  96. function ProtocolPhp:keepalive()
  97. local tt =
  98. {
  99. action = UserCmd.PHP_USER_KEEPALIVE,
  100. token = app.user.loginInfo.token,
  101. uid = app.user.loginInfo.uid,
  102. }
  103. logD("ProtocolPhp:keepalive()", table.tostring(tt))
  104. httpPost(self.phpUrl, tt, handler(self, self.onKeepAliveResponse))
  105. end
  106. -- 请求保持在线结果
  107. function ProtocolPhp:onKeepAliveResponse(status, response)
  108. logD("ProtocolPhp:onKeepAliveResponse()", status, response)
  109. if status ~= "successed" then
  110. self:login()
  111. return
  112. end
  113. local data = json.decode(response)
  114. if not data or type(data) ~= "table" or data.code ~= 200 then
  115. self:login()
  116. return
  117. end
  118. app.mainScene:runActions(cc.DelayTime:create(300), function()
  119. self:keepalive()
  120. end);
  121. end
  122. -- 请求登录
  123. function ProtocolPhp:login()
  124. local tt = {}
  125. tt.action = UserCmd.PHP_USER_LOGIN --//接口名
  126. tt.app = getAppId() --//应用ID
  127. tt.platform_id = app.user.unionid -- 平台ID,微信登录获取的 unionid微信则为:微信授权ID
  128. tt.platform_type = 1 --//平台类型,1为微信
  129. tt.uid = app.user.loginInfo.uid --//用户ID
  130. tt.channel = getChannelId() --//渠道号
  131. tt.token = app.user.loginInfo.token --//svr生成的32字节字符串,用于唯一验证客户端有消息
  132. -- 后端新收集的数据
  133. tt.nickname = app.user.nickname or "";
  134. tt.headimgurl = app.user.headimgurl or "";
  135. tt.sex = app.user.sex or 0;
  136. tt.access_token = app.user.access_token or "";
  137. tt.refresh_token = app.user.refresh_token or "";
  138. local appVersion = getAppVersionNum()
  139. local resVersion = loadVersion()
  140. local versionInfo = string.format(appVersion.."."..resVersion )
  141. tt.version = versionInfo --//客户端版本号
  142. tt.device = getDeviceID(); --//设备唯一标识,如有则传,无则无需传输
  143. tt.mac = getWifiMAC(); --//mac地址
  144. tt.network = getNetworkType(); --//1:WIFI 2:2G 3:3G 4:4G
  145. tt.resolution = self:getResolution() --//分辨率
  146. tt.machine_type = getLocalizedModel() --//机型
  147. local sysVersion = getSystemVersion();
  148. local sysName = getSystemName();
  149. local osStr = string.format(sysName..sysVersion);
  150. tt.os = osStr --//移动终端设备操作系统
  151. logD("ProtocolPhp:login() tt = ", table.tostring(tt))
  152. -- 校验微信信息的有效性
  153. self:checkWxInfoValilable()
  154. httpPost(self.phpUrl, tt, handler(self, self.onLoginResponse))
  155. end
  156. -- 登录结果
  157. function ProtocolPhp:onLoginResponse(status, response)
  158. logD("ProtocolPhp:onLoginResponse()", status, response)
  159. if status ~= "successed" then
  160. return
  161. end
  162. local data = json.decode(response)
  163. if not data or type(data) ~= "table" or data.code ~= 200 then
  164. return
  165. end
  166. -- 获取广告配置
  167. -- self:getAdsConfig();
  168. --请求商城数据
  169. -- app.phpShop:getShopInfo()
  170. -- 请求获取商城购买记录
  171. -- app.phpShop:requestGetShopRecord();
  172. -- 请求活动数据
  173. -- self:requestGetActivityInfo()
  174. -- 请求实名认证数据
  175. -- self:requestGetShiMingInfo()
  176. -- 请求邀请码数据
  177. -- self:requestGetInviteCodeInfo();
  178. -- 请求实名认证数据
  179. app.php:requestGetShiMingInfo()
  180. --拉取游戏红点
  181. if app.config.ModuleConfig.IsSupportRedPoint then
  182. self:requestActivityRedPoint()
  183. end
  184. local registerTime = data.result.user.join or 0
  185. saveUserInfo("userRegisterTime",registerTime)
  186. local rank = data.result.game.lvl or 1
  187. saveUserInfo("userRank",rank)
  188. -- 悠闲豆
  189. app.user.loginInfo.curBeanNum = data.result.game.beans or 0
  190. -- 礼券
  191. app.user.loginInfo.curLiquanNum = data.result.game.coupons or 0
  192. --账号注销状态
  193. app.user.logOut = {}
  194. app.user.logOut.logOutTime = data.result.user.endtime
  195. app.user.logOut.status = data.result.user.cancel
  196. app.user.logOut.imgUrl = data.result.user.imgUrl
  197. if app.user.logOut.status == 1 then
  198. app:dispatchEvent({name = "LOGOUT_TIPS"});
  199. end
  200. local iconUrl, iconTime = convertIconUrl(app.user.logOut.imgUrl)
  201. local iconFile = getImageNameFromUrl(iconUrl)
  202. getImageFromUrlWithTime(iconUrl, iconFile, tonumber(iconTime), function(ret)
  203. end)
  204. --自己道具信息
  205. self.mypropdata = data.result.prop or {}
  206. self.islogin = 1
  207. self.daili = {}
  208. -- 大厅客服微信
  209. if data.result and data.result.agent and data.result.agent.wechat and type(data.result.agent.wechat) == "table" then
  210. local t = {}
  211. for kk,vv in pairs(data.result.agent.wechat) do
  212. table.insert(t, vv);
  213. end
  214. self.daili[0] = t;
  215. end
  216. -- 子游戏代理微信
  217. if data.result and data.result.agent and data.result.agent.games and type(data.result.agent.games) == "table" then
  218. for k,v in pairs(data.result.agent.games) do
  219. local t = {}
  220. for kk, vv in pairs(v) do
  221. table.insert(t, vv);
  222. end
  223. self.daili[tonumber(k)] = t;
  224. end
  225. end
  226. --启动支付插件
  227. app.plugin:startIosPay()
  228. --登录时获取道具配置
  229. app.serverConfigs:requestClientConfig()
  230. -- 发送登录成功的事件
  231. app:dispatchEvent({name = "PHP_LGIN_SUCCESSED"});
  232. self:dispatchEvent({name = "getwetChatConfigResponse"})
  233. self.currTime = os.time()
  234. app.mainScene:runDelay(300, function()
  235. self:keepalive();
  236. end)
  237. end
  238. function ProtocolPhp:resetCheckOnline()
  239. self.isCheckTime = false
  240. self:checkOnline()
  241. end
  242. function ProtocolPhp:checkOnline()
  243. if self.isCheckTime then
  244. return
  245. end
  246. self.isCheckTime = true
  247. self.onlineTData = self:loadGameInfoFromFile()
  248. self.curDay = os.date("%Y%m%d");
  249. if self.onlineTData and self.onlineTData[self.curDay] then
  250. self.curTimeElapse = self.onlineTData[self.curDay].time or 0
  251. else
  252. self.curTimeElapse = 0;
  253. end
  254. local function showTime()
  255. if isWin32Platform() then
  256. local hour = math.floor(self.curTimeElapse/3600)
  257. local min = math.floor((self.curTimeElapse - hour * 3600)/60)
  258. local sec = math.floor(self.curTimeElapse - hour * 3600 - min * 60)
  259. local str = string.format("用户已经在线:%d小时%d分%d秒",hour,min,sec);
  260. local view = app:getCurrentView()
  261. local name = view and view.__cname
  262. if name == "MainView" or name == "LoginView" then
  263. showTooltip(str)
  264. else
  265. showTooltip("消息:用户在房间了!")
  266. end
  267. end
  268. end
  269. local action = cc.RepeatForever:create(cc.Sequence:create(cc.DelayTime:create(self.online.updateTime), cc.CallFunc:create(function()
  270. self:checkIsAdult()
  271. end)))
  272. action:setTag(20200408)
  273. app.mainScene:runActions(action)
  274. end
  275. function ProtocolPhp:checkIsAdult()
  276. self.curTimeElapse = self.curTimeElapse + self.online.updateTime
  277. --每到达一个60秒的倍数保存一次在线时间。
  278. if self.curTimeElapse % 60 == 0 then
  279. self:saveGameInfoToFile(self.curDay,self.curTimeElapse)
  280. end
  281. local view = app:getCurrentView()
  282. local name = view and view.__cname
  283. if self.curTimeElapse >= self.online.fiveHour then
  284. if self.shimingData.card == "" and name == "MainView" or name == "LoginView" then
  285. if toNumber(self.shimingData.certification) ~= -1 and not app.php.inShiMingView then
  286. local view = import("luaScript.Views.Main.NoticeShiMingTip"):new()
  287. view:setAnchorPoint(cc.p(0.5,0.5))
  288. app:showWaitDialog(view,0)
  289. app.mainScene:stopActionByTag(20200408)
  290. self:saveGameInfoToFile(self.curDay,self.curTimeElapse)
  291. return
  292. end
  293. end
  294. end
  295. if self.curTimeElapse >= self.online.twoHour and self.shimingData.card ~= "" then
  296. if self:getIsYoungPeople() and name == "MainView" or name == "LoginView" then
  297. if toNumber(self.shimingData.isAdult) ~= -1 then
  298. app.mainScene:stopActionByTag(20200408)
  299. self:saveGameInfoToFile(self.curDay,self.curTimeElapse)
  300. local hour
  301. if app.php.online.fiveHour % 3600 == 0 then
  302. hour = math.floor(app.php.online.twoHour/3600)
  303. else
  304. hour = string.format("%.2f",app.php.online.twoHour/3600)
  305. end
  306. local tip = "您好,因为您是未成年用户,您的游戏时长已超过"..tostring(hour).."小时,为了保证您的身心健康请退出游戏休息一下吧!"
  307. local function okCallBack()
  308. cc.Application:getInstance():shutdown();
  309. end
  310. showConfirmDialog(tip,okCallBack)
  311. return
  312. end
  313. end
  314. end
  315. end
  316. function ProtocolPhp:getIsYoungPeople()
  317. local card = self.shimingData.card..""
  318. local birthYear = string.sub(card,7,10)
  319. local curYear = os.date("%Y");
  320. local distance = math.abs(curYear - birthYear)
  321. return distance < 18
  322. end
  323. -- 从本地读取今天已经在线的游戏时长
  324. function ProtocolPhp:loadGameInfoFromFile()
  325. local locString = loadStringFromFile("onlineData.json")
  326. if not locString or locString == "" then
  327. return nil
  328. end
  329. local locData = json.decode(locString)
  330. if locData then
  331. return locData
  332. end
  333. return nil
  334. end
  335. -- 记录某一天的在线时长,每一分钟记录一次
  336. function ProtocolPhp:saveGameInfoToFile(curDay,curTimeElapse)
  337. if not curDay or not curTimeElapse then
  338. return
  339. end
  340. local tt = {}
  341. tt[curDay] = {
  342. time = curTimeElapse,
  343. }
  344. local locString = json.encode(tt)
  345. saveStringToFile(locString,"onlineData.json")
  346. end
  347. -- 获取活动数据
  348. function ProtocolPhp:requestGetActivityInfo()
  349. local tt =
  350. {
  351. action= "tasks.getList",
  352. uid = app.user.loginInfo.uid,
  353. apkver = getAppVersion(),
  354. app = getAppId(),
  355. --token = app.user.loginInfo.token,
  356. }
  357. logD("ProtocolPhp:requestGetActivityInfo()", table.tostring(tt))
  358. httpPost(self.phpUrl, tt, handler(self, self.onGetActivityInfoResponse))
  359. end
  360. function ProtocolPhp:onGetActivityInfoResponse(status, response)
  361. logD("ProtocolPhp:onGetActivityInfoResponse()", status, response)
  362. if status ~= "successed" then
  363. logE("活动数据拉取失败")
  364. return
  365. end
  366. local data = json.decode(response)
  367. if not data or type(data) ~= "table" or data.code ~= 200 then
  368. logE("活动数据错误")
  369. return
  370. end
  371. logD("ProtocolPhp:onGetActivityInfoResponse() data = ", table.tostring(data))
  372. self.activityData = data.result
  373. app:dispatchEvent({name = "onGetActivityInfoResponse"})
  374. app:dispatchEvent({name = "onGetHongBaoKaInfoResponse"})
  375. end
  376. -- 获取背包数据
  377. function ProtocolPhp:requestGetBagInfo(ptype)
  378. if not ptype then
  379. ptype = 0
  380. end
  381. local tt =
  382. {
  383. action= "prop.knapsack",
  384. uid = app.user.loginInfo.uid,
  385. app = getAppId(),
  386. token = app.user.loginInfo.token,
  387. prop_type = ptype
  388. }
  389. app.waitDialogManager:showWaitNetworkDialog();
  390. logD("ProtocolPhp:requestGetActivityInfo() data = ", table.tostring(tt))
  391. httpPost(self.phpUrl, tt, handler(self, self.onGetBagInfoResponse))
  392. end
  393. function ProtocolPhp:onGetBagInfoResponse(status, response)
  394. app.waitDialogManager:closeWaitNetworkDialog();
  395. logD("ProtocolPhp:onGetBagInfoResponse()", status, response)
  396. if status ~= "successed" then
  397. logE("背包数据拉取失败")
  398. return
  399. end
  400. local data = json.decode(response)
  401. if not data or type(data) ~= "table" or data.code ~= 200 then
  402. logE("背包数据错误")
  403. return
  404. end
  405. logD("ProtocolPhp:onGetBagInfoResponse() data = ", table.tostring(data))
  406. self.baginfodata = data.result.list
  407. app:dispatchEvent({name = "onGetBagInfoResponse"})
  408. end
  409. function ProtocolPhp:requestBagOperate(pid,ptype,gid)
  410. if not gid then
  411. gid = 0
  412. end
  413. local params =
  414. {
  415. action = "prop.setup",
  416. uid = app.user.loginInfo.uid,
  417. app = getAppId(),
  418. token = app.user.loginInfo.token,
  419. prop_id = pid,
  420. type = ptype,
  421. gid = gid,
  422. }
  423. app.waitDialogManager:showWaitNetworkDialog();
  424. httpPost(self.phpUrl, params, handler(self, self.onBagOperateResponse))
  425. end
  426. function ProtocolPhp:onBagOperateResponse(status, response)
  427. if status ~= "successed" then
  428. return
  429. end
  430. local ttResposne = json.decode(response)
  431. if not ttResposne then
  432. return
  433. end
  434. app.waitDialogManager:closeWaitNetworkDialog();
  435. -- 200成功
  436. if ttResposne.code == 200 then
  437. logD("onBagOperateResponse:",table.tostring(ttResposne));
  438. self.mypropdata = ttResposne.result
  439. app:dispatchEvent({name = "onBagOperateResponse"});
  440. else
  441. showTooltip("商品使用失败!");
  442. end
  443. end
  444. -- 获取实名认证数据
  445. function ProtocolPhp:requestGetShiMingInfo()
  446. local tt =
  447. {
  448. action= "identity.get",
  449. uid = app.user.loginInfo.uid,
  450. }
  451. httpPost(self.phpUrl, tt, handler(self, self.onGetShiMingInfoResponse))
  452. end
  453. function ProtocolPhp:onGetShiMingInfoResponse(status, response)
  454. logD("ProtocolPhp:onGetShiMingInfoResponse()", status, response)
  455. if status ~= "successed" then
  456. logE("实名认证拉取失败")
  457. return
  458. end
  459. local data = json.decode(response)
  460. if not data or type(data) ~= "table" or data.code ~= 200 then
  461. logE("实名认证数据错误")
  462. return
  463. end
  464. logD("ProtocolPhp:onGetShiMingInfoResponse() data = ", table.tostring(data))
  465. self.shimingData = data.result;
  466. if self.shimingData.certification~= -1 then
  467. self.online.fiveHour = self.shimingData.certification
  468. end
  469. if self.shimingData.isAdult ~= -1 then
  470. self.online.twoHour = self.shimingData.isAdult
  471. end
  472. self:checkOnline()
  473. app:dispatchEvent({name = "onGetShiMingInfoResponse"})
  474. end
  475. -- 请求实名认证
  476. function ProtocolPhp:requestBindShiMing(name, identity)
  477. local tt =
  478. {
  479. action= "identity.auth",
  480. uid = app.user.loginInfo.uid,
  481. card = identity,
  482. name = name,
  483. appId = getAppId()
  484. }
  485. logD("发送绑定身份证数据:"..table.tostring(tt))
  486. app.waitDialogManager:showWaitNetworkDialog("认证中....");
  487. httpPost(self.phpUrl, tt, function(status, response)
  488. self:onBindShiMingResponse(status, response, name, identity)
  489. end)
  490. end
  491. -- 请求实名认证结果
  492. function ProtocolPhp:onBindShiMingResponse(status, response, name, identity)
  493. app.waitDialogManager:closeWaitNetworkDialog();
  494. logD("ProtocolPhp:onBindShiMingResponse()", status, response)
  495. if status ~= "successed" then
  496. logE("实名认证失败")
  497. return
  498. end
  499. local data = json.decode(response)
  500. if not data or type(data) ~= "table" or data.code ~= 200 then
  501. logE("实名认证数据错误")
  502. local errStr =
  503. {
  504. [1100] = "参数错误",
  505. [1101] = "您填写的姓名跟身份证不匹配,请重新填写",
  506. [1102] = "已验证",
  507. [1103] = "您填写的姓名跟身份证不匹配,请重新填写",
  508. [1104] = "查询失败!",
  509. }
  510. showTooltip(errStr[data.code] or "未知错误 "..tostring(data.code))
  511. return
  512. end
  513. logD("ProtocolPhp:onBindShiMingResponse() data = ", table.tostring(data))
  514. self.shimingData = {}
  515. self.shimingData.name = name
  516. self.shimingData.card = identity
  517. self.shimingData.isAdult = data.result.isAdult
  518. --如果是未成年,实名认证后,重置在线时长
  519. if self:getIsYoungPeople() then
  520. self.curTimeElapse = 0
  521. self:saveGameInfoToFile(self.curDay,0)
  522. self:resetCheckOnline()
  523. end
  524. app:dispatchEvent({name = "onBindShiMingResponse"})
  525. end
  526. -- 获取邀请码数据
  527. function ProtocolPhp:requestGetInviteCodeInfo()
  528. local tt =
  529. {
  530. action= "invite.check",
  531. app = getAppId(),
  532. uid = app.user.loginInfo.uid,
  533. token = app.user.loginInfo.token,
  534. }
  535. httpPost(self.phpUrl, tt, handler(self, self.onGetInviteCodeInfoResponse))
  536. end
  537. function ProtocolPhp:onGetInviteCodeInfoResponse(status, response)
  538. logD("ProtocolPhp:onGetInviteCodeInfoResponse()", status, response)
  539. if status ~= "successed" then
  540. logE("邀请码数据拉取失败")
  541. return
  542. end
  543. local data = json.decode(response)
  544. if not data or type(data) ~= "table" or data.code ~= 200 then
  545. logE("邀请码数据错误")
  546. return
  547. end
  548. logD("ProtocolPhp:onGetInviteCodeInfoResponse() data = ", table.tostring(data))
  549. self.inviteCodeData = data.result;
  550. app:dispatchEvent({name = "onGetInviteCodeInfoResponse"})
  551. end
  552. -- 请求绑定邀请码
  553. function ProtocolPhp:requestBindInviteCode(inviteCode)
  554. local tt =
  555. {
  556. action= "invite.bind",
  557. app = getAppId(),
  558. uid = app.user.loginInfo.uid,
  559. token = app.user.loginInfo.token,
  560. code = inviteCode,
  561. }
  562. httpPost(self.phpUrl, tt, function(status, response)
  563. self:onBindInviteCodeResponse(status, response, inviteCode)
  564. end)
  565. end
  566. function ProtocolPhp:onBindInviteCodeResponse(status, response, inviteCode)
  567. logD("ProtocolPhp:onBindInviteCodeResponse()", status, response)
  568. if status ~= "successed" then
  569. logE("绑定邀请码失败1")
  570. return
  571. end
  572. local data = json.decode(response)
  573. if not data or type(data) ~= "table" or data.code ~= 200 then
  574. logE("绑定邀请码失败2")
  575. if data and data.error then
  576. showTooltip(data.error)
  577. end
  578. return
  579. end
  580. logD("ProtocolPhp:onBindInviteCodeResponse() data = ", table.tostring(data))
  581. self.inviteCodeData.code = inviteCode
  582. if data.result and data.result.card then
  583. app.user.loginInfo.curCardNum = data.result.card
  584. end
  585. app:dispatchEvent({name = "onBindInviteCodeResponse", data = data.result})
  586. end
  587. -- 获取广告配置
  588. function ProtocolPhp:getAdsConfig()
  589. local ttParams =
  590. {
  591. action = "slide.ads",
  592. app = getAppId(),
  593. uid = app.user.loginInfo.uid,
  594. apkver = getAppVersion(),
  595. }
  596. httpPost(self.phpUrl, ttParams, handler(self, self.getAdsConfigResponse))
  597. end
  598. --[[
  599. "code":200,
  600. "error":"",
  601. "result":{
  602. //排序ID url:图片地址 code:跳转地址 cmd为跳转界面,params为定义参数,特定界面使用。如:1为创建房间,params:{"jushu":20,"mode":"classic"} 局数为20局,模式为经典场
  603. 1:{"url":"www.xxx.com/x.png","jump":{"cmd":1,"param":{"xx":"xx"}}},
  604. 2:{"url":"www.xxx.com/x.png","jump":{"cmd":1,"param":{"xx":"xx"}}},
  605. 3:{"url":"www.xxx.com/x.png","jump":{"cmd":1,"param":{"xx":"xx"}}}
  606. },
  607. ]]
  608. function ProtocolPhp:getAdsConfigResponse(status, response)
  609. local ret, ttResult = checkPhpResponse(status, response)
  610. if not ret then
  611. logD("ProtocolPhp:getAdsConfigResponse() status = ", table.tostring(status))
  612. logD("ProtocolPhp:getAdsConfigResponse() response = ", table.tostring(response))
  613. --showPHPFailedResult(tostring(ttResult))
  614. return
  615. end
  616. logD("ProtocolPhp:getAdsConfigResponse()", table.tostring(ttResult))
  617. local imageCount = 0;
  618. local function onDownloadImageEnd()
  619. imageCount = imageCount - 1
  620. if imageCount <= 0 then
  621. self:dispatchEvent({name = "getAdsConfigResponse"})
  622. end
  623. end
  624. self.listAds = {}
  625. for k, v in pairs(ttResult) do
  626. local jump = v.jump;
  627. local url,time = convertIconUrl(v.url)
  628. local fileName = getImageNameFromUrl(url)
  629. imageCount = imageCount + 1
  630. getImageFromUrlWithTime(url, fileName, time, onDownloadImageEnd)
  631. table.insert(self.listAds, {idx = k, url = url, fileName = fileName, jump = jump})
  632. end
  633. logD("ProtocolPhp:getAdsConfigResponse()", table.tostring(self.mapAds))
  634. end
  635. -- 获取绑定手机的验证码
  636. function ProtocolPhp:requestBindPhoneProvingCode(phoneNumber)
  637. local params =
  638. {
  639. action = "sms.authToken",
  640. uid = app.user.loginInfo.uid,
  641. phone = tostring(phoneNumber),
  642. app = getAppId(),
  643. }
  644. httpPost(self.phpUrl, params, handler(self, self.onBindPhoneProvingCodeResponse))
  645. end
  646. function ProtocolPhp:onBindPhoneProvingCodeResponse(status, response)
  647. if status ~= "successed" then
  648. return
  649. end
  650. local ttResposne = json.decode(response)
  651. if not ttResposne then
  652. return
  653. end
  654. -- 200成功,5001手机号为空,5002手机格式错误
  655. if ttResposne.code ~= 200 then
  656. local tt =
  657. {
  658. [5001] = "手机号不能为空",
  659. [5002] = "手机格式错误",
  660. }
  661. showTooltip(tt[ttResposne.code] or "errCode = " .. tostring(ttResposne.code))
  662. return
  663. end
  664. showTooltip("验证码已发送,请注意查收短信")
  665. end
  666. -- 请求分享奖励
  667. function ProtocolPhp:requestGetShareReward()
  668. local params =
  669. {
  670. action = "missions.setshareflag",
  671. uid = app.user.loginInfo.uid,
  672. token = app.user.loginInfo.token,
  673. app = getAppId(),
  674. }
  675. httpPost(self.phpUrl, params, handler(self, self.onGetShareRewardResponse))
  676. end
  677. function ProtocolPhp:onGetShareRewardResponse(status, response)
  678. if status ~= "successed" then
  679. return
  680. end
  681. local ttResposne = json.decode(response)
  682. if not ttResposne then
  683. return
  684. end
  685. --result.flag 1操作成功0参数错误-1已设置-2服务器错误请重试
  686. --result.card 总房卡,成功时才返回
  687. --result.add 增加的房卡数
  688. if ttResposne.result then
  689. if ttResposne.result.flag == 1 then
  690. if ttResposne.result.card then
  691. app.user.loginInfo.curCardNum = ttResposne.result.card
  692. app:dispatchEvent({name = "onGetShareRewardResponse", data = ttResposne.result})
  693. end
  694. elseif ttResposne.result.flag == -1 then
  695. app:dispatchEvent({name = "onGetShareRewardResponse", data = ttResposne.result})
  696. --showTooltip("今日已领取过奖励!")
  697. else
  698. print("ProtocolPhp:onGetShareRewardResponse error code:", ttResposne.result.flag)
  699. end
  700. end
  701. end
  702. -- 请求每日登陆奖励
  703. function ProtocolPhp:requestDailyLoginReward()
  704. local params =
  705. {
  706. action = "missions.logintake",
  707. uid = app.user.loginInfo.uid,
  708. token = app.user.loginInfo.token,
  709. app = getAppId(),
  710. }
  711. httpPost(self.phpUrl, params, handler(self, self.onDailyLoginRewardResponse))
  712. end
  713. function ProtocolPhp:onDailyLoginRewardResponse(status, response)
  714. app.waitDialogManager:closeWaitNetworkDialog();
  715. if status ~= "successed" then
  716. return
  717. end
  718. local ttResposne = json.decode(response)
  719. if not ttResposne then
  720. return
  721. end
  722. --result.flag 1操作成功0参数错误-1已设置-2服务器错误请重试
  723. --result.card 总房卡,成功时才返回
  724. --result.add 增加的房卡数
  725. --result.cday 连续签到的天数
  726. if ttResposne.result then
  727. if ttResposne.result.flag == 1 then
  728. if ttResposne.result.card then
  729. app.user.loginInfo.curCardNum = ttResposne.result.card
  730. app:dispatchEvent({name = "onGetDailyaloginRewardResponse", data = ttResposne.result})
  731. end
  732. if ttResposne.result.coupons then
  733. app.user.loginInfo.curLiquanNum = ttResposne.result.coupons
  734. app:dispatchEvent({name = "onGetDailyaQianDaoRewardResponse", data = ttResposne.result})
  735. end
  736. elseif ttResposne.result.flag == -1 then
  737. showTooltip("今日已经签到过了!")
  738. end
  739. end
  740. end
  741. --请求分享奖励
  742. function ProtocolPhp:requestQianDaoShare(callback)
  743. local userInfo = json.decode(app.user.userInfo);
  744. local params =
  745. {
  746. action = "tasks.logintake",
  747. uid = app.user.loginInfo.uid,
  748. token = app.user.loginInfo.token,
  749. app = getAppId(),
  750. }
  751. logD("ProtocolPhp:requestQianDaoShare", table.tostring(params))
  752. --app.waitDialogManager:showWaitNetworkDialog();
  753. httpPost(self.phpUrl, params, function (status, strResponse)
  754. --app.waitDialogManager:closeWaitNetworkDialog();
  755. if strResponse then
  756. local data = json.decode(strResponse)
  757. dump(data,"requestQianDaoShare")
  758. if data then
  759. if data.result.coupons then
  760. app.user.loginInfo.curLiquanNum = data.result.coupons
  761. end
  762. if callback then
  763. callback(data)
  764. end
  765. end
  766. end
  767. end)
  768. end
  769. --请求红包券兑换记录
  770. function ProtocolPhp:requestGetHongBaoKaRecord()
  771. local tt =
  772. {
  773. action= "coupon.couponslog",
  774. uid = app.user.loginInfo.uid,
  775. type = 1,
  776. token = app.user.loginInfo.token,
  777. app = getAppId(),
  778. }
  779. httpPost(self.phpUrl, tt, handler(self, self.onGetHongBaoKaRecordResponse))
  780. end
  781. function ProtocolPhp:onGetHongBaoKaRecordResponse(status, response)
  782. logD("ProtocolPhp:onGetHongBaoKaRecordResponse()", status, response)
  783. if status ~= "successed" then
  784. logE("获取充值记录失败")
  785. return
  786. end
  787. local data = json.decode(response)
  788. if not data or type(data) ~= "table" or data.code ~= 200 then
  789. logE("充值记录数据错误")
  790. return
  791. end
  792. logD("ProtocolPhp:onGetHongBaoKaRecordResponse() data = ", table.tostring(data))
  793. self.hongbaokaRecordData = data.result.list;
  794. app:dispatchEvent({name = "onGetHongBaoKaRecordResponse"});
  795. end
  796. --请求红包券获取记录
  797. function ProtocolPhp:requestDuiHuanHongBaoKaRecord()
  798. local tt =
  799. {
  800. action= "coupon.couponslog",
  801. uid = app.user.loginInfo.uid,
  802. type = 2,
  803. token = app.user.loginInfo.token,
  804. app = getAppId(),
  805. }
  806. httpPost(self.phpUrl, tt, handler(self, self.onDuiHuanHongBaoKaRecordResponse))
  807. end
  808. function ProtocolPhp:onDuiHuanHongBaoKaRecordResponse(status, response)
  809. logD("ProtocolPhp:onDuiHuanHongBaoKaRecordResponse()", status, response)
  810. if status ~= "successed" then
  811. logE("获取充值记录失败")
  812. return
  813. end
  814. local data = json.decode(response)
  815. if not data or type(data) ~= "table" or data.code ~= 200 then
  816. logE("充值记录数据错误")
  817. return
  818. end
  819. logD("ProtocolPhp:onDuiHuanHongBaoKaRecordResponse() data = ", table.tostring(data))
  820. self.duihuanhongbaokaRecordData = data.result.list;
  821. app:dispatchEvent({name = "onDuiHuanHongBaoKaRecordResponse"});
  822. end
  823. --- ProtocolPhp:requestHongBaoQuanData 获取红包券数据
  824. function ProtocolPhp:requestHongBaoQuanData()
  825. local params =
  826. {
  827. action = "coupon.index",
  828. uid = app.user.loginInfo.uid,
  829. token = app.user.loginInfo.token,
  830. app = getAppId(),
  831. }
  832. httpPost(self.phpUrl, params, handler(self, self.onResponseHongBaoQuanInfo))
  833. end
  834. --- ProtocolPhp:onResponseHongBaoQuanInfo 获取红包券数据
  835. -- @param status
  836. -- @param response
  837. function ProtocolPhp:onResponseHongBaoQuanInfo(status,response)
  838. logD("ProtocolPhp:onResponseHongBaoQuanInfo()", status, response)
  839. if status ~= "successed" then
  840. return
  841. end
  842. local data = json.decode(response)
  843. if not data or type(data) ~= "table" or data.code ~= 200 then
  844. return
  845. end
  846. logD("ProtocolPhp:onResponseHongBaoQuanInfo() data = ", table.tostring(data))
  847. self.hongbaoquanData = data.result;
  848. if data.result.coupons then
  849. app.user.loginInfo.curLiquanNum = data.result.coupons
  850. end
  851. app:dispatchEvent({name = "onResponseHongBaoQuanInfo"})
  852. end
  853. --- ProtocolPhp:requestWithdarw 请求提现红包券
  854. -- @param wallet
  855. -- @param callback
  856. function ProtocolPhp:requestWithdarw(wallet,callback)
  857. if not wallet then
  858. return
  859. end
  860. local params =
  861. {
  862. action = "coupon.withdarw",
  863. uid = app.user.loginInfo.uid,
  864. app = getAppId(),
  865. token = app.user.loginInfo.token,
  866. wallet = wallet,
  867. }
  868. httpPost(self.phpUrl, params, function (status, strResponse)
  869. --app.waitDialogManager:closeWaitNetworkDialog();
  870. if strResponse then
  871. local data = json.decode(strResponse)
  872. dump(data,"ProtocolPhp:onResponseWithdarw()")
  873. if data then
  874. if data.result.coupons then
  875. app.user.loginInfo.curLiquanNum = data.result.coupons
  876. end
  877. if callback then
  878. callback(data)
  879. end
  880. end
  881. end
  882. end)
  883. end
  884. --- ProtocolPhp:requestExchange 请求红包券兑换钻石
  885. -- @param ZuanShiNum 钻石数
  886. function ProtocolPhp:requestExchange(ZuanShiNum)
  887. if not ZuanShiNum then
  888. return
  889. end
  890. local params =
  891. {
  892. action = "coupon.exchange",
  893. uid = app.user.loginInfo.uid,
  894. app = getAppId(),
  895. token = app.user.loginInfo.token,
  896. num = ZuanShiNum,
  897. }
  898. httpPost(self.phpUrl, params, handler(self, self.onResponseExchange))
  899. end
  900. --- ProtocolPhp:onResponseExchange 请求红包券兑换结果回复
  901. -- @param status Describe the parameter
  902. -- @param response Describe the parameter
  903. function ProtocolPhp:onResponseExchange(status,response)
  904. logD("ProtocolPhp:onResponseExchange()", status, response)
  905. if status ~= "successed" then
  906. return
  907. end
  908. local data = json.decode(response)
  909. if not data or type(data) ~= "table" or data.code ~= 200 then
  910. app:dispatchEvent({name = "onResponseExchangeShiBai"})
  911. return
  912. end
  913. logD("ProtocolPhp:onResponseExchange() data = ", table.tostring(data))
  914. if data.result.coupons then
  915. app.user.loginInfo.curLiquanNum = data.result.coupons
  916. end
  917. if data.result.card then
  918. app.user.loginInfo.curCardNum = data.result.card
  919. end
  920. app:dispatchEvent({name = "onResponseExchange",data = data.result} )
  921. end
  922. --- ProtocolPhp:requestZhengDianJiangli 请求领取整点奖励
  923. function ProtocolPhp:requestZhengDianJiangli()
  924. local params =
  925. {
  926. action = "tasks.getPrize",
  927. type = 11,
  928. uid = app.user.loginInfo.uid,
  929. token = app.user.loginInfo.token,
  930. app = getAppId(),
  931. }
  932. httpPost(self.phpUrl, params, handler(self, self.onResponseZhengDianJiangli))
  933. end
  934. --- ProtocolPhp:onResponseZhengDianJiangli 请求领取正点奖励回复
  935. -- @param status 状态
  936. -- @param response
  937. function ProtocolPhp:onResponseZhengDianJiangli(status, response)
  938. if status ~= "successed" then
  939. return
  940. end
  941. local ttResposne = json.decode(response)
  942. if not ttResposne then
  943. return
  944. end
  945. if ttResposne.result then
  946. if ttResposne.result.coupons then
  947. app.user.loginInfo.curLiquanNum = ttResposne.result.coupons
  948. app:dispatchEvent({name = "onResponseGetJiangli", data = ttResposne.result})
  949. end
  950. end
  951. end
  952. --- ProtocolPhp:requestGetDuiZhanJiangli 请求领取对战奖励
  953. -- @param JLType 奖励类型
  954. -- @param callback 回调
  955. function ProtocolPhp:requestGetDuiZhanJiangli(JLType,callback)
  956. local params =
  957. {
  958. action = "tasks.getPrize",
  959. type = JLType,
  960. uid = app.user.loginInfo.uid,
  961. token = app.user.loginInfo.token,
  962. app = getAppId(),
  963. }
  964. httpPost(self.phpUrl, params, function (status, strResponse)
  965. --app.waitDialogManager:closeWaitNetworkDialog();
  966. if strResponse then
  967. local data = json.decode(strResponse)
  968. dump(data,"requestGetDuiZhanJiangli")
  969. if data then
  970. if data.result.coupons then
  971. app.user.loginInfo.curLiquanNum = data.result.coupons
  972. end
  973. if callback then
  974. callback(data)
  975. end
  976. end
  977. end
  978. end)
  979. end
  980. --请求战绩
  981. function ProtocolPhp:requestZhanjiInfo(zhanjiType)
  982. local phpAddress = self.phpUrl
  983. self.fangjianInfo = nil
  984. self.zhanjiDetail = nil
  985. self.zhanjiInfoItem = nil
  986. local tt =
  987. {
  988. action= UserCmd.PHP_ZHANJI_LIST,
  989. app = getAppId(),
  990. uid = app.user.loginInfo.uid,
  991. gameid = 2,
  992. version = getAppVersion(),
  993. mode = zhanjiType, -- -1:所有游戏
  994. }
  995. log("ProtocolPhp:requestZhanjiInfo_sendInfo", table.tostring(tt))
  996. httpPost(phpAddress, tt, handler(self, self.responseZhanjiInfo));
  997. end
  998. function ProtocolPhp:responseZhanjiInfo(status, response)
  999. --数据结构
  1000. --[[data.result =
  1001. {
  1002. ["gamb"] = {
  1003. ["936"] = {
  1004. ["baseChips"] = 1/3,
  1005. ["detail"] = {
  1006. ["1"] = {
  1007. ["1"] = {
  1008. ["endtime"] = 1511939735,
  1009. ["flag"] = 0,
  1010. ["logid"] = 45,
  1011. ["score"] = {
  1012. ["1014682"] = 6,
  1013. },
  1014. },
  1015. },
  1016. },
  1017. ["endtime"] = 1511940053,
  1018. ["fbound"] = 10,
  1019. ["gameid"] = 3,
  1020. ["gamerule"] = 0,
  1021. ["nbound"] = 10,
  1022. ["roomid"] = 749868,
  1023. ["tgamb"] = {
  1024. ["1014682"] = {
  1025. ["l"] = 0,
  1026. ["w"] = 10,
  1027. },
  1028. },
  1029. ["tscore"] = {
  1030. ["1014682"] = 17,
  1031. },
  1032. },
  1033. }
  1034. ["user"] = {
  1035. ["1014682"] = {
  1036. ["h"] = ,
  1037. ["n"] = 游客1014682,
  1038. ["s"] = 1,
  1039. },
  1040. },
  1041. }--]]
  1042. print("ProtocolPhp:responseZhanjiInfo = "..table.tostring(response))
  1043. if status == "successed" and response then
  1044. local data = json.decode(response)
  1045. if not data then
  1046. print(response)
  1047. app:dispatchEvent({name = "zhanjiCallback"});
  1048. return
  1049. end
  1050. --返回码检查
  1051. if tonumber(data.code) ~= 200 then
  1052. print("data.code :"..data.code)
  1053. app:dispatchEvent({name = "zhanjiCallback"});
  1054. return
  1055. end
  1056. --显示错误信息
  1057. if tostring(data.error) ~= "" then
  1058. print("requestZhanjiInfo error", table.tostring(data.error));
  1059. app:dispatchEvent({name = "zhanjiCallback"});
  1060. return
  1061. end
  1062. --数据校验
  1063. if not data.result or type(data.result) ~= "table" then
  1064. app:dispatchEvent({name = "zhanjiCallback"});
  1065. return;
  1066. end
  1067. local resultT = {};
  1068. for logId, logInfo in pairs(data.result) do
  1069. logInfo.logid = logId
  1070. table.insert(resultT, logInfo)
  1071. end
  1072. table.sort(resultT, function(a, b) return tonumber(a.endtime) > tonumber(b.endtime); end)
  1073. print("ProtocolPhp:responseZhanjiInfo = "..table.tostring(resultT))
  1074. self.fangjianInfo = {}
  1075. self.zhanjiDetail = {}
  1076. self.zhanjiInfoItem = {}
  1077. self.playerInfo = {};
  1078. for k, v in ipairs(resultT) do
  1079. local zhanjiInfoT = {}
  1080. zhanjiInfoT.roomid = v.roomid --房间号
  1081. zhanjiInfoT.fbound = v.fbound --完成的局数
  1082. zhanjiInfoT.nbound = v.nbound --需要完成的局数
  1083. zhanjiInfoT.endtime = v.endtime --完成时间,unix时间戳
  1084. zhanjiInfoT.gameid = v.gameid --游戏ID
  1085. zhanjiInfoT.baseChips = v.baseChips --底分
  1086. zhanjiInfoT.gamerule = v.gamerule --游戏玩法
  1087. --牌局输赢情况
  1088. local paijuInfo = {};
  1089. for paiK,paiV in pairs(v.tgamb) do
  1090. local paiInfoT = {}
  1091. paiInfoT.w = paiV.w --赢次数
  1092. paiInfoT.l = paiV.l --输次数
  1093. paijuInfo[paiK] = paiInfoT;
  1094. end
  1095. zhanjiInfoT.tgamb = paijuInfo;
  1096. --用户总积分
  1097. local scoreCountInfo = {}
  1098. for scK,scV in pairs(v.tscore) do
  1099. scoreCountInfo[scK] = scV;
  1100. end
  1101. zhanjiInfoT.tscore = scoreCountInfo;
  1102. if not self.fangjianInfo then
  1103. self.fangjianInfo = {}
  1104. end
  1105. self.fangjianInfo[v.logid] = zhanjiInfoT;
  1106. --每轮详细信息
  1107. local detailInfo = {};
  1108. local idx = 1;
  1109. for dK,dV in pairsByKeys(v.detail) do
  1110. for kk,vv in pairsByKeys(dV) do
  1111. local detailT = {}
  1112. detailT.logid = vv.logid --此次小局结束的日志id
  1113. detailT.endtime = vv.endtime --结束时间
  1114. detailT.flag = vv.flag --结束原因
  1115. --单局下的积分
  1116. local scoreT = {}
  1117. for sK,sV in pairs(vv.score) do
  1118. scoreT[sK] = sV
  1119. end
  1120. detailT.score = scoreT;
  1121. detailInfo[idx] = detailT;
  1122. idx = idx + 1;
  1123. end
  1124. end
  1125. if not self.zhanjiDetail then
  1126. self.zhanjiDetail = {}
  1127. end
  1128. self.zhanjiDetail[v.logid] = detailInfo;
  1129. --玩家信息
  1130. local pInfo = {};
  1131. for uK,uV in pairsByKeys(v.userinfo) do
  1132. local playerT = {}
  1133. --头像
  1134. local nlen = string.len(uV.head)
  1135. if nlen == 0 then
  1136. playerT.head = ""
  1137. else
  1138. playerT.head = uV.head
  1139. end
  1140. --昵称
  1141. local nlen = string.len(uV.name)
  1142. if nlen == 0 then
  1143. playerT.name = ""
  1144. else
  1145. playerT.name = uV.name
  1146. end
  1147. pInfo[uK] = playerT
  1148. end
  1149. self.playerInfo[v.roomid] = pInfo;
  1150. end
  1151. app:dispatchEvent({name = "zhanjiInfo"});
  1152. else
  1153. print("战绩数据获取失败 status = ",table.tostring(status))
  1154. print(response)
  1155. end
  1156. end
  1157. function ProtocolPhp:initShareZhanJiToUrl(callback)
  1158. app.serverConfigs:requestClientConfig(function()
  1159. local zhanjiUrl = app.serverConfigs.clientConfig.webgamb or RomSetting.ZhanJiUrl
  1160. if callback then
  1161. callback(zhanjiUrl)
  1162. end
  1163. end)
  1164. end
  1165. --获取专用房卡
  1166. -- 返回参数:
  1167. -- {
  1168. -- code: 200,
  1169. -- error: "",
  1170. -- result: {
  1171. -- propsInfo: [
  1172. -- {
  1173. -- id: "2050", // game_id*1000+50为指定游戏的专用房卡
  1174. -- type: "50", // 50为通用房卡;
  1175. -- game_id: 2, // 指定游戏
  1176. -- startTime: "2018-10-23", // 开始有效
  1177. -- endTime: "2018-11-23", // 结束有效
  1178. -- roomcard: "20" // 剩余房卡
  1179. -- }
  1180. -- ]
  1181. -- }
  1182. -- }
  1183. function ProtocolPhp:requestDiamondSpecial(callback)
  1184. local phpAddress = self.phpUrl
  1185. -- self.fangjianInfo = nil
  1186. -- self.zhanjiDetail = nil
  1187. -- self.zhanjiInfoItem = nil
  1188. local tt =
  1189. {
  1190. action= UserCmd.PHP_GET_DIAMOND_SPECIAL,
  1191. app = getAppId(),
  1192. uid = app.user.loginInfo.uid,
  1193. token = app.user.loginInfo.token,
  1194. -- gameid = 2,
  1195. -- version = getAppVersion(),
  1196. -- mode = zhanjiType, -- -1:所有游戏
  1197. }
  1198. log("ProtocolPhp:requestDiamondSpecial", table.tostring(tt))
  1199. httpPost(phpAddress, tt, function (status, response)
  1200. log("ProtocolPhp:requestDiamondSpecial callback", table.tostring(response))
  1201. if response then
  1202. local jsonResponse = json.decode(response)
  1203. if tonumber(jsonResponse.code) == 200 then
  1204. if jsonResponse.result and jsonResponse.result.propsInfo then
  1205. if callback then callback(jsonResponse.result.propsInfo) end
  1206. else
  1207. if callback then callback({}) end
  1208. end
  1209. end
  1210. end
  1211. end);
  1212. end
  1213. -- 邀请新玩家初始化的数据
  1214. function ProtocolPhp:requestLaXinInitData()
  1215. local userInfo = json.decode(app.user.userInfo);
  1216. local tt =
  1217. {
  1218. action= UserCmd.PHP_LAXIN_MAIN,
  1219. uid = app.user.loginInfo.uid,
  1220. nickname = userInfo.nickname,
  1221. app = getAppId(),
  1222. token = app.user.loginInfo.token,
  1223. }
  1224. logD("ProtocolPhp:requestLaXinInitData", table.tostring(tt))
  1225. app.waitDialogManager:showWaitNetworkDialog();
  1226. httpPost(self.phpUrl, tt, function (status, strResponse)
  1227. logD("ProtocolPhp:requestLaXinInitData response", strResponse)
  1228. app.waitDialogManager:closeWaitNetworkDialog();
  1229. if strResponse then
  1230. local response = json.decode(strResponse)
  1231. dump(response)
  1232. if tonumber(response.code) == 200 then
  1233. app:dispatchEvent({name = "HallInviteNewFirend", ret = response.result})
  1234. else
  1235. showTooltip("拉取邀请新玩家数据失败:errCode:",response.code);
  1236. end
  1237. end
  1238. end)
  1239. end
  1240. function ProtocolPhp:requestLaXinFirstShare(callback)
  1241. local userInfo = json.decode(app.user.userInfo);
  1242. local tt =
  1243. {
  1244. action= UserCmd.PHP_LAXIN_SUB_FIRST_SHARE,
  1245. uid = app.user.loginInfo.uid,
  1246. app = getAppId(),
  1247. token = app.user.loginInfo.token,
  1248. type = 5001,
  1249. }
  1250. logD("ProtocolPhp:requestLaXinFirstShare", table.tostring(tt))
  1251. --app.waitDialogManager:showWaitNetworkDialog();
  1252. httpPost(self.phpUrl, tt, function (status, strResponse)
  1253. --app.waitDialogManager:closeWaitNetworkDialog();
  1254. if strResponse then
  1255. local data = json.decode(strResponse)
  1256. dump(data,"requestLaXinFirstShare")
  1257. if data then
  1258. if callback then
  1259. callback(data)
  1260. end
  1261. end
  1262. end
  1263. end)
  1264. end
  1265. function ProtocolPhp:requestLaXinRigisterShare(mType,id,callback)
  1266. local userInfo = json.decode(app.user.userInfo);
  1267. local tt =
  1268. {
  1269. action= UserCmd.PHP_LAXIN_SUB_RIGISTER_PLAY_AWARD,
  1270. uid = app.user.loginInfo.uid,
  1271. app = getAppId(),
  1272. token = app.user.loginInfo.token,
  1273. id = id,
  1274. type = mType,
  1275. }
  1276. logD("ProtocolPhp:requestLaXinRigisterShare", table.tostring(tt))
  1277. --app.waitDialogManager:showWaitNetworkDialog();
  1278. httpPost(self.phpUrl, tt, function (status, strResponse)
  1279. --app.waitDialogManager:closeWaitNetworkDialog();
  1280. if strResponse then
  1281. local data = json.decode(strResponse)
  1282. dump(data,"requestLaXinRigisterShare")
  1283. if data and type(data) == "table" then
  1284. if callback then
  1285. callback(data)
  1286. end
  1287. end
  1288. end
  1289. end)
  1290. end
  1291. function ProtocolPhp:requestLaXinGetMoney(mType,callback)
  1292. local userInfo = json.decode(app.user.userInfo);
  1293. local tt =
  1294. {
  1295. action= UserCmd.PHP_LAXIN_SUB_GET_MONEY,
  1296. uid = app.user.loginInfo.uid,
  1297. app = getAppId(),
  1298. token = app.user.loginInfo.token,
  1299. type = mType,--5005邀请奖5105召回奖
  1300. }
  1301. logD("ProtocolPhp:requestLaXinGetMoney", table.tostring(tt))
  1302. --app.waitDialogManager:showWaitNetworkDialog();
  1303. httpPost(self.phpUrl, tt, function (status, strResponse)
  1304. --app.waitDialogManager:closeWaitNetworkDialog();
  1305. if strResponse then
  1306. local data = json.decode(strResponse)
  1307. dump(data,"requestLaXinGetMoney")
  1308. if data then
  1309. if callback then
  1310. callback(data)
  1311. end
  1312. end
  1313. end
  1314. end)
  1315. end
  1316. function ProtocolPhp:requestLaXinExchange(mType,callback)
  1317. local userInfo = json.decode(app.user.userInfo);
  1318. local tt =
  1319. {
  1320. action= UserCmd.PHP_LAXIN_SUB_EXCHANGE,
  1321. uid = app.user.loginInfo.uid,
  1322. app = getAppId(),
  1323. token = app.user.loginInfo.token,
  1324. type = mType,--5005邀请奖5015召回奖
  1325. }
  1326. logD("ProtocolPhp:requestLaXinGetMoney", table.tostring(tt))
  1327. --app.waitDialogManager:showWaitNetworkDialog();
  1328. httpPost(self.phpUrl, tt, function (status, strResponse)
  1329. --app.waitDialogManager:closeWaitNetworkDialog();
  1330. if strResponse then
  1331. local data = json.decode(strResponse)
  1332. dump(data,"requestLaXinGetMoney")
  1333. if data then
  1334. if callback then
  1335. callback(data)
  1336. end
  1337. end
  1338. end
  1339. end)
  1340. end
  1341. function ProtocolPhp:requestLaXinDownPic(callBack)
  1342. local userInfo = json.decode(app.user.userInfo);
  1343. local tt =
  1344. {
  1345. action= UserCmd.PHP_LAXIN_SUB_PIC_LINK,
  1346. uid = app.user.loginInfo.uid,
  1347. nickname = userInfo.nickname,
  1348. app = getAppId(),
  1349. type = 1,
  1350. token = app.user.loginInfo.token,
  1351. }
  1352. logD("ProtocolPhp:requestLaXinDownPic", table.tostring(tt))
  1353. httpPost(self.phpUrl, tt, function (status, strResponse)
  1354. if strResponse then
  1355. local data = json.decode(strResponse)
  1356. dump(data,"requestLaXinDownPic")
  1357. if data then
  1358. if callBack then
  1359. callBack(data.result.shareImg)
  1360. end
  1361. end
  1362. end
  1363. end)
  1364. end
  1365. function ProtocolPhp:checkWxInfoValilable()
  1366. logD("ProtocolPhp:checkWxInfoValilable()");
  1367. if not isAndroidPlatform() and not isIOSPlatform() then
  1368. logD("ProtocolPhp:checkWxInfoValilable() return by not android and not ios");
  1369. return
  1370. end
  1371. if not app.user.refresh_token or string.len(app.user.refresh_token) < 10 then
  1372. logD("ProtocolPhp:checkWxInfoValilable() return by invalid refresh_token, refresh_token = ", tostring(app.user.refresh_token));
  1373. return
  1374. end
  1375. local PluginConfig = require("preload.PluginConfig")
  1376. local appId = PluginConfig.WeiXin.appId
  1377. local appKey = PluginConfig.WeiXin.appKey
  1378. --local url_refresh_token = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s"
  1379. local url_refresh_token = "https://api.weixin.qq.com/sns/oauth2/refresh_token"
  1380. local tt =
  1381. {
  1382. appid = appId,
  1383. grant_type = "refresh_token",
  1384. refresh_token = app.user.refresh_token
  1385. }
  1386. logD("ProtocolPhp:checkWxInfoValilable() tt = ", table.tostring(tt));
  1387. httpPost(url_refresh_token, tt, function (status, response)
  1388. logD("ProtocolPhp:checkWxInfoValilable() response = ", tostring(response))
  1389. if response and string.len(response) > 10 then
  1390. local jsonResponse = json.decode(response)
  1391. if jsonResponse then
  1392. local openid = jsonResponse.openid
  1393. local access_token = jsonResponse.access_token
  1394. local refresh_token = jsonResponse.refresh_token
  1395. self:updateWxInfoLatest(openid, access_token)
  1396. end
  1397. end
  1398. end);
  1399. end
  1400. function ProtocolPhp:updateWxInfoLatest(openid, access_token)
  1401. logD("ProtocolPhp:updateWxInfoLatest()", openid, access_token);
  1402. local PluginConfig = require("preload.PluginConfig")
  1403. local appId = PluginConfig.WeiXin.appId
  1404. local appKey = PluginConfig.WeiXin.appKey
  1405. local permissions = "snsapi_login"
  1406. -- "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID"
  1407. local user_info_url = "https://api.weixin.qq.com/sns/userinfo"
  1408. local tt =
  1409. {
  1410. openid = openid,
  1411. access_token = access_token
  1412. }
  1413. logD("ProtocolPhp:updateWxInfoLatest() tt = ", table.tostring(tt));
  1414. httpPost(user_info_url, tt, function (status, response)
  1415. logD("ProtocolPhp:updateWxInfoLatest() response = ", tostring(response))
  1416. if response and string.len(response) > 10 then
  1417. local jsonResponse = json.decode(response)
  1418. if jsonResponse then
  1419. if app.user.openid == jsonResponse.openid and app.user.unionid == jsonResponse.unionid then
  1420. if app.user.sex ~= jsonResponse.sex or app.user.nickname ~= jsonResponse.nickname or app.user.headimgurl ~= jsonResponse.headimgurl then
  1421. logD("ProtocolPhp:updateWxInfoLatest() need update wxInfo")
  1422. if isDevMode() then
  1423. showTooltip("need update wxInfo")
  1424. end
  1425. app.user.sex = jsonResponse.sex
  1426. app.user.nickname = jsonResponse.nickname
  1427. app.user.headimgurl = jsonResponse.headimgurl
  1428. -- 更新内存中的数据
  1429. app.user:updateUserInfo();
  1430. -- 删除本地的玩家头像
  1431. updatePlayerHeadImage(app.user.loginInfo.uid, app.user.headimgurl)
  1432. -- 更新本地保存的数据
  1433. local tt = {}
  1434. tt.forceCover = true
  1435. app.user:dispatchEvent({name = "updateWxUserInfo",response = tt})
  1436. else
  1437. logD("ProtocolPhp:updateWxInfoLatest() doesn't need update wxInfo")
  1438. if isDevMode() then
  1439. --showTooltip("doesn't need update wxInfo")
  1440. end
  1441. end
  1442. end
  1443. end
  1444. end
  1445. end);
  1446. end
  1447. function ProtocolPhp:requestReportGameVer(gameId,ver)
  1448. local userInfo = json.decode(app.user.userInfo);
  1449. local tt =
  1450. {
  1451. action= UserCmd.PHP_REPORT_GAME_VER,
  1452. uid = app.user.loginInfo.uid,
  1453. gameid =gameId,
  1454. app = getAppId(),
  1455. ver = ver
  1456. }
  1457. logD("ProtocolPhp:requestReportGameVer", table.tostring(tt))
  1458. httpPost(self.phpUrl, tt, function (status, strResponse)
  1459. -- if strResponse then
  1460. -- local data = json.decode(strResponse)
  1461. -- dump(data,"requestReportGameVer")
  1462. -- end
  1463. end)
  1464. end
  1465. function ProtocolPhp:requestKeFuUrl(callback)
  1466. local phpAddress = self.phpUrl
  1467. local tt =
  1468. {
  1469. action= UserCmd.PHP_GET_KEFU,
  1470. app = getAppId(),
  1471. uid = app.user.loginInfo.uid,
  1472. token = app.user.loginInfo.token,
  1473. nickname = app.user.nickname,
  1474. phone = app.user.phonenum,
  1475. sex = app.user.sex == 1 and "男" or "女",
  1476. email = "",
  1477. }
  1478. logD("ProtocolPhp:requestKeFuUrl", table.tostring(tt))
  1479. httpPost(phpAddress, tt, function (status, response)
  1480. logD("ProtocolPhp:requestKeFuUrl callback", table.tostring(response))
  1481. if response then
  1482. local jsonResponse = json.decode(response)
  1483. if tonumber(jsonResponse.code) == 200 then
  1484. if jsonResponse.result and jsonResponse.result.kefuUrl then
  1485. if callback then callback(jsonResponse.result.kefuUrl) end
  1486. else
  1487. if callback then callback() end
  1488. end
  1489. end
  1490. end
  1491. end);
  1492. end
  1493. function ProtocolPhp:requestActivityRedPoint()
  1494. local params =
  1495. {
  1496. action = UserCmd.PHP_REDDOT,
  1497. token = app.user.loginInfo.token,
  1498. uid = app.user.loginInfo.uid,
  1499. app = getAppId(),
  1500. }
  1501. logD("ProtocolPhp:requestActivityRedPoint() ", table.tostring(params))
  1502. httpPost(self.phpUrl, params, function (status, response)
  1503. if status == "successed" then
  1504. local data = json.decode(response)
  1505. logD("ProtocolPhp:requestActivityRedPoint response() ", table.tostring(data))
  1506. if data and data.result then
  1507. self.activityRedPoint = data.result.info;
  1508. app.msgManager:init();
  1509. --dump(data.result,"onActivityRedPoint")
  1510. app:dispatchEvent({name = "onActivityRedPoint",response = data.result.info});
  1511. end
  1512. end
  1513. end)
  1514. end
  1515. function ProtocolPhp:requestReadRedPoint(messType)
  1516. local params =
  1517. {
  1518. action = UserCmd.PHP_READ_MESSAGE,
  1519. token = app.user.loginInfo.token,
  1520. uid = app.user.loginInfo.uid,
  1521. app = getAppId(),
  1522. type = messType,
  1523. value = 0,
  1524. }
  1525. print("ProtocolPhp:requestReadRedPoint() ", table.tostring(params))
  1526. httpPost(self.phpUrl, params, function (status, response)
  1527. if status == "successed" then
  1528. local data = json.decode(response)
  1529. if data and data.result then
  1530. dump(data.result,"onReadRedPoint")
  1531. app:dispatchEvent({name = "onReadRedPoint",response = data.result});
  1532. app:dispatchEvent({name = "onActivityRedPoint"});
  1533. end
  1534. end
  1535. end)
  1536. end
  1537. function ProtocolPhp:requestCheckForbidClubInvite()
  1538. local params =
  1539. {
  1540. action = UserCmd.PHP_GET_ALLOW_CLUB,
  1541. uid = app.user.loginInfo.uid,
  1542. app = getAppId(),
  1543. }
  1544. app.waitDialogManager:showWaitNetworkDialog("请稍候...")
  1545. logD("ProtocolPhp:requestCheckForbidClubInvite() ", table.tostring(params))
  1546. httpPost(self.phpUrl, params, function (status, response)
  1547. app.waitDialogManager:closeAllNetWait()
  1548. if status == "successed" then
  1549. local data = json.decode(response)
  1550. if data and data.result then
  1551. logD("ProtocolPhp:requestCheckForbidClubInviteResponse() ", table.tostring(data))
  1552. app:dispatchEvent({name = "onCheckForbidClubInvite",response = data.result});
  1553. end
  1554. end
  1555. end)
  1556. end
  1557. function ProtocolPhp:requestSetForbidClubInvite(allow)
  1558. local params =
  1559. {
  1560. action = UserCmd.PHP_SET_ALLOW_CLUB,
  1561. uid = app.user.loginInfo.uid,
  1562. app = getAppId(),
  1563. isallow = allow,
  1564. }
  1565. app.waitDialogManager:showWaitNetworkDialog("请稍候...")
  1566. logD("ProtocolPhp:requestSetForbidClubInvite() ", table.tostring(params))
  1567. httpPost(self.phpUrl, params, function (status, response)
  1568. app.waitDialogManager:closeAllNetWait()
  1569. if status == "successed" then
  1570. logD("ProtocolPhp:requestSetForbidClubInviteResponse() ", table.tostring(response))
  1571. local data = json.decode(response)
  1572. if data and data.result then
  1573. showTooltip("设置成功!")
  1574. end
  1575. end
  1576. end)
  1577. end
  1578. return ProtocolPhp