You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PlayFab Economy v2 Google Play消耗型内购兑换失败求助

问题描述
  • 使用PlayFab Economy v2的PlayFabEconomyAPI.RedeemGooglePlayInventoryItems接口兑换安卓应用内购时失败,iOS版本运行正常
  • 产品ID「1000_diamonds」在Google Play与PlayFab的「市场映射」(对应「GooglePlay」键名)中完全匹配
  • Google Play购买流程正常,已收到购买凭证邮件,但PlayFab端兑换报错:

Inventory/RedeemGooglePlayInventoryItems: 生产环境下的Marketplace API 'PurchasesProductsGet'返回HTTP状态码400,错误码400,针对AlternateId“1000_diamonds”的错误信息为“Invalid Value”。

  • 请求代码如下:
RedeemGooglePlayInventoryItemsRequest request = new()
{
    Purchases = new List<GooglePlayProductPurchase> {
        new GooglePlayProductPurchase() {
            ProductId = purchasePayload.PayloadData?.JsonData?.productId,
            Token = purchasePayload.PayloadData?.signature
        }
    }
};
  • 日志显示purchasePayload.PayloadData?.JsonData?.productId值为「1000_diamonds」,且Token不为空;Google Cloud Platform账号中ProductPurchasesService.Get请求错误率100%
  • 已完成OAuth客户端(Web应用/安卓)、服务账号的创建与PlayFab配置,授予对应权限并添加至Google Play用户,启用Google Play服务,游戏登录功能正常;尝试过重新配置所有内容、在兑换请求中加入entity参数,问题仍未解决

排查与解决步骤
  1. 修正Token参数传递错误
    代码中错误将signature传给了Token字段,PlayFab调用Google Play API需要的是购买返回的purchaseToken而非签名。修正代码如下:

    RedeemGooglePlayInventoryItemsRequest request = new()
    {
        Purchases = new List<GooglePlayProductPurchase> {
            new GooglePlayProductPurchase() {
                ProductId = purchasePayload.PayloadData?.JsonData?.productId,
                Token = purchasePayload.PayloadData?.PurchaseToken // 替换为正确的购买Token字段
            }
        }
    };
    
  2. 验证服务账号权限与关联

    • 确认服务账号拥有Google Play Android Developer角色,且已在Google Play控制台「用户和权限」中添加,授予「查看应用权限」和「管理订单权限」
    • 检查PlayFab控制台中配置的服务账号密钥是否正确,无过期或格式错误
  3. 确认产品类型匹配

    • 检查「1000_diamonds」在Google Play中的产品类型(消耗型/非消耗型/订阅),PlayFab市场映射需对应匹配的类型,否则PurchasesProductsGet会返回无效值错误
    • 若为订阅产品,需使用订阅专属的兑换接口,而非普通产品兑换接口
  4. 区分生产与测试环境

    • 确保使用生产环境的PlayFab密钥与Google Play生产版本,避免用测试购买凭证在生产环境兑换,反之亦然
    • 若为测试购买,需确认Google Play控制台已添加测试账号,且PlayFab配置允许测试购买
  5. 检查GCP API启用状态
    登录GCP控制台,确认Google Play Android Developer API已启用,且服务账号拥有该API的调用权限

内容的提问来源于stack exchange,提问作者vklymenko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 18:25:00