var t = require; var e = module; var i = exports; var s = (this && this.__awaiter) || function (t, n, r, l) { return new (r = r || Promise)(function (i, e) { function s(t) { try { a(l.next(t)); } catch (t) { e(t); } } function o(t) { try { a(l.throw(t)); } catch (t) { e(t); } } function a(t) { var e; t.done ? i(t.value) : ((e = t.value) instanceof r ? e : new r(function (t) { t(e); }) ).then(s, o); } a((l = l.apply(t, n || [])).next()); }); }; Object.defineProperty(i, "__esModule", {value: !0}), (i.WxgameVideo = void 0); const r = t("App"), o = t("WxMiniGameUtil"), a = (t("ADManageBase"), t("MidashiPay")), n = t("PlatformBase"), l = t("DybAd"), h = t("DybSdk"); (i.default = class extends n.default { constructor() { super(), (this.appid = "wx9b25fce9f330f9b6"), (this.isShare = !1), (this.isShareSuccess = !1), (this.failedTexts = [ "奖励获取失败,请分享到不同好友试试", "奖励获取失败,请分享到不同的群试试", "奖励获取失败,请分享到群试试" ]), (this.lastShareTime = -1), (this.pay = null), (this.isServiceOpen = !0), (this.isShowIosPay = !1), (this.wxVersion = ""), (this.dybSdk = null), (this._isNew = !1), (this._launchOptions = wx.getLaunchOptionsSync()), (this.systemInfo = wx.getSystemInfoSync()), wx.onMemoryWarning(t => { (IS_AUTO_RELEASE = !0), r.default.ResRecycle.startAutoRelease(), cc.sys.os === cc.sys.OS_IOS ? this.record({type: 50, tid: 0, numinc: 1}) : this.record({type: 50, tid: (t && t.level) || 1, numinc: 1}); }), wx.onShow(this.wxGameOnShow.bind(this)), o.WxMiniGameUtil.enablePassiveShare(), this.initDybSdk(), (this.wxVersion = versionInfo.packVersion.replace(/\./g, "_")); } isShowGameCircle() { return !0; } initPay() { this.pay = new a.default(); } initDybSdk() { this.dybSdk = new h.DybSdk(); } getPrice(t) { t = this.getProductConfigByPayString(t); return t ? "¥" + t.cost : null; } checkIsNotch() { return 0 < this.systemInfo.safeArea.left || 0 < this.systemInfo.safeArea.top; } isShowDebugUI() { return this.systemInfo.enableDebug || "devtools" === this.systemInfo.brand; } vibrator(t = 0) { wx.vibrateShort({type: "light", success: function () {}, fail: function () {}, complete: function () {}}); } getAdKey() { return r.default.RandomUtils.randomArray(["adunit-8912a66c11fe595c"]); } initAd() { super.initAd(); var t = new l.DybAd(this.getAdKey()); this._videoManage.setAdObj(t); } loadZipFile(s) { return new Promise(r => { if ("windows" != this.systemInfo.platform && "mac" != this.systemInfo.platform) { const l = cc.assetManager.cacheManager.cacheDir, e = cc.sys.os === cc.sys.OS_ANDROID ? "/a_" : "/i_", i = l + e + "file.zip"; fsUtils.exists(i, t => { if (t) r(!1); else { const n = REMOTE_SERVER_ROOT + "/remote/"; fsUtils.downloadFile( n + `/${e}${versionInfo.zipVersion}.zip`, i, null, t => { s(t.totalBytesWritten, t.totalBytesExpectedToWrite); }, (t, e) => t ? (cc.error("下载zip文件失败", t), void r(!1)) : (console.log("开始解压"), void fsUtils.unzip(e, l, e => { if (e) r(!1); else { console.log("解压成功"); const i = cc.assetManager.cacheManager.cachedFiles, s = Date.now(), o = fsUtils.readJsonSync(l + "/fileList.json"), a = o.length; for (let t = 0; t < a; t += 2) { const e = n + o[t], a = o[t].split("/")[0]; i.add(e, {url: `${l}/${a}/${o[t + 1]}`, lastTime: s, bundle: a}); } r(!0); } })) ); } }); } else r(!1); }); } wxGameOnShow(t) { Log.warn("wxGameOnShow"), (this._launchOptions = t), (this.isShareSuccess = this.isShare = !1); } checkRandom() { var t = Math.random(); return Log.warn("分享成功概率:", t, 0.4 < t), 0.4 < t; } loginWx() { return new Promise((e, t) => { wx.login({ success: t => { e(t); }, fail: () => { t(); } }); }); } getAccountInfoSync() { return wx.getAccountInfoSync(); } getSenceCode() { var t = this._launchOptions; return null != t.scene || null != t.scene ? t.scene : -1; } share(t, s) { return new Promise(() => { this.isShareSuccess = this.isShare = !0; let t = ""; for (var e in s.paramList) t += e + "=" + s.paramList[e] + "&"; (t = t.substr(0, t.length - 1)), (this.lastShareTime = Date.now()); var i = -1 == s.url.indexOf("http") ? r.default.ConfigManager.gameConf.serverInfos.interface + "/" + s.url : s.url; wx.shareAppMessage({title: s.title, imageUrl: i, query: t}); }); } getLaunchOptions() { let t, e, i, s = this._launchOptions, o = "", a = 0; if (s.query && s.query.chl) { var n = s.query; return { chl: (t = n.chl || r.default.ConfigManager.gameConf.channel), serverid: (e = n.serverid || r.default.ConfigManager.gameConf.serverInfos.serverid), upplayerid: (i = n.playerid || ""), sourceAppid: o, shareid: (a = n.shareType || 0) }; } return ( s.referrerInfo && s.referrerInfo.appId && (o = s.referrerInfo.appId), { chl: (t = r.default.ConfigManager.gameConf.channel), serverid: (e = r.default.ConfigManager.gameConf.serverInfos.serverid), upplayerid: i, sourceAppid: o, shareid: a } ); } getUseInfoFinish(t) { "string" == typeof t.reg_time ? new Date(t.reg_time).getTime() : t.reg_time; const e = wx.getAccountInfoSync(); if (this._isNew && "release" === e.miniProgram.envVersion) { const e = r.default.ConfigManager.gameConf; t.channel !== e.channel && r.default.Http.post( e.serverInfos.interface + "/Interface/user/set_channel.php", {token: this.loginInfo.token, channel: e.channel}, 3 ); } } syncData() { const t = Object.create(null, {syncData: {get: () => super.syncData}}); return s(this, void 0, void 0, function* () { return cc.sys.os === cc.sys.OS_IOS && (yield this.getIosPayConfig()), t.syncData.call(this); }); } getServiceConfig() { return s(this, void 0, void 0, function* () { var t = yield r.default.Http.post( r.default.ConfigManager.gameConf.serverInfos.interface + "/Interface/game_conf/get.php", {key: "server_switch_" + this.wxVersion}, 5, 1e3 ); let e; t && 0 == (e = JSON.parse(t)).code && (this.isServiceOpen = !!e.data); }); } initAccountServer() { const t = wx.getAccountInfoSync(), e = r.default.ConfigManager.getConfig("Server")[this.getServerId()]; if ("release" === t.miniProgram.envVersion) r.default.ConfigManager.gameConf.serverInfos.interface = e.stat; else { (r.default.ConfigManager.gameConf.serverInfos.game = e.games[0].game), (r.default.ConfigManager.gameConf.serverInfos.interface = e.stat); const t = r.default.ConfigManager.getServerCacheInfo(); t && ((r.default.ConfigManager.gameConf.serverInfos.game = t.game), (r.default.ConfigManager.gameConf.serverInfos.interface = t.stat)); } } initGameServer(e) { var t = wx.getAccountInfoSync(), i = r.default.ConfigManager.getConfig("Server")[this.getServerId()]; if ("release" === t.miniProgram.envVersion) if (this.isServiceOpen) { r.default.ConfigManager.gameConf.serverInfos.game = i.games[1].game; for (let t = i.games.length - 1; 1 < t; t--) { var s = i.games[t]; if (s.regTime && e > s.regTime) { (r.default.ConfigManager.gameConf.serverInfos.game = s.game), (r.default.ConfigManager.gameConf.channel = s.chl), console.log("根据注册时间选择了服务器:", s); break; } } } else r.default.ConfigManager.gameConf.serverInfos.game = i.games[0].game; } login() { return this.loginInfo.token ? new Promise(t => { wx.checkSession({ success: () => { t({code: 0, loginKey: this.loginInfo.token}); }, fail: () => { t(this.dybSdkLogin()); } }); }) : this.dybSdkLogin(); } dybSdkLogin() { return s(this, void 0, void 0, function* () { var t = yield this.dybSdk.getDybUserInfo(); if (!t) return {code: null, loginKey: null}; if (this.loginInfo.token) return Promise.resolve({code: 0, loginKey: this.loginInfo.token}); var e = yield r.default.Http.requestAsync( r.default.ConfigManager.gameConf.serverInfos.interface + "/api/login/simple", {code: t, channel: this.getChannel()}, "GET" ); Log.trace(">>>>>>>>>>>>>>>游客登录", e, t); e = JSON.parse(e); return 0 === e.code ? ((this.loginInfo.playerid = e.data.id), (this.loginInfo.token = e.token), r.default.SaveManage.save(n.LoginDataSaveKey.loginCache), r.default.DateUtils.secondNow() - e.data.reg_time < 60 && this.dybSdk.createRole(), {code: e.code, loginKey: e.token}) : {code: e.code, loginKey: null}; }); } getServerId() { return "elve"; } wxLogin() { return s(this, void 0, void 0, function* () { var {code: t} = yield this.loginWx(), e = this.getLaunchOptions(), i = this.getSenceCode(), i = yield r.default.Http.requestAsync( r.default.ConfigManager.gameConf.serverInfos.interface + "/api/login/weixin", {code: t, channel: e.chl, scene: i} ), i = JSON.parse(i); return 0 === i.code ? ((this.loginInfo.unionid = i.session.unionid), (this.loginInfo.playerid = i.data.id), (this.loginInfo.token = i.token), (this.loginInfo.openid = i.session.openid), r.default.SaveManage.save(n.LoginDataSaveKey.loginCache), {code: i.code, loginKey: i.token}) : {code: i.code, loginKey: null}; }); } saveWxUserInfo() { return s(this, void 0, void 0, function* () { let i = i => s(this, void 0, void 0, function* () { let t = 3; do { try { var e = yield r.default.Http.requestAsync( r.default.ConfigManager.gameConf.serverInfos.interface + "/Interface/data/save_user_info.php", { token: r.default.GameDataMsr.playerInfo.token, appid: this.appid, userInfo: JSON.stringify(i.userInfo), rawData: i.rawData, signature: i.signature, encryptedData: i.encryptedData, iv: i.iv, cloudID: i.cloudID } ); if (0 === JSON.parse(e).code) break; } catch (t) { console.log("saveUserInfo 失败", t); } } while ((yield r.default.TimerManager.sleep(1e3), --t)); }); wx.getSetting({ success(t) { t.authSetting["scope.userInfo"] ? wx.getUserInfo({ withCredentials: !1, success: t => { if (t) { const e = r.default.GameDataMsr.playerInfo; (e.nickName = t.userInfo.nickName), (e.head = t.userInfo.avatarUrl); } }, fail: () => {} }) : wx.authorize({ scope: "scope.userInfo", success() { wx.getUserInfo({ success: t => { if (t) { const e = r.default.GameDataMsr.playerInfo; (e.nickName = t.userInfo.nickName), e.head != t.userInfo.avatarUrl && ((e.head = t.userInfo.avatarUrl), i(t)); } }, fail: () => {} }); }, fail: () => {} }); }, fail: () => {} }); }); } buy(i) { return s(this, void 0, void 0, function* () { r.default.EasyLoading.showLoading(); var t = this.getProductConfigByPayString(i), e = yield this.dybSdk.buy(t); return e && (this.playerSpendMoney = t.cost), r.default.EasyLoading.hideLoading(), e; }); } resetGame() { wx.restartMiniProgram(); } getIosPayConfig() { return s(this, void 0, void 0, function* () { var t = yield r.default.Http.requestAsync( r.default.ConfigManager.gameConf.serverInfos.interface + `/api/config/payment_switch/${this.wxVersion}`, {}, "GET" ); let e; t && 0 == (e = JSON.parse(t)).code && (this.isShowIosPay = e.data[this.wxVersion]); }); } getIsShowPay() { return cc.sys.os !== cc.sys.OS_IOS || this.isShowIosPay; } syncDataCallBack() { super.syncDataCallBack(), r.default.AnalyticMgr.dayStatistics(this.appid), this.saveWxUserInfo(); } isAuthorization() { return s(this, void 0, void 0, function* () { return new Promise(e => { wx.getSetting({ success(t) { e(t.authSetting["scope.userInfo"]); }, fail: () => { e(!1); } }); }); }); } resumOrder() { return s(this, void 0, void 0, function* () { r.default.EasyLoading.showLoading(), yield this.dybSdk.getNotReceivedOrder(), r.default.EasyLoading.hideLoading(); }); } }), (i.WxgameVideo = class { constructor(t) { (this.onLoadAdComplete = null), (this.onLoadAdFail = null), (this.adState = 0), (this.id = t); } addADLoadSuccessCallBack() { this.onLoadAdComplete(); } addADloadFailCallBack(t) { cc.log("addADloadFailCallBack error", t), this.onLoadAdFail(t); } addADCloesCallBack(t) { let e = {code: 1}; ((t && t.isEnded) || void 0 === t) && (e.code = 0), this.onShowAdComplete(e); } init() { this.initAd(); } initAd() { cc.log("adUnitId:", this.id); let t = (this.adVideo = wx.createRewardedVideoAd({adUnitId: this.id, multiton: !0})); t.onLoad(this.addADLoadSuccessCallBack.bind(this)), t.onError(this.addADloadFailCallBack.bind(this)), t.onClose(this.addADCloesCallBack.bind(this)), (this.adState = 1); } load() { return cc.log("加载广告"), this.adVideo.load(); } show() { return this.adVideo.show(); } });