RechargeProxy.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. local RemoteProxy = requireProxy("remote/RemoteProxy")
  2. local RechargeProxy = class("RechargeProxy", RemoteProxy)
  3. RechargeProxy.NAME = global.ProxyTable.RechargeProxy
  4. function RechargeProxy:ctor()
  5. RechargeProxy.super.ctor(self)
  6. self._products = {}
  7. end
  8. function RechargeProxy:GetProducts()
  9. return self._products
  10. end
  11. function RechargeProxy:GetProductByID(id)
  12. for _, v in pairs(self._products) do
  13. if tostring(id) == tostring(v.currency_itemid) then
  14. return v
  15. end
  16. end
  17. return nil
  18. end
  19. function RechargeProxy:RespProductInfo(msg)
  20. local jsonData = ParseRawMsgToJson(msg)
  21. if not jsonData then
  22. return false
  23. end
  24. -- dump(jsonData)
  25. self._products = jsonData
  26. end
  27. function RechargeProxy:RespRechargeComplete(msg)
  28. local jsonData = ParseRawMsgToJson(msg)
  29. if not jsonData then
  30. return false
  31. end
  32. -- -- 友盟 充值完成上报
  33. -- if global.L_NativeBridgeManager.GN_umengFinishPay then
  34. -- local AuthProxy = global.Facade:retrieveProxy( global.ProxyTable.AuthProxy )
  35. -- local uploadData = {
  36. -- userId = tostring( AuthProxy:GetUID() ),
  37. -- orderId = tostring( AuthProxy:getOrderID() ),
  38. -- productId = tostring( jsonData.currencyID ),
  39. -- productName = tostring( jsonData.productName ),
  40. -- productPrice = tostring( jsonData.productPrice ),
  41. -- }
  42. -- global.L_NativeBridgeManager:GN_umengFinishPay(uploadData)
  43. -- end
  44. end
  45. function RechargeProxy:RespRechargeReceived(msg)
  46. global.Facade:sendNotification(global.NoticeTable.RechargeReceivedResp)
  47. end
  48. function RechargeProxy:RespJumpRecharge(msg)
  49. local AuthProxy = global.Facade:retrieveProxy(global.ProxyTable.AuthProxy)
  50. local channels =
  51. {
  52. AuthProxy.PAY_CHANNEL.ALIPAY,
  53. AuthProxy.PAY_CHANNEL.HUABEI,
  54. AuthProxy.PAY_CHANNEL.WEIXIN,
  55. }
  56. local header = msg:GetHeader()
  57. local price = header.recog
  58. local payChannel = channels[header.param1]
  59. local currencyID = header.param2
  60. local productIndex = header.param3
  61. --
  62. if not payChannel then
  63. return nil
  64. end
  65. -- 二维码回调
  66. local product = self:GetProductByID(currencyID)
  67. if not product then
  68. ShowSystemTips( "未找到商品: " .. (currencyID or "") )
  69. return nil
  70. end
  71. -- 二维码充值回调
  72. local function qrcodeCB(isOK, filename)
  73. if isOK then
  74. -- 二维码拉取成功
  75. local qrcode_data = {
  76. filename = filename,
  77. channel = payChannel,
  78. }
  79. global.Facade:sendNotification( global.NoticeTable.Layer_Recharge_QRCode_Open, qrcode_data )
  80. end
  81. end
  82. -- 开始充值, 手机端使用原生 PC端使用二维码
  83. local info =
  84. {
  85. id = product.currency_itemid,
  86. name = product.currency_name,
  87. price = price,
  88. productIndex = productIndex,
  89. }
  90. local paytype = global.isWindows and AuthProxy.PAY_TYPE.QRCODE or AuthProxy.PAY_TYPE.NATIVE
  91. if global.L_GameEnvManager:GetEnvDataByKey("platform") == "mac" then
  92. paytype = AuthProxy.PAY_TYPE.QRCODE
  93. end
  94. local payData = {paytype = paytype, channel = payChannel, product = info, qrcodeCB = qrcodeCB}
  95. global.Facade:sendNotification(global.NoticeTable.PayProductRequest, payData)
  96. end
  97. function RechargeProxy:RespJumpRechargeEx(msg)
  98. local json = ParseRawMsgToJson(msg)
  99. if not json then
  100. return
  101. end
  102. local AuthProxy = global.Facade:retrieveProxy(global.ProxyTable.AuthProxy)
  103. local channels =
  104. {
  105. AuthProxy.PAY_CHANNEL.ALIPAY,
  106. AuthProxy.PAY_CHANNEL.HUABEI,
  107. AuthProxy.PAY_CHANNEL.WEIXIN,
  108. }
  109. local price = tonumber(json.Param1)
  110. local payChannel = tonumber(json.Param2) and channels[tonumber(json.Param2)]
  111. local currencyID = tonumber(json.Param3)
  112. local productIndex = tonumber(json.Param4)
  113. --
  114. if not payChannel or not price then
  115. return nil
  116. end
  117. -- 二维码回调
  118. local product = self:GetProductByID(currencyID)
  119. if not product then
  120. ShowSystemTips( "未找到商品: " .. (currencyID or "") )
  121. return nil
  122. end
  123. -- 二维码充值回调
  124. local function qrcodeCB(isOK, filename)
  125. if isOK then
  126. -- 二维码拉取成功
  127. local qrcode_data = {
  128. filename = filename,
  129. channel = payChannel,
  130. }
  131. global.Facade:sendNotification( global.NoticeTable.Layer_Recharge_QRCode_Open, qrcode_data)
  132. end
  133. end
  134. -- 开始充值, 手机端使用原生 PC端使用二维码
  135. local info =
  136. {
  137. id = product.currency_itemid,
  138. name = product.currency_name,
  139. price = price,
  140. productIndex = productIndex,
  141. }
  142. local paytype = global.isWindows and AuthProxy.PAY_TYPE.QRCODE or AuthProxy.PAY_TYPE.NATIVE
  143. local payData = {paytype = paytype, channel = payChannel, product = info, qrcodeCB = qrcodeCB}
  144. global.Facade:sendNotification(global.NoticeTable.PayProductRequest, payData)
  145. end
  146. function RechargeProxy:RegisterMsgHandler()
  147. RechargeProxy.super.RegisterMsgHandler(self)
  148. local msgType = global.MsgType
  149. LuaRegisterMsgHandler(msgType.MSG_SC_PRODUCT_INFO, handler(self, self.RespProductInfo))
  150. LuaRegisterMsgHandler(msgType.MSG_SC_RECHARGE_RECEIVED, handler(self, self.RespRechargeReceived))
  151. LuaRegisterMsgHandler(msgType.MSG_SC_RECHARGE_COMPLETE, handler(self, self.RespRechargeComplete))
  152. LuaRegisterMsgHandler(msgType.MSG_SC_JUMP_CHARGE, handler(self, self.RespJumpRecharge))
  153. LuaRegisterMsgHandler(msgType.MSG_SC_JUMP_CHARGE_EX, handler(self, self.RespJumpRechargeEx))
  154. end
  155. return RechargeProxy