123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- 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});
- const n = t("App");
- class o {
- constructor() {
- (this.isPayBy = !1),
- (this.isShowIosPay = !0),
- (this.env = 0),
- (this.localData = null),
- (this.receivedOrders = null);
- var t = cc.sys.localStorage.getItem("OrderData");
- (this.localData = t ? JSON.parse(t) : {}),
- cc.sys.os === cc.sys.OS_IOS && wx.onShow(this.wxGameOnShow.bind(this));
- }
- static get ins() {
- return this._ins || (this._ins = new o()), this._ins;
- }
- wxGameOnShow(t) {
- return s(this, void 0, void 0, function* () {
- this.payResolve && (this.payResolve(!0), (this.payResolve = null));
- });
- }
- getOrderDataByPayId(t) {
- return this.localData[t] || (this.receivedOrders && this.receivedOrders[t]);
- }
- getNotReceivedOrder(e = 5, i = 2e3) {
- return s(this, void 0, void 0, function* () {
- for (;;) {
- var t = yield n.default.Http.post(
- n.default.ConfigManager.gameConf.serverInfos.interface + "/Interface/midas/not_received_order.php",
- {token: n.default.GameDataMsr.playerInfo.token},
- 5,
- 3e3
- );
- if (t) {
- const e = JSON.parse(t);
- if (e && 0 == e.code && e.data && e.data.length) {
- this.receivedOrders = {};
- for (const i of e.data) {
- const e = n.default.Platform.getProductConfigById(i.gid);
- this.receivedOrders[e.payId] = i;
- }
- return e;
- }
- }
- if (e <= 0) return null;
- e--, yield n.default.TimerManager.sleep(i);
- }
- });
- }
- getConfig(i) {
- return s(this, void 0, void 0, function* () {
- var t = yield n.default.Http.post(
- n.default.ConfigManager.gameConf.serverInfos.interface + "/Interface/game_conf/get.php",
- {key: "payment_switch_" + i},
- 5,
- 1e3
- );
- let e;
- t && 0 == (e = JSON.parse(t)).code && (this.isShowIosPay = e.data);
- });
- }
- receive(e) {
- return s(this, void 0, void 0, function* () {
- var t = yield n.default.Http.post(
- n.default.ConfigManager.gameConf.serverInfos.interface + "/Interface/midas/receive.php",
- {token: n.default.GameDataMsr.playerInfo.token, oid: e},
- 5,
- 2e3
- );
- if (t) return JSON.parse(t);
- });
- }
- createOrder(e, i) {
- return s(this, void 0, void 0, function* () {
- let t = 3;
- do {
- const t = yield n.default.Http.post(
- n.default.ConfigManager.gameConf.serverInfos.interface + "/Interface/midas/create.php",
- {token: n.default.GameDataMsr.playerInfo.token, gid: e, gprice: Math.round(i)},
- 5,
- 2e3
- );
- if (t) {
- const e = JSON.parse(t);
- if (e && 0 == e.code) return e;
- }
- } while ((yield n.default.TimerManager.sleep(3e3), t--));
- return null;
- });
- }
- pay(t, i) {
- return new Promise(e => {
- wx.requestMidasPayment({
- mode: "game",
- currencyType: "CNY",
- env: this.env,
- offerId: "1450030214",
- buyQuantity: i,
- platform: "android",
- zoneId: "1",
- success(t) {
- console.warn("支付成功:", t), e(!0);
- },
- fail(t) {
- console.warn("支付失败:", t), e(!1);
- },
- complete() {}
- });
- });
- }
- deletaLocalData(t) {
- delete this.localData[t], cc.sys.localStorage.setItem("AppleOrderData", JSON.stringify(this.localData));
- }
- payByCustomerServiceConversation(e) {
- return new Promise(t => {
- wx.openCustomerServiceConversation({
- sendMessageTitle: e.desc,
- showMessageCard: !0,
- sendMessagePath: "good_" + e.id,
- sendMessageImg: "https://wxclient.gzqidong.cn/resource/Upload/resource/1658483721524057267.png",
- success: () => {
- this.payResolve = t;
- },
- fail: () => {
- t(!1);
- }
- });
- });
- }
- log(...t) {
- 1 === this.env && console.log("支付:", ...t);
- }
- buy(o, t, e, a) {
- return s(this, void 0, void 0, function* () {
- n.default.AnalyticMgr.recordInteractionAd();
- const e = n.default.Platform.getProductConfigByPayString(o);
- let i = 10 * e.cost;
- if ((this.env && (i = 10), cc.sys.os === cc.sys.OS_IOS)) {
- if (!this.isShowIosPay) return !1;
- let t = this.receivedOrders && this.receivedOrders[o];
- if (
- !(
- t ||
- (n.default.Platform.saveDataToLocal(),
- yield this.getNotReceivedOrder(0, 0),
- (t = this.receivedOrders && this.receivedOrders[o]))
- )
- ) {
- if (!(yield this.payByCustomerServiceConversation(e))) return !1;
- if ((n.default.EasyLoading.showLoadingByTime(20), !(yield this.getNotReceivedOrder())))
- return n.default.EasyLoading.hideLoading(), !1;
- t = this.receivedOrders && this.receivedOrders[o];
- }
- if (t) {
- const e = yield this.receive(t.oid);
- if (e && (delete this.receivedOrders[o], 0 == e.code))
- return (
- n.default.AnalyticMgr.recordUserBuy(o, t.oid, i / 10, 2),
- n.default.EasyLoading.hideLoading(),
- !0
- );
- }
- return n.default.EasyLoading.hideLoading(), !1;
- }
- const t = this.localData[o];
- if (t) t.retryCnt--, t.retryCnt <= 0 && this.deletaLocalData(o);
- else {
- if ((n.default.Platform.saveDataToLocal(), !(yield this.pay(o, i)))) return !1;
- this.addLocalData({payId: o, googlePayType: a, retryCnt: 5});
- }
- var s = yield this.createOrder(e.id, i);
- return (
- !!s &&
- (this.deletaLocalData(o),
- 0 == s.code && (n.default.AnalyticMgr.recordUserBuy(o, s.data.oid, i / 10, 1), !0))
- );
- });
- }
- addLocalData(t) {
- (this.localData[t.payId] = t), cc.sys.localStorage.setItem("AppleOrderData", JSON.stringify(this.localData));
- }
- getIsShowIosPay() {
- return cc.sys.os !== cc.sys.OS_IOS || this.isShowIosPay;
- }
- getIsDebug() {
- return !1 !== this.isShowIosPay;
- }
- isHaveAnomalyOrder(t) {
- return cc.sys.os === cc.sys.OS_IOS
- ? this.receivedOrders && this.receivedOrders[t]
- : this.localData && this.localData[t];
- }
- }
- (i.default = o)._ins = null;
|