KLMonthCardRechargePanel.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ---@class KLMonthCardRechargePanel:UIKmlLuaPanelBase
  2. ---@field view KLMonthCardRechargePanelView
  3. local KLMonthCardRechargePanel = class(UIKmlLuaPanelBase)
  4. local this =KLMonthCardRechargePanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. GUI:SetActive(self.view.clickMask, false)
  10. end
  11. ---注册UI事件和服务器消息
  12. function this:RegistEvents()
  13. end
  14. ---界面显示时调用一次
  15. function this:Show()
  16. end
  17. function this:LoadPayWebview(data)
  18. self.args = data
  19. self.env = SL:GetMetaValue("CS_MAIN_ENV")
  20. if self.env == "local" then
  21. self.url = "http://10.28.1.136/order?time="
  22. elseif self.env == "dev" then
  23. self.url = "http://192.168.13.43:100/order?time="
  24. elseif self.env == "test" then
  25. self.url = "http://sdkh5-test.yq712.shengaowl.com/order?time="
  26. elseif self.env == "pre" then
  27. self.url = "http://sdkh5.yq712.shengaowl.com/order?time="
  28. elseif self.env == "release" then
  29. self.url = "http://sdkh5.yq712.shengaowl.com/order?time="
  30. end
  31. ---@type UnityEngine.GameObject
  32. local obj = GUI:GetGameObject(self.view.prefab_webview)
  33. ---@type Vuplex.WebView.Core.Scripts.WebViewEx.WebViewControl
  34. self.webViewControl = obj:GetComponentInChildren(typeof(CS.Vuplex.WebView.Core.Scripts.WebViewEx.WebViewControl))
  35. self:LoadUrl(self.url .. tostring(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)))
  36. self.webViewControl:SetOnInitialized(function()
  37. self:SetSize(GUI:getSizeDelta(self.view.prefab_webview))
  38. GUI:SetActive(self.view.clickMask, true)
  39. end )
  40. self:SetMessageFun(self.OnMessage,self)
  41. end
  42. function this:SendPageMsg()
  43. local serverId = SL:GetMetaValue("SERVER_ID")
  44. local roleId = SL:GetMetaValue("MAIN_ACTOR_ID")
  45. local roleName = SL:GetMetaValue("USER_NAME")
  46. local serverName = SL:GetMetaValue("SERVER_NAME")
  47. ---@type BoxTokenData
  48. local boxData = GamePlay.boxData
  49. ---@type SdkTokenData
  50. local sdkData = GamePlay.sdkData
  51. local userToken = boxData.userToken
  52. local token = sdkData.token
  53. local gameId = SL:GetMetaValue("GAME_ID")
  54. local data = self.args
  55. local goodsId = data.shopId
  56. local goodsName = data.shopName
  57. --临时chanelId
  58. local channelId = SL:GetMetaValue("CHANNEL_ID")
  59. local shopPrice = data.shopPrice
  60. local shopCount = data.shopCount
  61. local goodsAmount = shopPrice * shopCount
  62. local extraParams = data.extraParams
  63. local appVersion = boxData.appVersion
  64. local isBoxSDK = LoginInfo.IsBoxSDK()
  65. local userId = sdkData.userId
  66. local msg = json.encode({ userId = tostring(userId), serverId = tostring(serverId), roleId = tostring(roleId), roleName = roleName, serverName = serverName,
  67. token = token,userToken = userToken, gameId = gameId, goodsAmount = tostring(goodsAmount), goodsId = tostring(goodsId), goodsName = goodsName,
  68. channelId = tostring(channelId), shopPrice = tostring(shopPrice), shopCount = tostring(shopCount), extraParams = tostring(extraParams), appVersion = tostring(appVersion), isBoxSDK = isBoxSDK})
  69. if DebugFlag.LogEnable then
  70. log(msg)
  71. end
  72. self:SendJsonMessage(msg)
  73. end
  74. function this:OnMessage(jsonStr)
  75. local jsonTbl = json.decode(jsonStr)
  76. if DebugFlag.LogEnable then
  77. log(jsonStr)
  78. end
  79. if jsonTbl.action == 1003 or jsonTbl.action == 3001 then --旧1234 新1003关闭,3001支付成功
  80. GUI:UIPanel_Close("dev/ui/WebView/Panel/KLMonthCardRecharge/KLMonthCardRechargePanel")
  81. elseif jsonTbl.action == 1005 then
  82. if jsonTbl.data.action == 3001 then
  83. self:SendPageMsg()
  84. end
  85. end
  86. end
  87. ---创建或者刷新界面数据时调用
  88. function this:Refresh()
  89. end
  90. function this:Close()
  91. GUI:SetActive(self.view.clickMask, false)
  92. if self.webViewControl then
  93. self.webViewControl:SetOnInitialized(nil)
  94. end
  95. end
  96. function this:SetSize(width, height)
  97. self.webViewControl:SetSize(width, height)
  98. end
  99. function this:LoadUrl(url)
  100. self.webViewControl:LoadURL(url)
  101. end
  102. function this:SetMessageFun(fun,ui)
  103. self.webViewControl:SetMessageHandler(function(json)
  104. fun(ui,json)
  105. end)
  106. end
  107. function this:SendJsonMessage(json)
  108. self.webViewControl:SendJsonMessage(json)
  109. end
  110. return this