簡體   English   中英

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>

而收據應包含此處記錄的元素

我正在使用模擬器,也正在使用IIS本地托管的模擬服務器從此處返回我的假產品清單

誰能告訴我我做錯了什么,或者這僅僅是微軟設計的? 我知道In App Purchase在模擬器上的行為會有所不同,有人知道我使用真實設備是否會產生預期的行為?

謝謝

這種行為是正常的,因為本地托管的Marketplace模擬無法返回任何交易的收據。

要測試我的應用內購買,我必須

  • 以Beta模式發布我的應用

  • 以0.00美元創建測試IAP

上面的代碼運行完美,並且根據網絡狀況幾乎立即引發了LicenseChanged事件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM