2

当使用命名空间 Windows.services.Store 中的StoreContext.RequestPurchaseAsync()从WPF 桌面应用程序执行应用内购买时,我们会收到带有 ExtendedError 消息“值不在预期范围内”的 StorePurchaseResult。

我们的应用程序已发布并可从 Windows 应用商店下载。

它是使用 DesktopAppConverter 工具转换的。我们根据 Store 中的描述(Identity Name, Publisher...)设置 manifest.appx。

我们按照下面提供的说明从使用桌面桥的 Windows 桌面应用程序的 UI 线程中使用 C# 中的应用内购买。

https://docs.microsoft.com/en-us/windows/uwp/monetize/in-app-purchases-and-trials https://docs.microsoft.com/en-us/windows/uwp/monetize/enable -in-app-purchases-of-apps-and-add-ons

在我们应用程序的代码中,我们声明了 IInitializeWithWindow 接口:

[ComImport]
[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithWindow
{
  void Initialize(IntPtr hwnd);
}

然后,当我们的应用程序启动时,我们使用单用户方式获取 StoreContext(存储在 storeContext_ 属性中):

// Init the store context
storeContext_ = StoreContext.GetDefault();
IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)storeContext_;
initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);

在此之后,我们设法检索 StoreLicense(存储在 storeLicense_ 属性中)并列出关联的商店产品而没有任何错误

// Get the current user license
storeLicense_ = await storeContext_.GetAppLicenseAsync();
if (storeLicense_ == null)
{
    MessageBox.Show("An error occurred while retrieving the license.", "StoreLicenseApp Error");
    return;
}

// Create a filtered list of the product AddOns I care about
string[] filterList = new string[] { "Durable" };

// Get list of Add Ons this app can sell, filtering for the types we know about
StoreProductQueryResult addOns = await storeContext_.GetAssociatedStoreProductsAsync(filterList);
if (addOns.ExtendedError != null)
{
    MessageBox.Show("Impossible to retreive the list of the products on the store.\n" + addOns.ExtendedError.Message,
                               "Get Associated Store Products Error");
}
            

从商店中检索到产品的商店 ID 后,我们等待用户单击调用下面回调的购买按钮。

private async void PurchaseButton_Clicked(object sender, RoutedEventArgs e)
{
   StorePurchaseResult result = await storeContext_.RequestPurchaseAsync(selectedStoreId);
   
   // Capture the error message for the operation, if any.
   string extendedError = string.Empty;
   if (result.ExtendedError != null)
   {
                   extendedError = result.ExtendedError.Message;
   }
               
               [...]
}

RequestPurchaseAsync()返回错误,而不是显示购买产品的 Metro 界面。这是返回的扩展错误:

Message = "值不在预期范围内。"

HResult = -2147024809

有关如何解决此问题的任何线索?

4

2 回答 2

0

以下是使用 WSCOLLECT.exe 收集的应用内购买任务类别的错误日志:

1) 消息 Windows::Services::Store::StoreContext::RequestPurchaseAsync(9PMRHM0MJ85K) 被调用。(CV:+hcSKxR9+UGX7BQ/.1.3) 函数 Windows::Services::Store::StoreContext::RequestPurchaseAsync 错误代码 -1 源 \storecontext.cpp 行号 1194

2) 消息:ChkHr(hrGetTicket) 功能:Windows::Services::Store::PurchaseOperation::_PromptForPasswordAndEnterOrderWithRetry 错误代码:-2147024809 来源:\purchaseoperation.cpp 行号 506

3) 消息:ChkHr(_PromptForPasswordAndEnterOrderWithRetry(fPromptForCredentials)) 功能:Windows::Services::Store::PurchaseOperation::_ProceedToPurchase 错误代码:-2147024809 来源:\purchaseoperation.cpp 行号:630

4) 消息:ChkHr(_ProceedToPurchase(needsToSignIn)) 功能:Windows::Services::Store::PurchaseOperation::_Purchase 错误代码:-2147024809 来源:\purchaseoperation.cpp 行号:792

5) 消息 ChkHr(_hresultOfOperation) 函数 Windows::Services::Store::RequestPurchaseOperation::DoWork 错误代码 -2147024809 源 \requestpurchaseoperation.cpp 行号 115

于 2017-05-09T13:50:05.150 回答
0

RequestPurchaseAsync()我们函数中的调用PurchaseButton_Clicked()返回错误,因为我们在应用程序启动时正在另一个函数中初始化存储上下文。

我们通过将存储上下文初始化指令放置在以下内容中解决了这个问题PurchaseButton_Clicked()

public async void PurchaseSelectedProduct(ProductModel product){
    if (product == null){
        MessageBox.Show("Product not valid", "PurchaseInApp Error");
        return;
    }

    // Init store context for purchase
    IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)storeContext_;
    initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);

    // Buy through in app purchase sdk
    StorePurchaseResult result = null;
    try { result = await product.StoreProduct.RequestPurchaseAsync(); }
}
于 2017-09-28T08:55:38.827 回答