fix: 部分活动未上报yinli_Pay

This commit is contained in:
guanchao
2026-10-15 15:37:27 +08:00
parent af38c6c9ec
commit e279afa31d
9 changed files with 423 additions and 76 deletions
+17 -2
View File
@@ -1,6 +1,7 @@
import Utils from "../Pay/Utils";
import ActivityScheduleService from "./ActivityScheduleService";
import ActivityBundleLoader from "./ActivityBundleLoader";
import { MiniGameSdk } from "../../Sdk/MiniGameSdk";
const FIELDS: { [id: string]: string } = { "1001": "coinAmount", "2001": "freezeAmount", "2002": "hammerAmount", "2003": "magicAmount", "2005": "userPowerTime" };
const LOCAL: { [field: string]: string } = { coinAmount: "coin", freezeAmount: "freezeAmount", hammerAmount: "hammerAmount", magicAmount: "magicAmount", userPowerTime: "userPowerTime" };
@@ -192,6 +193,14 @@ export default class PyramidService {
cc.warn("[Pyramid] 支付结果查询失败,继续重试", error);
}
if (result && (result.paymentStatus === "succeeded" || result.paymentStatus === "closed")) {
if (result.paymentStatus === "succeeded") {
try {
const price = Number(result.goodsPrice ?? pending.price) * Number(result.itemCount ?? 1);
const productId = result.itemid || pending.productId;
if (!Number.isSafeInteger(price) || price <= 0 || !productId) throw new Error("订单上报信息缺失");
MiniGameSdk.API.yinli_Pay(price, pending.orderId, productId);
} catch (error) { cc.warn("[Pyramid] 付费上报失败", error); }
}
delete this.journal.confirmingOrder; this.paymentRetryBlocked = false; this.save(); await this.refresh(); return;
}
if (attempt < this.paymentPollDelays.length)
@@ -213,7 +222,10 @@ export default class PyramidService {
}
private static async openIosCustomerPayment(platform: any, state: any, level: any,
generation: number, orderId: string): Promise<void> {
const pending = { orderId, periodId: state.periodId, level: state.currentLevel, channel: "ios_customer" };
const pending = {
orderId, periodId: state.periodId, level: state.currentLevel, channel: "ios_customer",
price: level.itemPrice, productId: level.itemId
};
this.journal.confirmingOrder = pending; this.save(); this.emit();
const opened: any = await new Promise(resolve => Utils.GoKEFu({
outTradeNo: orderId, price: level.itemPrice, payment_name: level.itemId, payment_count: 1,
@@ -260,7 +272,10 @@ export default class PyramidService {
// if (result.paymentFailed) { platform.showToast({ title: "取消充值", icon: "none" }); return; }
if (result.err) throw Object.assign(new Error(result.err), result);
// Only the SDK success callback creates durable payment confirmation work.
this.journal.confirmingOrder = { orderId: result.outTradeNo, periodId: state.periodId, level: state.currentLevel };
this.journal.confirmingOrder = {
orderId: result.outTradeNo, periodId: state.periodId, level: state.currentLevel,
price: level.itemPrice, productId: level.itemId
};
this.paymentRetryBlocked = false; this.save(); this.emit(); await this.confirmPayment(true);
});
}
+55
View File
@@ -260,6 +260,7 @@ export default class Utils {
// callBack("请求支付超时");
// }, timeoutDuration);
const orderNumber = res.data.outTradeNo;
if (/^jungle_treasure_[1-8]$/.test(id)) Utils.rememberJunglePayment(orderNumber, id, price * count, false);
try {
//@ts-ignore
wx.requestMidasPaymentGameItem({
@@ -424,6 +425,7 @@ export default class Utils {
else if (/^jungle_treasure_\d+$/.test(String(iosPayInfo.payment_name || ""))) {
cc.fx.GameConfig.GM_INFO.iosJungleOrder = null;
cc.fx.GameConfig.GM_INFO.iosJungleOrder = order;
Utils.rememberJunglePayment(order, iosPayInfo.payment_name, iosPayInfo.price * iosPayInfo.payment_count, true);
}
else if (/^gold_miner(?:_\d+)?$/.test(String(iosPayInfo.payment_name || ""))) {
// The activity persists its order separately; do not overwrite shop orders.
@@ -473,6 +475,59 @@ export default class Utils {
});
}
private static jungleRecovery: Promise<void> = null;
static junglePaymentKey(): string {
return "junglePayments:v1:" + this.apiBaseUrl() + ":" + String(cc.fx.GameConfig.GM_INFO.uid || "");
}
static rememberJunglePayment(order: string, productId: string, price: number, ios: boolean): void {
const key = this.junglePaymentKey(), orders = cc.fx.StorageMessage.getStorage(key) || {};
orders[order] = { productId, price, ios };
cc.fx.StorageMessage.setStorage(key, orders);
}
static forgetJunglePayment(order: string): void {
const key = this.junglePaymentKey(), orders = cc.fx.StorageMessage.getStorage(key) || {};
delete orders[order]; cc.fx.StorageMessage.setStorage(key, orders);
}
/** Login recovery only; the activity still reports its normal payment callbacks. */
static recoverJunglePayments(loginOrders: any[]): Promise<void> {
if (this.jungleRecovery) return this.jungleRecovery;
const key = this.junglePaymentKey(), uid = cc.fx.GameConfig.GM_INFO.uid, token = cc.fx.GameConfig.GM_INFO.token;
for (const order of loginOrders) {
if (/^jungle_treasure_[1-8]$/.test(order.itemid))
this.rememberJunglePayment(order.outTradeNo, order.itemid, Number(order.goodsPrice) * Number(order.itemCount || 1), order.type === "ios");
}
const orders = cc.fx.StorageMessage.getStorage(key) || {};
const current = () => key === this.junglePaymentKey() && token === cc.fx.GameConfig.GM_INFO.token;
this.jungleRecovery = (async () => {
for (const order of Object.keys(orders)) {
if (!current()) return;
try {
const payment = orders[order];
const query = (route: string): Promise<any> => new Promise(resolve => this.POST(route, { uid, outTradeNo: order }, resolve));
let response = await query("wx/getPayInfo");
if (!current()) return;
let paid = response?.code === 1 && response.data?.pay_state === 2;
if (!paid && payment.ios) {
response = await query("wx/iosgetPayInfo");
if (!current()) return;
paid = response?.code === 1;
}
if (!paid) continue;
const completed: any = await new Promise(resolve => this.setPayInfo(resolve, order));
if (!current()) return;
// The activity may have reported while the query was in flight.
if (completed?.code !== 1 || !(cc.fx.StorageMessage.getStorage(key) || {})[order]) continue;
if (!Number.isSafeInteger(payment.price) || payment.price <= 0) throw new Error("订单金额缺失");
MiniGameSdk.API.yinli_Pay(payment.price, order, "补发充值成功" + payment.productId);
this.forgetJunglePayment(order);
} catch (error) { console.warn("丛林宝藏付费补报待重试", order, error); }
}
})().then(() => { this.jungleRecovery = null; }, error => {
this.jungleRecovery = null; console.warn("丛林宝藏付费补报待重试", error);
});
return this.jungleRecovery;
}
//#region ios获取支付结果
/** ios获取支付结果 */
static getIosPayInfo(order, callBack) {