refactor(googleplay): 支持purchaseOptionId作为备选商品ID

This commit is contained in:
2026-04-10 14:30:53 +08:00
parent c8f8311cae
commit d654777a02
3 changed files with 8 additions and 2 deletions

View File

@@ -146,7 +146,7 @@ public class GooglePlayApiClient {
JsonNode offerDetails = firstLineItem.path("productOfferDetails");
String state = mapOneTimeState(text(root.path("purchaseStateContext"), "purchaseState"));
String purchaseOptionId = text(offerDetails, "purchaseOptionId");
// 修正:一次性购买的订单号字段名为 "orderId"
String googleOrderId = text(root, "orderId");
@@ -156,6 +156,7 @@ public class GooglePlayApiClient {
.productId(text(firstLineItem, "productId"))
.productType(GooglePlayConstants.PRODUCT_TYPE_ONE_TIME)
.purchaseToken(purchaseToken)
.purchaseOptionId(purchaseOptionId)
.orderKey(resolveOrderKey(googleOrderId, purchaseToken))
.googleOrderId(googleOrderId)
.linkedPurchaseToken(null)

View File

@@ -32,7 +32,10 @@ public class GooglePlayStateService {
@Transactional(rollbackFor = Exception.class)
public GooglePlaySyncResult sync(GooglePlaySyncCommand command, GooglePlayPurchaseSnapshot snapshot) {
KeyboardProductItems product = loadProduct(snapshot.getBasePlanId());
String productId = (snapshot.getBasePlanId() != null) ?
snapshot.getBasePlanId() :
snapshot.getPurchaseOptionId();
KeyboardProductItems product = loadProduct(productId);
GooglePlayOrder order = buildOrder(command, snapshot);
GooglePlayPurchaseToken token = buildToken(command, snapshot);
// 先保存订单以确保 order.id 已生成,钱包充值等权益分发依赖 order.id 写入交易流水

View File

@@ -56,4 +56,6 @@ public class GooglePlayPurchaseSnapshot {
private Date lastSyncedAt;
private String rawResponse;
private String purchaseOptionId;
}