WP8.1 Silverlight - 许可证上的意外许可证信息已更改

本文关键字:许可证 信息 意外 Silverlight WP8 | 更新日期: 2023-09-27 17:56:52

我正在尝试检测客户端应用程序进行的应用内购买。

我正在使用以下代码

public async Task InitializeInAppPurchase()
{
    CurrentApp.LicenseInformation.LicenseChanged += LicenseInformation_LicenseChanged;
    var listingInformationTask = CurrentApp.LoadListingInformationAsync();
    var listingInformation = await listingInformationTask;
    PurchaseProduct(listingInformation.ProductListings.First().Value.ProductId);
}
private void LicenseInformation_LicenseChanged()
{
    var receipt = CurrentApp.GetAppReceiptAsync().AsTask().Result;
    Console.Writeline(receipt);
}
async void PurchaseProduct(string productId)
{
    try
    {
        // Kick off purchase; don't ask for a receipt when it returns
        var result = await CurrentApp.RequestProductPurchaseAsync(productId);
        // Now that purchase is done, give the user the goods they paid for
        // (DoFulfillment is defined later)
        await DoFulfillment(result);
    }
    catch (Exception ex)
    {
        // When the user does not complete the purchase (e.g. cancels or navigates back from the Purchase Page), an exception with an HRESULT of E_FAIL is expected.
    }
}
//
// Fulfillment of consumable in-app products
public async Task DoFulfillment(PurchaseResults result)
{
    var productLicenses = CurrentApp.LicenseInformation.ProductLicenses;
    // Check fulfillment for consumable products with hard-coded asset counts
    await MaybeGiveMeGold(productLicenses["Test1"], 50, result);
}
// Count is passed in as a parameter
async Task MaybeGiveMeGold(ProductLicense license, int goldCount, PurchaseResults result)
{
    if (license.IsConsumable && license.IsActive)
    {
        await CurrentApp.ReportConsumableFulfillmentAsync(license.ProductId, result.TransactionId);
    }
}

当引发事件 LicenseChanged 时,我惊讶地发现收据不包括刚刚发生的交易。我明白这个

 <Receipt Version="1.0" ReceiptDate="2015-06-18T04:41:31.867Z" ReceiptDeviceId="4e362949-acc3-fe3a-e71b-89893eb4f528" CertificateId="FB3D3A6455095D2C4A841AA8B8E20661B10A6112" xmlns="http://schemas.microsoft.com/windows/2012/store/receipt">
    <AppReceipt Id="8ffa256d-eca8-712a-7cf8-cbf5522df24b" AppId="01e34c43-fdd8-47a6-a8ba-36ad5b880de9" PurchaseDate="2015-06-18T04:41:31.867Z" LicenseType="Full" />
</Receipt>

而收据应包含此处记录的元素

我正在使用模拟器,并且我还使用在IIS中本地托管的模拟服务器从此处返回我的假产品列表

谁能告诉我我是否做错了什么,或者这仅仅是Microsoft设计的?我知道应用内购买在模拟器上的行为不同,有谁知道如果我使用真实设备,我是否会有预期的行为?

谢谢

WP8.1 Silverlight - 许可证上的意外许可证信息已更改

这种行为是正常的,因为本地托管的市场模拟无法返回任何交易的收据。

要测试我的应用内购买,我必须

  • 在测试模式下发布我的应用

  • 以 0.00$ 的价格创建测试 IAP

上面的代码运行良好,并且根据网络条件几乎立即引发 LicenseChanged 事件。