在应用内购买、WinRT、C#

In app purchase, WinRT, C#

我正在尝试使用 C# 在我的应用程序(WinRT 平台)中实施 IaP,但我找不到任何好的教程甚至文档(只有 docum。我发现是针对 Silverlight 的...)。

我已经为它创建了一个测试版应用程序和一个免费的 IaP。我已经在本地测试了它(使用 CurrentAppSimulator)并且一切正常,但现在在那个测试版中(我发现创建测试版是如何使用真实的 CurrentApp 实例测试它的唯一方法)我什至无法获得我的 ListingInformation(它似乎是 emply,甚至是 null - 不能说,因为我无法调试它)。

我有这个ini方法:

    private async void ini()
        {
#if DEBUG
            StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Data");
            StorageFile proxyFile = await proxyDataFolder.GetFileAsync("WindowsStoreProxy.xml");
            await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);

            listing = await CurrentAppSimulator.LoadListingInformationAsync();
#else
            listing = await CurrentApp.LoadListingInformationAsync();
#endif
        }

列表被声明为全球。 但是后来我调用了它,但没有任何显示(emply sb,emplty dialog)。

private async void btnListAllProducts_Click_1(object sender, RoutedEventArgs e)
    {
        StringBuilder sb = new StringBuilder();

        foreach (var product in listing.ProductListings)
        {
            sb.AppendLine(string.Format("{0}, {1}, {2}",
              product.Key,
              product.Value.Name,
              product.Value.FormattedPrice));
        }

        var messageDialog = new MessageDialog(sb.ToString());
        await messageDialog.ShowAsync();
    }

在 Silverlight 的一些旧教程中,我发现有一些 appmanifest 连接(复制一些 ID),但我找不到它,所以我跳过了这一步(也许是我 "bug" 的原因? ?).

无论如何,我几乎没有其他问题。当我在 CurrentAppSimulator 中测试时,它从未保存过,所以在我的应用程序重新启动后,我能够再次购买该项目。我必须在某处保存一些许可信息吗?

我的购买方法是这样的:

async private void btnBuySuperMap_Click_1(object sender, RoutedEventArgs e)
        {
            var newMapItem =
            listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "11111" && p.Value.ProductType == ProductType.Durable);

            string receipt;
            bool licInfo;
#if DEBUG
            licInfo = CurrentAppSimulator.LicenseInformation.ProductLicenses[newMapItem.Value.ProductId].IsActive;
#else
            licInfo = CurrentApp.LicenseInformation.ProductLicenses[newMapItem.Value.ProductId].IsActive;
#endif
            try
            {
                if (licInfo)
                {
                    var messageDialog = new MessageDialog("You already own this Map!");
                    await messageDialog.ShowAsync();
                }
                else
                {
#if DEBUG
                    receipt = await CurrentAppSimulator.RequestProductPurchaseAsync(newMapItem.Value.ProductId, true);
#else
                    receipt = await CurrentApp.RequestProductPurchaseAsync(newMapItem.Value.ProductId, true);
#endif
                    txtBoughtSW.Visibility = Visibility.Visible;
                    txtBoughtSW.Text = "You own the Super Map Now!";
                }
            }
            catch (Exception ex)
            {
                var messageDialog = new MessageDialog(ex.ToString());
                messageDialog.ShowAsync();
            }
        }

我想说的最后一件事,它首先是简单的测试外观。在这个工作之后,我当然会更好地实施它。 :)

提前感谢您的任何建议!

PS:有人知道这方面的一些好的教程吗?如果没有,我可能会为其他人创建自己的(在一些帮助下)。

编辑:此时它是 Windows(平板电脑)版本(WinRT,通用)。 WindowsPhone 接下来是实施(在成功实施之后)(可能共享 class??不知道)。

完成了。我在开发中心编辑了该 IaP 项目的一些信息,现在它正在运行。提示:如果您不填写所有(甚至是可选的)信息,如描述等,有时它不起作用,语言描述必须(可能)适用于您的应用程序支持的所有语言(即使 MS 也说它也是可选的)。