0

当使用StoreContext.RequestPurchaseAsync()从WPF桌面应用程序执行应用程序内购买时,Windows.services.Store命名空间带有扩展错误消息的StorePurchaseResult “值不在预期的范围内。”Windows应用商店购买问题“价值不符合预期范围”

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

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

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

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); 

在此之后,我们设法检索S toreLicense(存储到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是从商店retreived,我们等待用户点击购买按钮调用下面的回调。

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接口。 这里是扩展错误返回:

消息=“价值不在预期的范围内”。

的HResult = -2147024809

如何解决这个问题的任何线索?

+0

就根据此错误信息,我们不能查找原因为发生故障的请求。如果可能,你能否提供你提供的产品ID(对于父应用程序和IAP产品)? –

+0

嗨Mattew,这里是父应用程序一个9NFMR9KZRHTV和IAP是9PHL59JKBHNC – jarne

+0

您可以运行** WSCOLLECT **并提供商店日志吗? –

回答

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(); } 
} 
0

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

1)信息窗口::服务::商店:: StoreContext :: RequestPurchaseAsync(9PMRHM0MJ85K)调用。 (CV:+ hcSKxR9 + UGX7BQ/1.3) 功能的Windows ::服务::商店:: StoreContext :: RequestPurchaseAsync 错误代码-1 来源\ storecontext.cpp 行号1194

2)消息:ChkHr (hrGetTicket) 函数:Windows :: Services :: Store :: PurchaseOperation :: _ PromptForPasswordAndEnterOrderWithRetry 错误代码:-2147024809 来源:\ purchaseoperation。CPP 行号506

3)消息:ChkHr(_PromptForPasswordAndEnterOrderWithRetry(fPromptForCredentials)) 功能:视窗::服务::商店:: PurchaseOperation :: _ ProceedToPurchase 错误代码:-2147024809 来源:\ purchaseoperation.cpp 行号:630

4)消息:ChkHr(_ProceedToPurchase(needsToSignIn)) 功能:视窗::服务::商店:: PurchaseOperation :: _采购 错误代码:-2147024809 来源:\ purchaseoperation.cpp 线号码:792

5)信息ChkHr(_hresultOfOperation) 功能的Windows ::服务::商店:: RequestPurchaseOperation :: DoWork的 错误代码-2147024809 来源\ requestpurchaseoperation.cpp 行号115

+0

如何解决此问题的任何线索? – jarne

相关问题