gpt4 book ai didi

c# - purchase.products.get 忽略 productId 值并在 ProductPurchase 中返回 null

转载 作者:行者123 更新时间:2023-12-02 09:40:27 30 4
gpt4 key购买 nike

我正在向 google Android Publisher api 提出请求检查提供的应用内购买的 purchaseToken 是否正确。第一个问题是产品 ID 被忽略,我可以输入任何内容作为参数。只需要包名和purchaseToken是正确的。其次,为什么 ProductPurchase 中的 productId 和 purchaseToken 为空。我想检查提供的 purchaseToken 是否与 productId 匹配。当 productId 可以是任何东西并且没有返回响应时,我如何检查这对于特定的应用内购买 productId 是否有效?

    private static Task<ProductPurchase> GetInAppPurchase(string packageName, string productId, string purchaseToken)
{
GoogleCredential credential;
using (Stream stream = new FileStream(@"api.json", FileMode.Open, FileAccess.Read, FileShare.Read))
{
credential = GoogleCredential.FromStream(stream);
}

string[] scopes = {
AndroidPublisherService.Scope.Androidpublisher
};
credential = credential.CreateScoped(scopes);

BaseClientService.Initializer initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "My Application"
};



AndroidPublisherService service = new AndroidPublisherService(initializer);

return service.Purchases.Products.Get(packageName, productId, purchaseToken).ExecuteAsync();
}

private static void TestGooglePlayPurchaseApi()
{
string packageName = "validPackageName";
string productId = "validOrInvalidProductName";
string purchaseToken = "validPurchaseToken";

ProductPurchase purchase = GetInAppPurchase(packageName, productId, purchaseToken).Result;

Console.WriteLine("Kind: " + purchase.Kind);
Console.WriteLine("Quantity: " + purchase.Quantity);
Console.WriteLine("AcknowledgementState: " + purchase.AcknowledgementState!);
Console.WriteLine("ConsumptionState: " + purchase.ConsumptionState!);
Console.WriteLine("DeveloperPayload: " + purchase.DeveloperPayload);
Console.WriteLine("ETag: " + purchase.ETag);
Console.WriteLine("OrderId: " + purchase.OrderId);
Console.WriteLine("ProductId: " + purchase.ProductId);
Console.WriteLine("PurchaseState: " + purchase.PurchaseState!);
Console.WriteLine("PurchaseToken: " + purchase.PurchaseToken);
Console.WriteLine("PurchaseType: " + purchase.PurchaseType!);
Console.WriteLine("RegionCode: " + purchase.RegionCode);
Console.WriteLine("PurchaseTimeMillis: " + purchase.PurchaseTimeMillis);
Console.WriteLine("ObfuscatedExternalAccountId: " + purchase.ObfuscatedExternalAccountId);
Console.WriteLine("ObfuscatedExternalProfileId: " + purchase.ObfuscatedExternalProfileId);
}
这就是我正在接受的:
Kind: androidpublisher#productPurchase
Quantity:
AcknowledgementState: 1
ConsumptionState: 1
DeveloperPayload: {"developerPayload":"","is_free_trial":false,"has_introductory_price_trial":false,"is_updated":false,"accountId":""}
ETag:
OrderId: YYY.XXXX-XXXX-XXXX-XXXXX
ProductId:
PurchaseState: 0
PurchaseToken:
PurchaseType: 0
RegionCode: PL
PurchaseTimeMillis: 1601915754698
ObfuscatedExternalAccountId:
ObfuscatedExternalProfileId:
为什么 ProductId 为空?

最佳答案

如果您的数据库中只有一项,它将为空。很奇怪,但事实就是如此。
添加同一类别的第二个项目,您将开始获得正确的响应值。

关于c# - purchase.products.get 忽略 productId 值并在 ProductPurchase 中返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64217553/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com