首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何确定Windows应用程序的附加订阅是在试用期还是在付费期

如何确定Windows应用程序的附加订阅是在试用期还是在付费期
EN

Stack Overflow用户
提问于 2019-02-23 01:34:51
回答 2查看 339关注 0票数 0

我正在使用Windows.Services.Store API在Windows中发布的桌面桥应用程序中添加附加订阅。

我创建了一个为期3个月的测试附加订阅,为期1周的试用期。我可以通过从我的应用程序调用StoreAppLicence方法获得一个StoreContext.GetAppLicenseAsync实例,然后从它的AddOnLicenses属性中找到一个StoreLicense实例,该实例的SkuStoreId在开始时与测试添加的StoreId匹配。但是不知道这个订阅是在试用期还是在付费(完整)阶段,因为它没有像IsTrial那样的StoreAppLicence属性。

因此,我想知道如何确定订阅是在试用期还是在付费期,以便向我的用户展示我的应用程序中的归属状态。

更新

我不太清楚,但我询问的情况后,目前的用户已经“购买”附加订阅作为免费试用。我想知道如何确定试用期是否尚未完成,还是试用期已过,订阅已转至已支付(完整)期。

也许我可以通过将用户在本地“购买”订阅的数据存储起来,并将其与当前日期进行比较,但这似乎并不理想,因为这可能与Windows服务器管理的数据不一致。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-17 04:34:53

也许我找到了解决办法。

IsTrial方法得到的StoreCollectionDataStoreCollectionData性质提供了我所需要的信息。此外,StoreCollectionData还包括AcquiredDate属性,该属性指示订阅添加的购买日期,对于计算过期日期非常有用。根据我的经验,用ExpirationDate方法获得的StoreLicense的StoreLicense性质似乎不准确(比实际过期日期晚3天)。

示例代码如下所示。

代码语言:javascript
运行
复制
public enum LicenseStatus
{
    Unknown = 0,
    Trial,
    Full
}

private static StoreContext _context;

public static async Task<(string storeId, LicenseStatus status, DateTimeOffset acquiredDate)[]> GetSubscriptionAddonStatusesAsync()
{
    if (_context is null)
        _context = StoreContext.GetDefault();

    StoreProductQueryResult queryResult = await _context.GetUserCollectionAsync(new[] { "Durable" });
    if (queryResult.ExtendedError != null)
        throw queryResult.ExtendedError;

    IEnumerable<(string, LicenseStatus, DateTimeOffset)> Enumerate()
    {
        foreach (KeyValuePair<string, StoreProduct> pair in queryResult.Products)
        {
            StoreSku sku = pair.Value.Skus.FirstOrDefault();
            StoreCollectionData data = sku?.CollectionData;
            if (data != null)
            {
                LicenseStatus status = data.IsTrial ? LicenseStatus.Trial : LicenseStatus.Full;
                yield return (pair.Key, status, data.AcquiredDate);
            }
        }
    }

    return Enumerate().ToArray();
}

另一方面,在StoreContext.GetUserCollectionAsync方法中仍然存在一种奇怪的东西。它只提供最新的附加信息,而从它的解释,它应该提供所有附加的信息。因此,如果要检查多个附加项,此方法将是不够的.

票数 1
EN

Stack Overflow用户

发布于 2019-02-25 02:57:44

C#示例:

代码语言:javascript
运行
复制
subscriptionStoreProduct = await GetSubscriptionProductAsync();
if (subscriptionStoreProduct == null)
{
    return;
}
// Check if the first SKU is a trial and notify the customer that a trial is available.
// If a trial is available, the Skus array will always have 2 purchasable SKUs and the
// first one is the trial. Otherwise, this array will only have one SKU.
StoreSku sku = subscriptionStoreProduct.Skus[0];
if (sku.SubscriptionInfo.HasTrialPeriod)
{
    // You can display the subscription trial info to the customer here. You can use 
    // sku.SubscriptionInfo.TrialPeriod and sku.SubscriptionInfo.TrialPeriodUnit 
    // to get the trial details.
}
else
{
    // You can display the subscription purchase info to the customer here. You can use 
    // sku.SubscriptionInfo.BillingPeriod and sku.SubscriptionInfo.BillingPeriodUnit
    // to provide the renewal details.
}

从示例购买订阅附加项和类StoreSku类派生

更新

如果用户可以使用订阅,则只有两种可能,一种是试用期,另一种是他们已经购买的。代码中的方法(GetSubscriptionProductAsync)获取用户可以使用的订阅,您可以在示例(购买一个挂号附加程序。)中看到详细信息。属性HasTrialPeriod获得一个值,该值指示订阅是否包含试用期。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54837363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档