Microsoft Store API:无法获取所有插件的许可证信息
private async Task<bool> CheckIfUserHasSubscriptionAsync()
{
StoreAppLicense appLicense = await storeContext.GetAppLicenseAsync();
// Check if the customer has the rights to the subscription.
foreach (var addOnLicense in appLicense.AddOnLicenses)
{
StoreLicense license = addOnLicense.Value;
if (license.SkuStoreId.StartsWith(subscriptionStoreId))
{
if (license.IsActive)
{
// The expiration date is available in the license.ExpirationDate property.
return true;
}
}
}
// The customer does not have a license to the subscription.
return false;
}
上面是 MSDN 文档中的小代码,用于读取插件许可证信息。 我购买了两个插件,一个是消耗型插件,另一个是订阅类型。 当我查询存储时,它仅返回订阅类型插件信息。 循环只进入一次。为什么? 是否有另一种方法来获取用户拥有的所有插件的列表? 或者我在这里做错了什么?
此致
于 2022 年 3 月 15 日更新
添加我作为用户拥有的插件的屏幕截图。
-
更新于 2022 年 3 月 24 日
嗨,Roy, 更新一下,我现在购买了 3 个插件。
1 个消费品类型和
2 个订阅类型,其中 1 个订阅有试用期。
我想再次注意这个循环 foreach(appLicense.AddOnLicenses 中的 var addOnLicense) 仅检索插件详细信息的订阅类型。 (这是错误吗?)
获得的信息如下,但没有详细信息,例如,
FreeSubscriptionWithTrailPeriod 是否处于试用期?
appLicense.ExtendedJsonData
{
"productAddOns":[
{
"devOfferId":"",
"inAppOfferToken":"FreeSubscriptionWithTrailPeriod",
"productId":"9-P-S-Z-Z-6K",
"productType":"Durable",
"skuId":"0020",
"skuType":"Full",
"expiration":"2022-04-03 00:00:00",
"isActive":true
},
{
"devOfferId":"",
"inAppOfferToken":"FreeChirpSubscriptionForTest",
"productId":"9_Q-X-1-K-X-",
"productType":"Durable",
"skuId":"0020",
"skuType":"Full",
"expiration":"2022-04-15 00:00:00",
"isActive":true
}
],
"productId":"9-T9-Z-6-7-Z",
"skuId":"0010",
"isActive":true,
"isTrial":false,
"isTrialOwnedByThisUser":false,
"isDiscLicense":false,
"expiration":"9999-12-31 00:00:00",
"trialTimeRemaining":"10675199.02:48:05.477581"
}
进一步,我尝试了您对 的建议GetUserCollectionAsync() 方法。 的输出。ExtendedJsonData
在这里,我得到以下来自(StoreProduct) 产品
所以问题深入到如何解释这些数据。查找详细信息,例如 是试用期吗? 试用期到期或订阅到期时?
我仅列出一些导入项目
"ProductId": "9-P-S-Z-Z-6K",
"Properties": {
"PackageFamilyName": null,
"InAppOfferToken": "FreeSubscriptionWithTrailPeriod"
},
"ProductKind": "Durable",
"DisplaySkuAvailabilities": [
{
"Sku": {
"LocalizedProperties": [
{
"SkuDescription": "Coding Games.",
"SkuTitle": "Players: Testing Free with Trial Period",
"SkuButtonTitle": "",
"SkuDisplayRank": [],
"LegalText": {
"Copyright": "",
"CopyrightUri": "",
"PrivacyPolicy": "",
"PrivacyPolicyUri": "https:....",
"Tou": "",
"TouUri": ""
},
"Language": "en"
}
],
"Properties": {
"CustomDeveloperData": "MaxPlayers=2\r\nMaxLevel=5",
"FulfillmentType": null,
"BundledSkus": null,
"IsRepurchasable": true,
"SkuDisplayRank": 0,
"IsTrial": false
},
"SkuId": "0020",
"RecurrencePolicy": null,
"CollectionData": {
"acquiredDate": "2022-03-24T11:38:55.3972654+00:00",
"autoRenew": true,
"additionalIds": [],
"devOfferId": "",
"effectiveBeneficiaries": [],
"endDate": "2022-04-03T00:00:00+00:00",
"externalReferences": [],
"fulfillmentData": [],
"inAppOfferToken": "FreeSubscriptionWithTrailPeriod",
"isCacheable": true,
"isTrial": true,
"itemId": "edb3c746efff41f0a85e126c67854f4d",
"localTicketReference": "0",
"modifiedDate": "2022-03-24T11:38:55.3985601+00:00",
"musicTracksInfo": [],
"orderId": "cc19857a-56f4-479d-8f42-c216375abd7d",
"orderLineItemId": "0c797e10-83d9-4ab2-a7b8-2fd2b1d502c1",
"ownershipType": "OwnedByBeneficiary",
"productFamily": "",
"productId": "9NP3S4Z1ZD6K",
"productKind": "Durable",
"productTitleId": "-129071",
"purchasedCountry": "IN",
"quantity": 1,
"recurrenceId": "mdr:310574664085794:aeac68161e404372931218beff5a10d1:cc19857a-56f4-479d-8f42-c216375abd7d",
"skuId": "0020",
"skuType": "Full",
"sharingSource": "None",
"startDate": "2022-03-24T00:00:00+00:00",
"status": "Active",
"tags": [],
"transactionId": "cc19857a-56f4-479d-8f42-c216375abd7d"
}
},
"Availabilities": [
{
"Actions": [
"License"
],
"AvailabilityId": "9-9-4-K-V-7D",
"Conditions": {
"EndDate": "9998-12-30T00:00:00.0000000Z"
},
"OrderManagementData": {
"Price": {
"CurrencyCode": "USD",
"ListPrice": 0,
"MSRP": 0
}
},
"DisplayRank": 0
}
]
}
还会出现一些问题,例如 DisplaySkuAvailities 是一个数组或集合,那么什么时候可以期待多个 sku?
问候
private async Task<bool> CheckIfUserHasSubscriptionAsync()
{
StoreAppLicense appLicense = await storeContext.GetAppLicenseAsync();
// Check if the customer has the rights to the subscription.
foreach (var addOnLicense in appLicense.AddOnLicenses)
{
StoreLicense license = addOnLicense.Value;
if (license.SkuStoreId.StartsWith(subscriptionStoreId))
{
if (license.IsActive)
{
// The expiration date is available in the license.ExpirationDate property.
return true;
}
}
}
// The customer does not have a license to the subscription.
return false;
}
Above is small code from MSDN Docs that would read Addon License Infomation.
I have purchased two addons, One of Consumable Type and another of Subscription Type.
When i query store it only returns Subscription Type addon information.
The loop goes in only once. why?
Is there another way to get list of all addons that a user owns ?
Or am I doing something wrong here ?
Regards
Updated on 15-3-2022
Adding screenshot of addons I as a user Owns.
-
Updated on 24-3-2022
Hi Roy,
To refresh, I now have 3 addons purchased.
1 of type Consumable and
2 of type subscription, out of which one subscription has trial period.
Once again I would like to bring to notice that loop
foreach (var addOnLicense in appLicense.AddOnLicenses)
only retrieves subscription type of addon details.
(Is this bug ?)
Information obtained is as below, but it has no details like,
is FreeSubscriptionWithTrailPeriod is in Trial Period ?
appLicense.ExtendedJsonData
{
"productAddOns":[
{
"devOfferId":"",
"inAppOfferToken":"FreeSubscriptionWithTrailPeriod",
"productId":"9-P-S-Z-Z-6K",
"productType":"Durable",
"skuId":"0020",
"skuType":"Full",
"expiration":"2022-04-03 00:00:00",
"isActive":true
},
{
"devOfferId":"",
"inAppOfferToken":"FreeChirpSubscriptionForTest",
"productId":"9_Q-X-1-K-X-",
"productType":"Durable",
"skuId":"0020",
"skuType":"Full",
"expiration":"2022-04-15 00:00:00",
"isActive":true
}
],
"productId":"9-T9-Z-6-7-Z",
"skuId":"0010",
"isActive":true,
"isTrial":false,
"isTrialOwnedByThisUser":false,
"isDiscLicense":false,
"expiration":"9999-12-31 00:00:00",
"trialTimeRemaining":"10675199.02:48:05.477581"
}
Going further I tried your suggestion on GetUserCollectionAsync() method. Here i get following output taken from
(StoreProduct) product.ExtendedJsonData
So the question drills down to how to interpret this data. to find details like
is it in trial period?
When Trial expires or when subscription expires ?
I am listing some of import items only
"ProductId": "9-P-S-Z-Z-6K",
"Properties": {
"PackageFamilyName": null,
"InAppOfferToken": "FreeSubscriptionWithTrailPeriod"
},
"ProductKind": "Durable",
"DisplaySkuAvailabilities": [
{
"Sku": {
"LocalizedProperties": [
{
"SkuDescription": "Coding Games.",
"SkuTitle": "Players: Testing Free with Trial Period",
"SkuButtonTitle": "",
"SkuDisplayRank": [],
"LegalText": {
"Copyright": "",
"CopyrightUri": "",
"PrivacyPolicy": "",
"PrivacyPolicyUri": "https:....",
"Tou": "",
"TouUri": ""
},
"Language": "en"
}
],
"Properties": {
"CustomDeveloperData": "MaxPlayers=2\r\nMaxLevel=5",
"FulfillmentType": null,
"BundledSkus": null,
"IsRepurchasable": true,
"SkuDisplayRank": 0,
"IsTrial": false
},
"SkuId": "0020",
"RecurrencePolicy": null,
"CollectionData": {
"acquiredDate": "2022-03-24T11:38:55.3972654+00:00",
"autoRenew": true,
"additionalIds": [],
"devOfferId": "",
"effectiveBeneficiaries": [],
"endDate": "2022-04-03T00:00:00+00:00",
"externalReferences": [],
"fulfillmentData": [],
"inAppOfferToken": "FreeSubscriptionWithTrailPeriod",
"isCacheable": true,
"isTrial": true,
"itemId": "edb3c746efff41f0a85e126c67854f4d",
"localTicketReference": "0",
"modifiedDate": "2022-03-24T11:38:55.3985601+00:00",
"musicTracksInfo": [],
"orderId": "cc19857a-56f4-479d-8f42-c216375abd7d",
"orderLineItemId": "0c797e10-83d9-4ab2-a7b8-2fd2b1d502c1",
"ownershipType": "OwnedByBeneficiary",
"productFamily": "",
"productId": "9NP3S4Z1ZD6K",
"productKind": "Durable",
"productTitleId": "-129071",
"purchasedCountry": "IN",
"quantity": 1,
"recurrenceId": "mdr:310574664085794:aeac68161e404372931218beff5a10d1:cc19857a-56f4-479d-8f42-c216375abd7d",
"skuId": "0020",
"skuType": "Full",
"sharingSource": "None",
"startDate": "2022-03-24T00:00:00+00:00",
"status": "Active",
"tags": [],
"transactionId": "cc19857a-56f4-479d-8f42-c216375abd7d"
}
},
"Availabilities": [
{
"Actions": [
"License"
],
"AvailabilityId": "9-9-4-K-V-7D",
"Conditions": {
"EndDate": "9998-12-30T00:00:00.0000000Z"
},
"OrderManagementData": {
"Price": {
"CurrencyCode": "USD",
"ListPrice": 0,
"MSRP": 0
}
},
"DisplayRank": 0
}
]
}
Few more questions arises like, DisplaySkuAvailabilities is an array or collection, so when to expect more then one sku ?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:
尝试一下:
有关详细信息,请检查:获取应用程序和附加组件的产品信息
旧:
有两种类型的消耗附加组件
开发人员管理的消耗品。对于这种类型的消耗品,您负责跟踪用户的附加组件所代表的物品的余额,并在用户消耗完所有物品后向商店报告附加组件的购买已完成。在您的应用报告之前的附加组件购买已完成之前,用户无法再次购买该附加组件。
商店管理的消耗品。对于这种类型的消耗品,商店会跟踪用户的附加组件所代表的物品的余额。当用户消费任何物品时,您有责任向商店报告这些物品已履行完毕,然后商店更新用户的余额。用户可以根据需要多次购买附加组件(他们不需要先消费这些物品)。您的应用可以随时向应用商店查询用户的当前余额。
如果您使用商店管理的消耗品,您可以使用 StoreContext.GetConsumableBalanceRemainingAsync() 方法。像这样:
Update:
Try this:
For more information, please check: Get product info for apps and add-ons
Old:
There are two types of consumable add-ons
Developer-managed consumable. For this type of consumable, you are responsible for keeping track of the user's balance of items that the add-on represents, and for reporting the purchase of the add-on as fulfilled to the Store after the user has consumed all of the items. The user cannot purchase the add-on again until your app has reported the previous add-on purchase as fulfilled.
Store-managed consumable. For this type of consumable, the Store keeps track of the user's balance of items that the add-on represents. When the user consumes any items, you are responsible for reporting those items as fulfilled to the Store, and the Store updates the user's balance. The user can purchase the add-on as many times as they want (they do not need to consume the items first). Your app can query the Store for the current balance for the user at any time.
If you are using Store-managed consumable, you could check the remaining balance for the consumable add-on using StoreContext.GetConsumableBalanceRemainingAsync() Method. Like this: