NativeBridgeProxy.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. local DebugProxy = requireProxy("DebugProxy")
  2. local NativeBridgeProxy = class("NativeBridgeProxy", DebugProxy)
  3. NativeBridgeProxy.NAME = global.ProxyTable.NativeBridgeProxy
  4. local cjson = require("cjson")
  5. function NativeBridgeProxy:ctor()
  6. NativeBridgeProxy.super.ctor(self)
  7. self:registerN2GMethods()
  8. self._996_kefu_un_read_ums = 0
  9. end
  10. -- 隐私撤销
  11. function NativeBridgeProxy:GN_Private_BackOut( data )
  12. -- 是否撤回隐私协议
  13. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  14. local jsonString = data and cjson.encode(data) or ""
  15. local methodName = "GN_Private_BackOut"
  16. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  17. release_print("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. jsonString)
  18. end
  19. end
  20. -- 语音
  21. function NativeBridgeProxy:GN_Voice( data )
  22. -- 语音
  23. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  24. local jsonString = data and cjson.encode(data) or ""
  25. local methodName = "GN_Voice"
  26. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  27. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. jsonString)
  28. end
  29. end
  30. -- 语音2.0
  31. function NativeBridgeProxy:GN_Voice_New( data )
  32. -- 语音
  33. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  34. local jsonString = data and cjson.encode(data) or ""
  35. local methodName = "GN_Voice_New"
  36. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  37. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. jsonString)
  38. end
  39. end
  40. --PC callof 直接打开 渠道的充值窗口 美杜莎360要用
  41. function NativeBridgeProxy:GN_PC_CallOF( data )
  42. -- 充值
  43. if cc.PLATFORM_OS_WINDOWS == global.Platform then
  44. local jsonString = data and cjson.encode(data) or ""
  45. local methodName = "GN_onCallOF"
  46. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  47. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. jsonString)
  48. end
  49. end
  50. -- 任务
  51. function NativeBridgeProxy:GN_Mission( data )
  52. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  53. if DataRePortProxy:CheckRepeatTask(data) then
  54. return
  55. end
  56. -- 任务
  57. if global.L_GameEnvManager:GetEnvDataByKey("platform") == "mac" then
  58. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  59. DataRePortProxy:RoleTask(data)
  60. else
  61. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  62. local jsonString = data and cjson.encode(data) or ""
  63. local methodName = "GN_Mission"
  64. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  65. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. jsonString)
  66. elseif cc.PLATFORM_OS_WINDOWS == global.Platform then
  67. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  68. DataRePortProxy:RoleTask(data)
  69. end
  70. end
  71. end
  72. -- 移动端 游戏时长上报暂停/恢复
  73. -- 掉线/小退通知暂停, 重连成功通知恢复
  74. -- isGameDuration: false 暂停 true 恢复
  75. function NativeBridgeProxy:GN_Game_Duration_State( data )
  76. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  77. local jsonString = data and cjson.encode(data) or ""
  78. local methodName = "GN_Game_Duration_State"
  79. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  80. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. jsonString)
  81. end
  82. end
  83. -- PC关闭按钮状态
  84. --- param data table {state=1: 能关闭(默认), 0: 不能关闭}
  85. function NativeBridgeProxy:GN_IsCan_Windown_Close_State( data )
  86. if cc.PLATFORM_OS_WINDOWS == global.Platform then
  87. local jsonString = data and cjson.encode(data) or ""
  88. local methodName = "GN_IsCan_Windown_Close_State"
  89. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  90. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. jsonString)
  91. end
  92. end
  93. -----------------------------------------------------------------------
  94. -- 三方交易行相关
  95. --- param data table {event = "action",params = {}}
  96. function NativeBridgeProxy:GN_TradingBank_Interface( data )
  97. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  98. local jsonString = data and cjson.encode(data) or ""
  99. local methodName = "GN_TradingBank_Interface"
  100. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  101. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. jsonString)
  102. end
  103. end
  104. -- 三方交易行相关
  105. function NativeBridgeProxy:NG_TradingBank_Interface(sender,jsonStr)
  106. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  107. -- debug
  108. releasePrint("lua NG_TradingBank_Interface:" .. (jsonStr and tostring(jsonStr) or ""))
  109. local paramJson = cjson.decode(jsonStr)
  110. if paramJson then
  111. global.Facade:sendNotification( global.NoticeTable.Layer_TradingBank_Interface_other,paramJson)
  112. end
  113. end
  114. end
  115. -----------------------------------------------------------------------
  116. ---------------------------------c++ to lua begin-------------------------------------------
  117. -- PC关闭按钮通知
  118. function NativeBridgeProxy:NG_windowClose()
  119. global.Facade:sendNotification( global.NoticeTable.Delay_Exit_Game_Window_Close_Notice )
  120. end
  121. ---------------------------------c++ to lua end-------------------------------------------
  122. -- 自定义数据上报
  123. -- and & ios
  124. function NativeBridgeProxy:GN_ReportCustomEvent(data)
  125. if global.L_GameEnvManager:GetEnvDataByKey("platform") == "mac" then
  126. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  127. DataRePortProxy:ReportCustomEvent(cjson.decode(data))
  128. return
  129. end
  130. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  131. local methodName = "GN_ReportCustomEvent"
  132. NativeBridgeCtl:Inst():sendMessage2Native(methodName, data)
  133. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. data)
  134. return
  135. end
  136. -- pc 数据上报
  137. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  138. DataRePortProxy:ReportCustomEvent(cjson.decode(data))
  139. end
  140. -- 好评有礼
  141. function NativeBridgeProxy:GN_ReviewGift(data)
  142. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  143. local methodName = "GN_ReviewGift"
  144. NativeBridgeCtl:Inst():sendMessage2Native(methodName, data)
  145. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (data or ""))
  146. end
  147. end
  148. -- 服务器踢人通知
  149. -- and & ios
  150. function NativeBridgeProxy:GN_DetachSucceedByServer(data)
  151. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  152. local methodName = "GN_DetachSucceedByServer"
  153. local jsonString = data and cjson.encode(data) or ""
  154. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  155. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. jsonString)
  156. return
  157. end
  158. dump(data,"GN_DetachSucceedByServer")
  159. end
  160. -- 盒子交易行 返回盒子 到 某商品
  161. function NativeBridgeProxy:GN_GoToCommondity(data)
  162. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  163. local methodName = "GN_GoToCommondity"
  164. local jsonString = data and cjson.encode(data) or ""
  165. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  166. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  167. end
  168. end
  169. -- 盒子交易行 返回盒子 到 求购商品
  170. function NativeBridgeProxy:GN_GoToPurchaseCommondity(data)
  171. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  172. local methodName = "GN_GoToPurchaseCommondity"
  173. local jsonString = data and cjson.encode(data) or ""
  174. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  175. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  176. end
  177. end
  178. -- 盒子交易行 手机盒子交易行跳转支付宝app支付
  179. function NativeBridgeProxy:GN_TradingPayAppInfo(data)
  180. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  181. local methodName = "GN_TradingPayAppInfo"
  182. local jsonString = data and cjson.encode(data) or ""
  183. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  184. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  185. end
  186. end
  187. -- 主界面按钮/图片点击事件上报
  188. function NativeBridgeProxy:GN_MainUIClickEvent(data)
  189. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  190. return
  191. end
  192. local DataRePortProxy = global.Facade:retrieveProxy(global.ProxyTable.DataRePortProxy)
  193. DataRePortProxy:MainUIClickEvent(data)
  194. end
  195. -- 跳转指定应用
  196. -- data = {projectName=包名, jumpLink=跳转链接}
  197. function NativeBridgeProxy:GN_JumpToSpecifyApp(data)
  198. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  199. local methodName = "GN_JumpToSpecifyApp"
  200. local jsonString = data and cjson.encode(data) or ""
  201. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  202. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  203. end
  204. end
  205. ------------------------------------------游戏内客服 begin----------------------------------------
  206. -- 显示客服会话窗口
  207. function NativeBridgeProxy:GN_ShowCustomerService(data)
  208. -- 移动端
  209. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  210. local methodName = "GN_ShowCustomerService"
  211. local jsonString = data and cjson.encode(data) or ""
  212. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  213. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  214. return
  215. end
  216. -- 直接跳转
  217. local url = data and data.url
  218. if url then
  219. cc.Application:getInstance():openURL(url)
  220. end
  221. end
  222. -- 隐藏客服会话窗口
  223. function NativeBridgeProxy:GN_DismissCustomerService(data)
  224. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  225. local methodName = "GN_DismissCustomerService"
  226. local jsonString = data and cjson.encode(data) or ""
  227. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  228. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  229. end
  230. end
  231. -- 显示消息列表
  232. function NativeBridgeProxy:GN_ShowMsgListPop(data)
  233. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  234. local methodName = "GN_ShowMsgListPop"
  235. local jsonString = data and cjson.encode(data) or ""
  236. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  237. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  238. end
  239. end
  240. -- 隐藏消息列表
  241. function NativeBridgeProxy:GN_DismissMsgListPop(data)
  242. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  243. local methodName = "GN_DismissMsgListPop"
  244. local jsonString = data and cjson.encode(data) or ""
  245. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  246. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  247. end
  248. end
  249. -- 结束当前会员
  250. function NativeBridgeProxy:GN_StopCurrentSession(data)
  251. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  252. local methodName = "GN_StopCurrentSession"
  253. local jsonString = data and cjson.encode(data) or ""
  254. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  255. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  256. end
  257. end
  258. -- 鸿蒙账号解绑
  259. function NativeBridgeProxy:GN_unbindAccount()
  260. if global.isOHOS then
  261. local methodName = "GN_unbindAccount"
  262. NativeBridgeCtl:Inst():sendMessage2Native(methodName, "")
  263. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName)
  264. end
  265. end
  266. -- 获取未读消息数量, 小退重进需要显示红点
  267. function NativeBridgeProxy:Get996KeFuUnReadNums()
  268. return self._996_kefu_un_read_ums
  269. end
  270. -- 接收客服消息
  271. function NativeBridgeProxy:NG_Receive_996KeFu_Message(sender,jsonString)
  272. local paramJson = cjson.decode(jsonString)
  273. if not paramJson then
  274. return
  275. end
  276. releasePrint("=====================NG_Receive_996KeFu_Message jsonString: ", jsonString)
  277. if paramJson.nType == 1 then --收到消息,内容字段msg 类型字符串
  278. SLBridge:onLUAEvent(LUA_EVENT_MANUAL_SERVICE_MESSAGE_NEW, {message = paramJson.msg})
  279. elseif paramJson.nType == 2 then -- 未读消息个数 字段num 类型 int
  280. self._996_kefu_un_read_ums = paramJson.num or 0
  281. local ManualService996Proxy = global.Facade:retrieveProxy(global.ProxyTable.ManualService996Proxy)
  282. if ManualService996Proxy then
  283. ManualService996Proxy:SetUnReadNums(paramJson.num or 0)
  284. SLBridge:onLUAEvent(LUA_EVENT_MANUAL_SERVICE_MESSAGE_UN_READ, {unReadNums = paramJson.num})
  285. end
  286. elseif paramJson.nType == 3 then -- 关闭客服
  287. local ManualService996Proxy = global.Facade:retrieveProxy(global.ProxyTable.ManualService996Proxy)
  288. if ManualService996Proxy then
  289. ManualService996Proxy:SetShowMaulServiceState(false)
  290. ManualService996Proxy:SetUnReadNums(0)
  291. SLBridge:onLUAEvent(LUA_EVENT_MANUAL_SERVICE_MESSAGE_CLOSE)
  292. end
  293. end
  294. end
  295. -- sdk打开的ui
  296. function NativeBridgeProxy:NG_Receive_996KeFu_SDKUI(sender,jsonString)
  297. releasePrint("=====================NG_Receive_996KeFu_SDKUI")
  298. local ManualService996Proxy = global.Facade:retrieveProxy(global.ProxyTable.ManualService996Proxy)
  299. if ManualService996Proxy then
  300. releasePrint("=====================NG_Receive_996KeFu_SDKUI111111")
  301. ManualService996Proxy:SetSDKUI(true)
  302. end
  303. end
  304. -- np hack callback
  305. -- table{hackName: 应用名, hackInfo: 路径}
  306. function NativeBridgeProxy:NG_onNPHackInfoCallbOF(sender, jsonString)
  307. if cc.PLATFORM_OS_WINDOWS == global.Platform then
  308. local paramJson = cjson.decode(jsonString)
  309. SLBridge:onLUAEvent(LUA_EVENT_NP_HACK_INFO_CALLBACK, paramJson)
  310. end
  311. end
  312. function NativeBridgeProxy:NG_HarmonyUnbindCB(sender, jsonString)
  313. releasePrint("NG_HarmonyUnbing:" .. tostring(jsonString))
  314. if global.isOHOS then
  315. local paramJson = cjson.decode(jsonString)
  316. local state = paramJson.state -- 0: 解绑成功,1:未绑定,2:解绑失败
  317. if state == 0 then
  318. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(1094))
  319. elseif state == 1 then
  320. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(1095))
  321. else
  322. global.Facade:sendNotification(global.NoticeTable.SystemTips, GET_STRING(1096))
  323. end
  324. end
  325. end
  326. ---------------------------------------游戏内客服 end----------------------------------------------
  327. -- 调用sdk接口打开第三方应用 需sdk实现
  328. function NativeBridgeProxy:GN_Third_APP( data )
  329. -- 移动端
  330. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  331. local methodName = "GN_Third_APP"
  332. local jsonString = data and cjson.encode(data) or ""
  333. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  334. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  335. return
  336. end
  337. end
  338. -- 传递的扩展参数数据
  339. function NativeBridgeProxy:GN_SetExpandInfo(data)
  340. if cc.PLATFORM_OS_WINDOWS ~= global.Platform then
  341. local methodName = "GN_SetExpandInfo"
  342. local jsonString = data and cjson.encode(data) or ""
  343. NativeBridgeCtl:Inst():sendMessage2Native(methodName, jsonString)
  344. releasePrint("+++++++++++++++++++++++++++++++++++++ " .. methodName .. " " .. (jsonString or ""))
  345. return
  346. end
  347. end
  348. function NativeBridgeProxy:registerN2GMethods()
  349. local nativeBridgeCtl = NativeBridgeCtl:Inst()
  350. -- remove last selector
  351. nativeBridgeCtl:removeSelectorsInGroup("windowMonitor")
  352. -- register windowMonitor callback
  353. nativeBridgeCtl:addNativeSelector("windowMonitor","NG_windowClose",handler(self, self.NG_windowClose), nil)
  354. --tradingBank_other
  355. nativeBridgeCtl:removeSelectorsInGroup("tradingBank_other")
  356. nativeBridgeCtl:addNativeSelector("tradingBank_other","NG_TradingBank_Interface",handler(self, self.NG_TradingBank_Interface), nil)
  357. --tradingBank_other
  358. nativeBridgeCtl:removeSelectorsInGroup("tradingBank_other")
  359. nativeBridgeCtl:addNativeSelector("tradingBank_other","NG_TradingBank_Interface",handler(self, self.NG_TradingBank_Interface), nil)
  360. --game_kefu
  361. nativeBridgeCtl:removeSelectorsInGroup("game_kefu")
  362. --receive
  363. nativeBridgeCtl:addNativeSelector("game_kefu","NG_Receive_996KeFu_Message",handler(self, self.NG_Receive_996KeFu_Message), nil)
  364. nativeBridgeCtl:addNativeSelector("game_kefu","NG_Receive_996KeFu_SDKUI", handler(self, self.NG_Receive_996KeFu_SDKUI), nil)
  365. -- NPProtect
  366. nativeBridgeCtl:removeSelectorsInGroup("NPProtect")
  367. -- register NPProtect callback
  368. nativeBridgeCtl:addNativeSelector("NPProtect","NG_onNPHackInfoCallbOF",handler(self, self.NG_onNPHackInfoCallbOF), nil)
  369. -- harmony
  370. nativeBridgeCtl:removeSelectorsInGroup("harmony_unbind")
  371. nativeBridgeCtl:addNativeSelector("harmony_unbind","NG_HarmonyUnbindCB", handler(self, self.NG_HarmonyUnbindCB), nil)
  372. end
  373. return NativeBridgeProxy