PlatformWan17MiniGame.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. 17玩MiniGame(VIVO OPPO)
  3. */
  4. import Config from "../Config";
  5. import GameController from "../GameController";
  6. import { PlayerLogin, PlayerLoginPram } from "../common/Xyc";
  7. import { AD_VIDEO_KEY, GameErrCode, PayProductParam, ReportRoleType } from "../data/const/TypeConst";
  8. import { SevBack } from "../common/Xys";
  9. import PlatformBase from "./PlatformBase";
  10. import { gameMethod } from "../common/gameMethod";
  11. import GameDataCenter from "../data/GameDataCenter";
  12. import EventMng from "../manager/EventMng";
  13. import { LoadEvent } from "../data/const/EventConst";
  14. import Gamecfg from "../common/gameCfg";
  15. import UIHelp from "../logic/ui/UIHelp";
  16. import Mint from "../utils/mintFilter/index";
  17. export default class PlatformWan17MiniGame extends PlatformBase {
  18. mint: Mint;
  19. constructor() {
  20. super()
  21. //设置屏幕常亮
  22. qg.setKeepScreenOn({
  23. keepScreenOn: true,
  24. success: function (res) { },
  25. fail: function (res) { },
  26. complete: function (res) { },
  27. });
  28. qg.onShow((res) => {
  29. if (Config.paySuccAdokId != null) {
  30. clearInterval(Config.paySuccAdokId)
  31. Config.paySuccAdokId = null
  32. }
  33. Config.paySuccAdokIndex = 0
  34. Config.paySuccAdokId = setInterval(() => {
  35. Config.paySuccAdokIndex++
  36. if (Config.paySuccAdokIndex >= 5) {
  37. clearInterval(Config.paySuccAdokId)
  38. Config.paySuccAdokId = null
  39. }
  40. GameDataCenter.time.sendAdok()
  41. }, 1000)
  42. });
  43. }
  44. showLoginView(): void {
  45. console.log("初始化&登录SDK")
  46. qg.asdk.asdkInit((res) => {
  47. //执行登录授权
  48. if (res.code.toString() == "0") {
  49. qg.asdk.asdkLogin((loginRes) => {
  50. //console.log("登录结果" + JSON.stringify(loginRes))
  51. if (loginRes.code.toString() == "0") {
  52. let params: PlayerLoginPram = {
  53. pid: Config.pid,
  54. param: [loginRes.data.account.accountid, loginRes.data.account.sessionid]
  55. }
  56. GameController.network.send(PlayerLogin.url, params, (result: SevBack) => {
  57. console.log("后段验证返回")
  58. if (result.type != 1) {
  59. if (gameMethod.isEmpty(result.win) || gameMethod.isEmpty(result.win.msgOut)) {
  60. GameDataCenter.plat.showErrDialog(GameErrCode.errGamePlatLogin)
  61. }
  62. return
  63. }
  64. EventMng.emit(LoadEvent.LOAD_PROGRESS, 1, "login")
  65. if (result.type == 1 && result.platBack) {
  66. GameDataCenter.plat.instance.openId = result.platBack.openid
  67. GameDataCenter.plat.instance.loginParams = [result.platBack.token]
  68. console.log("后端验证成功", this.openId)
  69. GameDataCenter.plat.instance.login()
  70. } else {
  71. console.log("PlayerLogin.url 返回数据异常")
  72. if (gameMethod.isEmpty(result.win) || gameMethod.isEmpty(result.win.msgOut)) {
  73. GameDataCenter.plat.showErrDialog(GameErrCode.errGamePlatLogin)
  74. }
  75. }
  76. })
  77. }
  78. else {
  79. UIHelp.ShowDialog({ content: loginRes.msg });
  80. }
  81. });
  82. }
  83. });
  84. }
  85. pay(orderId: string, order10cs: string, param: PayProductParam): void {
  86. let packageInfo = Gamecfg.packageInfo.getItem(Config.pid)
  87. let payUrl: string = packageInfo.wayhttp + "player/pay/" + Config.pid
  88. let orderData = {
  89. callbackurl: payUrl, // 游戏方充值回调地址
  90. paymoney: param.price.toString(),//游戏充值金额(单位为 元)
  91. custominfo: "",//游戏透传参数,回调时原样返回
  92. customorderid: orderId,//游戏透传参数,回调时原样返回
  93. productdesc: param.productName,//充值描述
  94. productfeecode: order10cs,
  95. };
  96. qg.asdk.asdkPay(orderData, function (res) {
  97. //console.log("pay return:"+JSON.stringify(res))
  98. if (res.code.toString() != "0") {
  99. //console.log("支付失败,失败原因:"+res.msg);
  100. } else {
  101. if (Config.paySuccAdokId != null) {
  102. clearInterval(Config.paySuccAdokId)
  103. Config.paySuccAdokId = null
  104. }
  105. Config.paySuccAdokIndex = 0
  106. Config.paySuccAdokId = setInterval(() => {
  107. Config.paySuccAdokIndex++
  108. if (Config.paySuccAdokIndex >= 5) {
  109. clearInterval(Config.paySuccAdokId)
  110. Config.paySuccAdokId = null
  111. }
  112. GameDataCenter.time.sendAdok()
  113. }, 1000)
  114. }
  115. })
  116. }
  117. // 上报角色数据
  118. reportRole(event: ReportRoleType): void {
  119. let playerinfo = {
  120. playerid: GameDataCenter.user.uuid, //角色ID
  121. playername: GameDataCenter.user.nickName, //角色名称
  122. playerlevel: GameDataCenter.sevBack.userInfo.a?.level?.toString(), //角色等级
  123. serverid: GameDataCenter.sevBack.userInfo.a?.sid, //区服ID
  124. servername: GameDataCenter.user.serverName //区服名称
  125. };
  126. qg.asdk.asdkSendRole(playerinfo, function (res) {
  127. //console.log('角色上报返回:'+JSON.stringify(res));
  128. });
  129. }
  130. showRewardAd(adId: string, kid: string, order11Id: string): void {
  131. qg.asdk.asdkRewardedAd(adId, (res) => {
  132. //console.log('广告返回:'+JSON.stringify(res));
  133. if (res.code.toString() != "0") {
  134. //console.log("看广告失败,失败原因:"+res.msg);
  135. } else {
  136. GameDataCenter.adVideo.onXiadanSucc() // 改成直接调用,不回调了
  137. }
  138. });
  139. }
  140. saveAppToDesktop(cb?: Function): void {
  141. qg.asdk.asdkCreateIcon(function (res) {
  142. //console.log('创建状态返回:'+JSON.stringify(res))
  143. if (res.code.toString() != "0") {
  144. //console.log("创建图标失败,失败原因:"+res.msg);
  145. } else {
  146. if (cb) {
  147. cb();
  148. }
  149. }
  150. })
  151. }
  152. logout(): void {
  153. qg.asdk.asdkQuit();
  154. }
  155. setClipboard(data: string, cb?: Function) {
  156. qg.setClipboardData({
  157. data: data,
  158. success: function () {
  159. //console.log("setClipboardData success" );
  160. UIHelp.ShowTips("已复制到剪切板");
  161. if (cb) {
  162. cb();
  163. }
  164. },
  165. fail: function () {
  166. //console.log("setClipboardData fail");
  167. },
  168. complete: function () {
  169. //console.log("setClipboardData complete");
  170. }
  171. });
  172. }
  173. }