【发布时间】:2017-10-01 10:28:59
【问题描述】:
当使用命名空间 Windows.services.Store 中的 StoreContext.RequestPurchaseAsync() 从 WPF 桌面应用程序执行应用内购买时,我们会收到带有 ExtendedError 消息 "Value 的 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
关于如何解决这个问题的任何线索?
【问题讨论】:
-
仅根据此错误信息,我们无法查找您请求失败的原因。如果可能,您能否提供您提供的产品 ID(用于父应用和 IAP 产品)?
-
嗨 Mattew,这里是父应用 9NFMR9KZRHTV,IAP 是 9PHL59JKBHNC
-
能否请您运行 WSCOLLECT 并在此处提供存储日志?
-
它是否为您提供了足够的信息?
-
@ZhendongWu-MSFT 我也面临这个问题 - 我想知道是否有任何解决方案。我们的应用 ID 是 9PGBZ1L0KRS8,我们尝试了两个开发管理的消耗品,ID 分别为 9N0S0GZNCX53 和 9N3SJVF4HM66。这是 WSCOLLECT 收集的错误的粘贴:pastebin.com/RYLjsS37
标签: c# windows-store-apps in-app-purchase desktop-application desktop-app-converter