You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UWP订阅附加组件无法通过GetAssociatedStoreProductsAsync返回求助

问题排查与解决方案

我一眼就揪出问题所在啦!你当前代码里犯了个类型匹配的关键错误——订阅型附加组件并不属于"Durable"类型,所以用["Durable"]作为参数调用GetAssociatedStoreProductsAsync时,自然无法返回你的订阅产品。

核心原因

Windows 商店的附加组件分为三类核心类型:

  • Durable:永久型附加组件(比如一次性购买的解锁内容、专属道具)
  • Subscription:订阅型附加组件(就是你上架的这类按月/按年付费的订阅产品)
  • Consumable:消耗型附加组件(比如可重复购买的游戏货币、次数道具)

你的代码只请求了 Durable 类型的产品,完全没包含 Subscription 类型,订阅产品当然不会出现在查询结果里。

修改后的代码

把GetAssociatedStoreProductsAsync的参数改成包含"Subscription"的数组即可。如果需要同时获取 Durable 和订阅产品,就把两个类型都加上:

private async Task<StoreProduct> GetSubscriptionProductAsync() {
    // 同时请求Durable和Subscription类型的附加组件
    StoreProductQueryResult result = await context.GetAssociatedStoreProductsAsync(new string[] { "Durable", "Subscription" });
    if (result.ExtendedError != null) {
        System.Diagnostics.Debug.WriteLine("Something went wrong while getting the add-ons. " +
            "ExtendedError:" + result.ExtendedError);
        return null;
    }
    // 查找目标订阅产品
    foreach (var item in result.Products) {
        StoreProduct product = item.Value;
        if (product.StoreId == subscriptionStoreId) {
            return product;
        }
    }
    System.Diagnostics.Debug.WriteLine("The subscription was not found.");
    return null;
}

如果你只需要获取订阅产品,也可以直接传new string[] { "Subscription" }。

额外检查点

  1. 确认subscriptionStoreId完全匹配你在商店后台配置的订阅产品ID,不要有拼写或格式错误
  2. 如果修改后还是找不到,可以打印result.Products里的所有产品ID,排查是否是ID配置或商店同步延迟问题
  3. 确保测试环境是正式商店环境(你已经上架应用,无需再用未关联的测试沙箱)

内容的提问来源于stack exchange,提问作者Emil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 10:00:06