PlatformXXGame.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. 闲闲游戏 SDK
  3. */
  4. import Gamecfg from "../common/gameCfg";
  5. import { gameMethod } from "../common/gameMethod";
  6. import { PlayerLogin, PlayerLoginPram } from "../common/Xyc";
  7. import { SevBack } from "../common/Xys";
  8. import Config from "../Config";
  9. import { GameEvent, LoadEvent, PlatEvent } from "../data/const/EventConst";
  10. import { AD_VIDEO_KEY, ConstItem, GameErrCode, PayProductParam, ReportRoleType } from "../data/const/TypeConst";
  11. import GameDataCenter from "../data/GameDataCenter";
  12. import GameController from "../GameController";
  13. import UIHelp from "../logic/ui/UIHelp";
  14. import EventMng from "../manager/EventMng";
  15. import NativeManager from "../utils/NativeManager";
  16. import PlatformBase from "./PlatformBase";
  17. export default class PlatformXXGame extends PlatformBase {
  18. rewardVideo: any
  19. adId: string;
  20. constructor() {
  21. super()
  22. window["NativeNotify"] = {
  23. //native平台回调
  24. OnNativeNotify: function (eventType, eventDataString) {
  25. try {
  26. console.log("NativeNotify OnNativeNotify eventType:" + eventType + ",eventDataString:" + eventDataString);
  27. let dataDict = JSON.parse(eventDataString);
  28. if (eventType == "XXGameLogin") { //登录
  29. EventMng.emit(LoadEvent.LOAD_PROGRESS, 0.75, "login")
  30. let params: PlayerLoginPram = {
  31. pid: Config.pid,
  32. param: [dataDict.uid, dataDict.token]
  33. }
  34. // if (dataDict.status != 0) {
  35. // GameDataCenter.plat.showErrDialog(GameErrCode.errPlatLogin)
  36. // return
  37. // }
  38. setTimeout(() => {
  39. GameController.network.send(PlayerLogin.url, params, (result: SevBack) => {
  40. console.log("后段验证返回", JSON.stringify(result))
  41. if (result.type != 1) {
  42. if (gameMethod.isEmpty(result.win) || gameMethod.isEmpty(result.win.msgOut)) {
  43. GameDataCenter.plat.showErrDialog(GameErrCode.errGamePlatLogin)
  44. }
  45. return
  46. }
  47. EventMng.emit(LoadEvent.LOAD_PROGRESS, 1, "login")
  48. if (result.type == 1 && result.platBack) {
  49. GameDataCenter.plat.instance.openId = result.platBack.openid
  50. GameDataCenter.plat.instance.loginParams = [result.platBack.token]
  51. console.log("后端验证成功", GameDataCenter.plat.instance.openId)
  52. // // 加载广告组件
  53. //GameDataCenter.plat.instance.initRewardedVideoAd(AD_VIDEO_KEY.welChest)
  54. // 获取邀请者uuid
  55. let inviter = ""
  56. GameDataCenter.plat.instance.login(inviter)
  57. } else {
  58. console.log("PlayerLogin.url 返回数据异常")
  59. if (gameMethod.isEmpty(result.win) || gameMethod.isEmpty(result.win.msgOut)) {
  60. GameDataCenter.plat.showErrDialog(GameErrCode.errGamePlatLogin)
  61. }
  62. }
  63. })
  64. }, 1000)
  65. } else if (eventType == "XXGamePay") { //支付
  66. if (dataDict.status == 0) {
  67. //充值成功
  68. if (Config.paySuccAdokId != null) {
  69. clearInterval(Config.paySuccAdokId)
  70. Config.paySuccAdokId = null
  71. }
  72. Config.paySuccAdokIndex = 0
  73. Config.paySuccAdokId = setInterval(() => {
  74. Config.paySuccAdokIndex++
  75. if (Config.paySuccAdokIndex >= 5) {
  76. clearInterval(Config.paySuccAdokId)
  77. Config.paySuccAdokId = null
  78. }
  79. GameDataCenter.time.sendAdok()
  80. }, 1000)
  81. } else if (dataDict.status == 1) {
  82. //充值失败
  83. } else {
  84. //待审核中
  85. }
  86. }
  87. else if (eventType == "XXGameLogout") {
  88. //退出登录
  89. GameDataCenter.plat.instance.restart();
  90. }
  91. else if (eventType == "getClipboardText") {
  92. //EventMng.emit(duihuanEvent.GetText, dataDict.msg);
  93. }
  94. else {
  95. console.log("NativeNotify OnNativeNotify not find eventType: " + eventType);
  96. }
  97. }
  98. catch (error) {
  99. console.log("NativeNotify OnNativeNotify error: " + error.stack);
  100. }
  101. },
  102. }
  103. }
  104. showLoginView(): void {
  105. console.log("平台sdk初始化...")
  106. EventMng.emit(LoadEvent.LOAD_PROGRESS, 0.25, "login")
  107. let packageInfo = Gamecfg.packageInfo.getItem(Config.pid)
  108. NativeManager.CallToNative("OnXXGameInit", {}, "")
  109. }
  110. // 上报用户信息
  111. reportUserInfo(res) {
  112. console.log("上报用户信息", res)
  113. }
  114. // 上报角色数据
  115. reportRole(event: ReportRoleType): void {
  116. if (GameDataCenter.sevBack == null) { return }
  117. if (GameDataCenter.sevBack.userInfo == null) { return }
  118. console.log("上报角色数据:", event)
  119. let gameServerId = GameDataCenter.sevBack?.userInfo?.a?.sid;
  120. let serverName = GameDataCenter.user.getServerNameBySid(GameDataCenter.sevBack.userInfo.a.sid) || GameDataCenter.sevBack.userInfo.a.sid;
  121. let roleId = GameDataCenter.sevBack?.userInfo?.a?.uuid;
  122. let level = GameDataCenter.sevBack?.userInfo?.a?.level ?? 1;
  123. let roleName = GameDataCenter.sevBack?.userInfo?.a?.name;
  124. let argList = [];
  125. argList.push({ "Name": "gameServerId", "Value": gameServerId });
  126. argList.push({ "Name": "gameServerName", "Value": serverName });
  127. argList.push({ "Name": "roleId", "Value": roleId });
  128. argList.push({ "Name": "roleLevel", "Value": level.toString() });
  129. argList.push({ "Name": "roleName", "Value": roleName });
  130. if (event == ReportRoleType.create) {
  131. NativeManager.CallToNative("OnXXGamedCreateRole", argList, "")
  132. } else if (event == ReportRoleType.levelup) {
  133. NativeManager.CallToNative("OnXXGamedReportRole", argList, "")
  134. } else if (event == ReportRoleType.online) {
  135. NativeManager.CallToNative("OnXXGamedEnterGame", argList, "")
  136. }
  137. }
  138. pay(orderId: string, order10cs: string, param: PayProductParam): void {
  139. let gameServerId = GameDataCenter.sevBack?.userInfo?.a?.sid;
  140. let serverName = GameDataCenter.user.getServerNameBySid(GameDataCenter.sevBack.userInfo.a.sid) || GameDataCenter.sevBack.userInfo.a.sid;
  141. let roleId = GameDataCenter.sevBack?.userInfo?.a?.uuid;
  142. let level = GameDataCenter.sevBack?.userInfo?.a?.level ?? 1;
  143. let roleName = GameDataCenter.sevBack?.userInfo?.a?.name;
  144. let argList = [];
  145. argList.push({ "Name": "gameServerId", "Value": gameServerId });
  146. argList.push({ "Name": "gameServerName", "Value": serverName });
  147. argList.push({ "Name": "itemName", "Value": param.productName });
  148. argList.push({ "Name": "itemId", "Value": param.productId });
  149. argList.push({ "Name": "roleId", "Value": roleId });
  150. argList.push({ "Name": "roleLevel", "Value": level.toString() });
  151. argList.push({ "Name": "roleName", "Value": roleName });
  152. argList.push({ "Name": "orderId", "Value": orderId });
  153. argList.push({ "Name": "price", "Value": param.price.toString() });
  154. NativeManager.CallToNative("OnXXGamePay", argList, "")
  155. }
  156. //打开浏览器打开链接
  157. openUrl(url: string) {
  158. NativeManager.CallToNative("OnOpenBrowser", [{ "Name": "url", "Value": url }], "")
  159. }
  160. getClipboardText(): void {
  161. NativeManager.CallToNative("getClipboardText", {}, "");
  162. }
  163. reShowLogInView(): void {
  164. NativeManager.CallToNative("OnXXGameLogin", {}, "");
  165. }
  166. }