PlatformWan17H5.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. 17玩H5
  3. */
  4. import Config from "../Config";
  5. import GameController from "../GameController";
  6. import { PlayerLogin, PlayerLoginPram } from "../common/Xyc";
  7. import { LoadEvent } from "../data/const/EventConst";
  8. import { ConstItem, GameErrCode, PayProductParam, ReportRoleType } from "../data/const/TypeConst";
  9. import UIHelp from "../logic/ui/UIHelp";
  10. import EventMng from "../manager/EventMng";
  11. import PlatformBase from "./PlatformBase";
  12. import { SevBack } from "../common/Xys";
  13. import { gameMethod } from "../common/gameMethod";
  14. import GameDataCenter from "../data/GameDataCenter";
  15. import Gamecfg from "../common/gameCfg";
  16. export default class PlatformWan17H5 extends PlatformBase {
  17. constructor() {
  18. super()
  19. //监听屏幕切回来的状态 (防止切回来游戏却收不到支付成功的回调)
  20. cc.game.on(cc.game.EVENT_SHOW, function () {
  21. if (Config.paySuccAdokId != null) {
  22. clearInterval(Config.paySuccAdokId)
  23. Config.paySuccAdokId = null
  24. }
  25. Config.paySuccAdokIndex = 0
  26. Config.paySuccAdokId = setInterval(() => {
  27. Config.paySuccAdokIndex++
  28. if (Config.paySuccAdokIndex >= 5) {
  29. clearInterval(Config.paySuccAdokId)
  30. Config.paySuccAdokId = null
  31. }
  32. GameDataCenter.time.sendAdok()
  33. }, 1000)
  34. GameDataCenter.audio.resumeMusic();
  35. });
  36. cc.game.on(cc.game.EVENT_HIDE, () => {
  37. GameDataCenter.audio.pauseMusic();
  38. })
  39. }
  40. private getQueryString(name) {
  41. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  42. var r = window.location.search.substr(1).match(reg);
  43. if (r != null) {
  44. return unescape(r[2]);
  45. } else {
  46. return null;
  47. }
  48. }
  49. showLoginView(): void {
  50. console.log("初始化&登录SDK")
  51. EventMng.emit(LoadEvent.LOAD_PROGRESS, 0.25, "login")
  52. try {
  53. let packageInfo = Gamecfg.packageInfo.getItem(Config.pid)
  54. let gameid = packageInfo.params[0];
  55. let gamekey = packageInfo.params[1];
  56. Sdk.init(gameid, gamekey);
  57. setTimeout(() => {
  58. EventMng.emit(LoadEvent.LOAD_PROGRESS, 0.75, "login")
  59. let a_pub = this.getQueryString("a_pub")
  60. let a_accountid = this.getQueryString("a_accountid")
  61. let a_sessionid = this.getQueryString("a_sessionid")
  62. if (!a_accountid || !a_sessionid) {
  63. return;
  64. }
  65. let params: PlayerLoginPram = {
  66. pid: Config.pid,
  67. param: [a_accountid, a_sessionid]
  68. }
  69. GameController.network.send(PlayerLogin.url, params, (result: SevBack) => {
  70. console.log("后段验证返回")
  71. if (result.type != 1) {
  72. if (gameMethod.isEmpty(result.win) || gameMethod.isEmpty(result.win.msgOut)) {
  73. GameDataCenter.plat.showErrDialog(GameErrCode.errGamePlatLogin)
  74. }
  75. return
  76. }
  77. EventMng.emit(LoadEvent.LOAD_PROGRESS, 1, "login")
  78. if (result.type == 1 && result.platBack) {
  79. GameDataCenter.plat.instance.openId = result.platBack.openid
  80. GameDataCenter.plat.instance.loginParams = [result.platBack.token]
  81. console.log("后端验证成功", this.openId)
  82. GameDataCenter.plat.instance.login()
  83. } else {
  84. console.log("PlayerLogin.url 返回数据异常")
  85. if (gameMethod.isEmpty(result.win) || gameMethod.isEmpty(result.win.msgOut)) {
  86. GameDataCenter.plat.showErrDialog(GameErrCode.errGamePlatLogin)
  87. }
  88. }
  89. })
  90. }, 3000);
  91. } catch (error) {
  92. UIHelp.ShowSystemDialog({ content: error })
  93. }
  94. }
  95. pay(orderId: string, order10cs: string, param: PayProductParam): void {
  96. let packageInfo = Gamecfg.packageInfo.getItem(Config.pid)
  97. let payUrl: string = packageInfo.wayhttp + "player/pay/" + Config.pid
  98. let orderData = {
  99. callbackurl: payUrl,//游戏方充值回调地址
  100. paymoney: param.price,//游戏充值金额
  101. custominfo: "",//游戏透传参数,回调时原样返回
  102. customorderid: orderId,//订单号
  103. productdesc: param.productDesc,//充值描述
  104. productfeecode: order10cs, // 计费点ID(苹果的商品id)
  105. };
  106. var orderDataJson = JSON.stringify(orderData);
  107. Sdk.pay(orderDataJson, function (result) {
  108. if (result.code != 0) {
  109. console.log("支付失败,失败原因:" + result.msg);
  110. } else {
  111. if (Config.paySuccAdokId != null) {
  112. clearInterval(Config.paySuccAdokId)
  113. Config.paySuccAdokId = null
  114. }
  115. Config.paySuccAdokIndex = 0
  116. Config.paySuccAdokId = setInterval(() => {
  117. Config.paySuccAdokIndex++
  118. if (Config.paySuccAdokIndex >= 5) {
  119. clearInterval(Config.paySuccAdokId)
  120. Config.paySuccAdokId = null
  121. }
  122. GameDataCenter.time.sendAdok()
  123. }, 1000)
  124. }
  125. });
  126. //17玩 如果有的渠道没有充值回调的,只能强行调用充值的时候就开始刷心跳包了
  127. // if (Config.paySuccAdokId != null) {
  128. // clearInterval(Config.paySuccAdokId)
  129. // Config.paySuccAdokId = null
  130. // }
  131. // Config.paySuccAdokIndex = 0
  132. // Config.paySuccAdokId = setInterval(() => {
  133. // Config.paySuccAdokIndex++
  134. // if (Config.paySuccAdokIndex >= 30) {
  135. // clearInterval(Config.paySuccAdokId)
  136. // Config.paySuccAdokId = null
  137. // }
  138. // GameDataCenter.time.sendAdok()
  139. // }, 1000)
  140. }
  141. // 上报角色数据
  142. reportRole(event: ReportRoleType): void {
  143. if (GameDataCenter.sevBack == null) { return }
  144. if (GameDataCenter.sevBack.userInfo == null) { return }
  145. if (GameDataCenter.item == null) { return }
  146. let power = GameDataCenter.zhanLi.getTotalZhanLi(GameDataCenter.sevBack);
  147. let clubName = GameDataCenter.sevBack?.club?.a?.name ?? "";
  148. let level = GameDataCenter.sevBack?.userInfo?.a?.level ?? 1;
  149. let sid = GameDataCenter.sevBack?.userInfo?.a?.sid;
  150. let itemNum = GameDataCenter.item.getItemCount(ConstItem.gem);
  151. let roleData = {
  152. ingot: itemNum, //剩余游戏代币
  153. playerid: GameDataCenter.user.uuid, //角色ID
  154. factionname: clubName,//帮派名称
  155. viplevel: "0",//VIP等级
  156. servername: GameDataCenter.user.serverName,//区服名称
  157. playerlevel: level,//角色等级
  158. serverid: sid,//区服ID
  159. playername: GameDataCenter.user.nickName,//角色名称
  160. };
  161. var roleDataJson = JSON.stringify(roleData);
  162. Sdk.uploadRoleData(roleDataJson, function (result) {
  163. if (result.code != 0) {
  164. console.log("上报失败,失败原因:" + result.msg);
  165. } else {
  166. //上报成功
  167. }
  168. });
  169. }
  170. logout(): void {
  171. Sdk.logout(function (result) {
  172. if (result.code != 0) {
  173. console.log("退出失败,失败原因:" + result.msg);
  174. } else {
  175. //退出成功
  176. GameDataCenter.plat.instance.restart()
  177. }
  178. })
  179. }
  180. //打开浏览器打开链接
  181. openUrl(url: string) {
  182. }
  183. }