MidashiPay.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s =
  5. (this && this.__awaiter) ||
  6. function (t, n, r, l) {
  7. return new (r = r || Promise)(function (i, e) {
  8. function s(t) {
  9. try {
  10. a(l.next(t));
  11. } catch (t) {
  12. e(t);
  13. }
  14. }
  15. function o(t) {
  16. try {
  17. a(l.throw(t));
  18. } catch (t) {
  19. e(t);
  20. }
  21. }
  22. function a(t) {
  23. var e;
  24. t.done
  25. ? i(t.value)
  26. : ((e = t.value) instanceof r
  27. ? e
  28. : new r(function (t) {
  29. t(e);
  30. })
  31. ).then(s, o);
  32. }
  33. a((l = l.apply(t, n || [])).next());
  34. });
  35. };
  36. Object.defineProperty(i, "__esModule", {value: !0});
  37. const n = t("App");
  38. class o {
  39. constructor() {
  40. (this.isPayBy = !1),
  41. (this.isShowIosPay = !0),
  42. (this.env = 0),
  43. (this.localData = null),
  44. (this.receivedOrders = null);
  45. var t = cc.sys.localStorage.getItem("OrderData");
  46. (this.localData = t ? JSON.parse(t) : {}),
  47. cc.sys.os === cc.sys.OS_IOS && wx.onShow(this.wxGameOnShow.bind(this));
  48. }
  49. static get ins() {
  50. return this._ins || (this._ins = new o()), this._ins;
  51. }
  52. wxGameOnShow(t) {
  53. return s(this, void 0, void 0, function* () {
  54. this.payResolve && (this.payResolve(!0), (this.payResolve = null));
  55. });
  56. }
  57. getOrderDataByPayId(t) {
  58. return this.localData[t] || (this.receivedOrders && this.receivedOrders[t]);
  59. }
  60. getNotReceivedOrder(e = 5, i = 2e3) {
  61. return s(this, void 0, void 0, function* () {
  62. for (;;) {
  63. var t = yield n.default.Http.post(
  64. n.default.ConfigManager.gameConf.serverInfos.interface + "/Interface/midas/not_received_order.php",
  65. {token: n.default.GameDataMsr.playerInfo.token},
  66. 5,
  67. 3e3
  68. );
  69. if (t) {
  70. const e = JSON.parse(t);
  71. if (e && 0 == e.code && e.data && e.data.length) {
  72. this.receivedOrders = {};
  73. for (const i of e.data) {
  74. const e = n.default.Platform.getProductConfigById(i.gid);
  75. this.receivedOrders[e.payId] = i;
  76. }
  77. return e;
  78. }
  79. }
  80. if (e <= 0) return null;
  81. e--, yield n.default.TimerManager.sleep(i);
  82. }
  83. });
  84. }
  85. getConfig(i) {
  86. return s(this, void 0, void 0, function* () {
  87. var t = yield n.default.Http.post(
  88. n.default.ConfigManager.gameConf.serverInfos.interface + "/Interface/game_conf/get.php",
  89. {key: "payment_switch_" + i},
  90. 5,
  91. 1e3
  92. );
  93. let e;
  94. t && 0 == (e = JSON.parse(t)).code && (this.isShowIosPay = e.data);
  95. });
  96. }
  97. receive(e) {
  98. return s(this, void 0, void 0, function* () {
  99. var t = yield n.default.Http.post(
  100. n.default.ConfigManager.gameConf.serverInfos.interface + "/Interface/midas/receive.php",
  101. {token: n.default.GameDataMsr.playerInfo.token, oid: e},
  102. 5,
  103. 2e3
  104. );
  105. if (t) return JSON.parse(t);
  106. });
  107. }
  108. createOrder(e, i) {
  109. return s(this, void 0, void 0, function* () {
  110. let t = 3;
  111. do {
  112. const t = yield n.default.Http.post(
  113. n.default.ConfigManager.gameConf.serverInfos.interface + "/Interface/midas/create.php",
  114. {token: n.default.GameDataMsr.playerInfo.token, gid: e, gprice: Math.round(i)},
  115. 5,
  116. 2e3
  117. );
  118. if (t) {
  119. const e = JSON.parse(t);
  120. if (e && 0 == e.code) return e;
  121. }
  122. } while ((yield n.default.TimerManager.sleep(3e3), t--));
  123. return null;
  124. });
  125. }
  126. pay(t, i) {
  127. return new Promise(e => {
  128. wx.requestMidasPayment({
  129. mode: "game",
  130. currencyType: "CNY",
  131. env: this.env,
  132. offerId: "1450030214",
  133. buyQuantity: i,
  134. platform: "android",
  135. zoneId: "1",
  136. success(t) {
  137. console.warn("支付成功:", t), e(!0);
  138. },
  139. fail(t) {
  140. console.warn("支付失败:", t), e(!1);
  141. },
  142. complete() {}
  143. });
  144. });
  145. }
  146. deletaLocalData(t) {
  147. delete this.localData[t], cc.sys.localStorage.setItem("AppleOrderData", JSON.stringify(this.localData));
  148. }
  149. payByCustomerServiceConversation(e) {
  150. return new Promise(t => {
  151. wx.openCustomerServiceConversation({
  152. sendMessageTitle: e.desc,
  153. showMessageCard: !0,
  154. sendMessagePath: "good_" + e.id,
  155. sendMessageImg: "https://wxclient.gzqidong.cn/resource/Upload/resource/1658483721524057267.png",
  156. success: () => {
  157. this.payResolve = t;
  158. },
  159. fail: () => {
  160. t(!1);
  161. }
  162. });
  163. });
  164. }
  165. log(...t) {
  166. 1 === this.env && console.log("支付:", ...t);
  167. }
  168. buy(o, t, e, a) {
  169. return s(this, void 0, void 0, function* () {
  170. n.default.AnalyticMgr.recordInteractionAd();
  171. const e = n.default.Platform.getProductConfigByPayString(o);
  172. let i = 10 * e.cost;
  173. if ((this.env && (i = 10), cc.sys.os === cc.sys.OS_IOS)) {
  174. if (!this.isShowIosPay) return !1;
  175. let t = this.receivedOrders && this.receivedOrders[o];
  176. if (
  177. !(
  178. t ||
  179. (n.default.Platform.saveDataToLocal(),
  180. yield this.getNotReceivedOrder(0, 0),
  181. (t = this.receivedOrders && this.receivedOrders[o]))
  182. )
  183. ) {
  184. if (!(yield this.payByCustomerServiceConversation(e))) return !1;
  185. if ((n.default.EasyLoading.showLoadingByTime(20), !(yield this.getNotReceivedOrder())))
  186. return n.default.EasyLoading.hideLoading(), !1;
  187. t = this.receivedOrders && this.receivedOrders[o];
  188. }
  189. if (t) {
  190. const e = yield this.receive(t.oid);
  191. if (e && (delete this.receivedOrders[o], 0 == e.code))
  192. return (
  193. n.default.AnalyticMgr.recordUserBuy(o, t.oid, i / 10, 2),
  194. n.default.EasyLoading.hideLoading(),
  195. !0
  196. );
  197. }
  198. return n.default.EasyLoading.hideLoading(), !1;
  199. }
  200. const t = this.localData[o];
  201. if (t) t.retryCnt--, t.retryCnt <= 0 && this.deletaLocalData(o);
  202. else {
  203. if ((n.default.Platform.saveDataToLocal(), !(yield this.pay(o, i)))) return !1;
  204. this.addLocalData({payId: o, googlePayType: a, retryCnt: 5});
  205. }
  206. var s = yield this.createOrder(e.id, i);
  207. return (
  208. !!s &&
  209. (this.deletaLocalData(o),
  210. 0 == s.code && (n.default.AnalyticMgr.recordUserBuy(o, s.data.oid, i / 10, 1), !0))
  211. );
  212. });
  213. }
  214. addLocalData(t) {
  215. (this.localData[t.payId] = t), cc.sys.localStorage.setItem("AppleOrderData", JSON.stringify(this.localData));
  216. }
  217. getIsShowIosPay() {
  218. return cc.sys.os !== cc.sys.OS_IOS || this.isShowIosPay;
  219. }
  220. getIsDebug() {
  221. return !1 !== this.isShowIosPay;
  222. }
  223. isHaveAnomalyOrder(t) {
  224. return cc.sys.os === cc.sys.OS_IOS
  225. ? this.receivedOrders && this.receivedOrders[t]
  226. : this.localData && this.localData[t];
  227. }
  228. }
  229. (i.default = o)._ins = null;