0
我想在這種情況下處理情況,用戶在此機器上執行購買,但在另一臺機器上運行該功能。處理Windows App Store應用內購買收據
我知道我必須檢查收據。我想知道,這是否是正確的方法?請注意,我繞過簽名檢查。因爲我需要建立一個我現在不想考慮的後端系統。我甚至無法在本地執行簽名檢查,因爲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));
}
}