WP8.1 Silverlight - LicenseChanged 上的意外许可证信息

WP8.1 Silverlight - Unexpected License info on LicenseChanged

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

我正在使用以下代码

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>

而收据应包含记录的要素 here

我正在使用模拟器,我还使用本地托管在 IIS 中的模拟服务器来 return 来自 here

的假 ProductListings

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

谢谢

这种行为是正常的,因为本地托管的 Marketplace 模拟无法return 收到任何交易的收据。

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

  • 以 Beta 模式发布我的应用程序

  • 以 0.00 美元创建测试 IAP

上面的代码运行良好,根据网络状况,LicenseChanged 事件几乎是瞬间引发的。