JaS*_*Hin 5 .net c# uwp desktop-bridge
在我通过 Desktop Bridge 打包的 WPF 应用程序中,我发现了一个问题,即某些用户无法通过应用内购买购买插件。它显示我的“已取消”警报,该警报代表的StorePurchaseStatus.NotPurchased位置。result.ExtendedErrornull
目标框架是:
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
Run Code Online (Sandbox Code Playgroud)
以下是促成购买的简化代码:
namespace MyApp {
public partial class MainWindow: Window {
private readonly StoreContext context;
public MainWindow(){
context = StoreContext.GetDefault();
}
private bool IsAdministrator()
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
private async void BuyButtonClick(object sender, RoutedEventArgs e) {
if (IsAdministrator())
{
ShowAlert("Cannot run under administrator rights");
return;
}
if (sender is Button button)
{
StoreProduct? storeProduct = ((Product)dataContext).storeProduct;
if (storeProduct != null)
{
Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new ThreadStart(async delegate
{
var hwnd = new WindowInteropHelper(this).Handle;
WinRT.Interop.InitializeWithWindow.Initialize(context, hwnd);
var result = await context.RequestPurchaseAsync(storeProduct.StoreId);
switch (result.Status)
{
case StorePurchaseStatus.Succeeded:
ShowAlert("Succeeded");
break;
case StorePurchaseStatus.AlreadyPurchased:
ShowAlert("AlreadyPurchased");
break;
case StorePurchaseStatus.NotPurchased:
var extendedError = result.ExtendedError;
if (extendedError != null)
{
ShowAlert(extendedError.Message);
}
else
{
ShowAlert("Canceled");
}
break;
case StorePurchaseStatus.NetworkError:
ShowAlert("NetworkError");
break;
case StorePurchaseStatus.ServerError:
ShowAlert("ServerError");
break;
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
它可以在我的设备(Windows 11 和 Windows 10)上的任何地方运行。无法购买的用户拥有Windows 11。
这可能是由客户使用的帐户类型引起的。
\n首先,如果应用程序以管理员身份运行,商店购买将会失败。
\n普通 \xe2\x80\x9cadmin\xe2\x80\x9d 帐户(具有拆分令牌的管理员组中的人员)只会以标准用户身份运行您的桌面桥接应用程序,除非他们右键单击并显式启动提升的内容。
\n但如果客户在其设备上使用系统内置帐户,则购买将会失败,因为应用程序将以管理员身份运行。Microsoft Store 购买 API 不允许这样做。
\n