嗨,我正在开发UWP Microsfot Store App; 我需要在加载项中检查并计算用户购买的次数。
示例我在附件中购买了6(4xgold + 2xsilver)产品 我用了它,但只得到了2种产品(金银)
string[] productKinds = { "Consumable", "UnmanagedConsumable" };
var license = await _storeContext.GetUserCollectionAsync(productKinds);
我尝试了这段代码,但返回null
appLicense = await context.GetAppLicenseAsync();
*.appLicese.AddOnLicenses
如何获取所有用户的购买记录?
编辑:最低目标为内部版本10240
答案 0 :(得分:0)
答案:
private async void CheckBanner()
{
try
{
string[] productKinds = { "Consumable", "UnmanagedConsumable" };
StatusBar.Visibility = Visibility.Visible;
var userPurchases = await _storeContext.GetUserCollectionAsync(productKinds);
StatusBar.Visibility = Visibility.Collapsed;
foreach (var item in userPurchases.Products)
{
var product = item.Value;
TextBlock count = GetProductQuatity(product.ExtendedJsonData)
}
}
catch
{
//
}
}
private string GetProductQuatity(string jsonData)
{
try
{
var obj = JObject.Parse(jsonData);
return obj["DisplaySkuAvailabilities"][0]["Sku"]["CollectionData"]["quantity"].ToString();
}
catch
{
return "1";
}
}