簡體   English   中英

處理Windows App Store應用內購買收據

[英]Handling Windows App Store In-app purchase receipt

我想處理這種情況,用戶在這台機器上執行購買,但是要在另一台機器上運行功能。

我知道我必須檢查收據。 我想知道,這是正確的方法嗎? 請注意,我繞過了簽名檢查。 因為,我需要設置一個我現在不想考慮的后端系統。 我什至無法在本地執行簽名檢查,因為Windows 8 Store App不提供System.Security.Cryptography API。

我想知道以下代碼片段是否足以應付大多數情況? 注意,我無法測試代碼,因為我需要發布新版本才能測試代碼。

private async void history_Click(object sender, RoutedEventArgs e)
{
    bool OK = true;

    // The next line is commented out for production/release.       
    LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
    if (!licenseInformation.ProductLicenses["PremiumFeatures"].IsActive)
    {
        try
        {
            // The customer doesn't own this feature, so 
            // show the purchase dialog.

            String receipt = await CurrentApp.RequestProductPurchaseAsync("PremiumFeatures", true);
            // the in-app purchase was successful

            licenseInformation = CurrentApp.LicenseInformation;
            if (licenseInformation.ProductLicenses["PremiumFeatures"].IsActive || receipt.Length > 0)
            {
                // In some situations, you may need to verify that a user made an in-app purchase. 
                // For example, imagine a game that offers downloaded content. If the user who 
                // purchased the content wants to play the game on another PC, you need to verify 
                // that the user purchased the content.
                //
                // Receipt is used to handle such situation.
                //
                // Validate receipt is complicated, as it requires us to setup a backend system.
                // http://msdn.microsoft.com/en-US/library/windows/apps/jj649137
                //
                // I will just assume non empty receipt string means valid receipt.
                OK = true;
            }
            else
            {
                OK = false;
            }
        }
        catch (Exception)
        {
            // The in-app purchase was not completed because 
            // an error occurred.
            OK = false;
        }
    }
    else
    {
        // The customer already owns this feature.
        OK = true;
    }

    if (OK)
    {
        // Launch premium feature.
        Frame.Navigate(typeof(HistoryPage));
    }
}

您可以使用CurrentAppSimulator而不是CurrentApp來測試代碼。 在我看來還可以。

暫無
暫無

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

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