Wal*_*jad 8 .net c# windows-rt win-universal-app windows-10
我想在我的Windows通用应用程序中集成应用程序内购买.我在编码前做了以下事情.
在Windows开发人员中心制作应用程序
加入产品在单边行动计划部分细节,并提交到商店,你可以在看图片
CurrentApp而不是CurrentAppSimulator在我的代码中,但它是异常的.private async void RenderStoreItems()
{
picItems.Clear();
try
{
//StoreManager mySM = new StoreManager();
ListingInformation li = await CurrentAppSimulator.LoadListingInformationAsync();
System.Diagnostics.Debug.WriteLine(li);
foreach (string key in li.ProductListings.Keys)
{
ProductListing pListing = li.ProductListings[key];
System.Diagnostics.Debug.WriteLine(key);
string status = CurrentAppSimulator.LicenseInformation.ProductLicenses[key].IsActive ? "Purchased" : pListing.FormattedPrice;
string imageLink = string.Empty;
picItems.Add(
new ProductItem
{
imgLink = key.Equals("BaazarMagzine101") ? "block-ads.png" : "block-ads.png",
Name = pListing.Name,
Status = status,
key = key,
BuyNowButtonVisible = CurrentAppSimulator.LicenseInformation.ProductLicenses[key].IsActive ? false : true
}
);
}
pics.ItemsSource = picItems;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}
private async void ButtonBuyNow_Clicked(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
string key = btn.Tag.ToString();
if (!CurrentAppSimulator.LicenseInformation.ProductLicenses[key].IsActive)
{
ListingInformation li = await CurrentAppSimulator.LoadListingInformationAsync();
string pID = li.ProductListings[key].ProductId;
string receipt = await CurrentAppSimulator.RequestProductPurchaseAsync(pID, true);
System.Diagnostics.Debug.WriteLine(receipt);
// RenderStoreItems();
}
}
Run Code Online (Sandbox Code Playgroud)
我也与商店员工在我的应用程序和我的应用程序包是一样的MS开发中心应用程序,你可以在看图片
当我运行我的应用程序并点击"购买"按钮时,我得到了这个对话框,你可以在Image中看到我没有从商店获得收据数据.
如果我做错了,请给我适当的指导,以实现应用内购买并测试我的笔记本电脑设备中的应用内购买.
我也遇到了这个问题,问题出在WindowsStoreProxy.xml文件上。
WindowsStoreProxy.xml默认情况下在IsTrial为 true,在该模式下,应用内购买似乎不起作用。当我将其更改为 false 时,它开始对我有用。
首先,我们在这里讨论在开发时模拟应用内购买(通过使用类CurrentAppSimulator)。在这种情况下,您需要一个WindowsStoreProxy.xml文件。它\xe2\x80\x99s描述在这里
现在您显示的窗口已由CurrentAppSimulator.RequestProductPurchaseAsync线条打开。它基本上控制 Windows 运行时本机方法的返回值(这对我来说很奇怪 \xe2\x80\xa6 我认为 \xe2\x80\x99s 不是 Microsoft\xe2\x80\xa6 故意的,应该在那里做其他事情),但如果你让它返回S_OK,基本上就是用户为应用内购买付款时的情况。
当它什么也没返回时,那么很有可能出现WindowsStoreProxy.xml错误。我建议您创建自己的并使用如下方法WindowsStoreProxy.xml阅读:CurrentAppSimulator.ReloadSimulatorAsync
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Testing\\WindowsStoreProxy.xml");\nawait CurrentAppSimulator.ReloadSimulatorAsync(file);\nRun Code Online (Sandbox Code Playgroud)对我来说,使用 \ndid 中的默认值C:\\Users\\<username>\\AppData\\Local\\Packages\\<app package folder>\\LocalState\\Microsoft\\Windows Store\\ApiData\\WindowsStoreProxy.xml不起作用,但一项更改已经解决了问题:我更改了这部分
<LicenseInformation>\n <App>\n <IsActive>true</IsActive>\n <IsTrial>true</IsTrial>\n </App>\n</LicenseInformation>\nRun Code Online (Sandbox Code Playgroud)\n\n对此:
\n\n<LicenseInformation>\n <App>\n <IsActive>true</IsActive>\n <IsTrial>false</IsTrial>\n </App>\n</LicenseInformation>\nRun Code Online (Sandbox Code Playgroud)\n\n(所以IsTrial设置为 false...)
现在,我还想提一下,这有点奇怪,因为默认情况下WindowsStoreProxy.xml没有为我的应用内购买定义产品。所以对于我的 \xe2\x80\x9cRemoveAds\xe2\x80\x9d 来说,正确的WindowsStoreProxy.xml应该是这样的:
<?xml version="1.0" encoding="utf-16" ?>\n<CurrentApp>\n <ListingInformation>\n <App>\n <AppId>00000000-0000-0000-0000-000000000000</AppId>\n <LinkUri>http://apps.microsoft.com/webpdp/app/00000000-0000-0000-0000-000000000000</LinkUri>\n <CurrentMarket>en-US</CurrentMarket>\n <AgeRating>3</AgeRating>\n <MarketData xml:lang="en-US">\n <Name>AppName</Name>\n <Description>AppDescription</Description>\n <Price>1.00</Price>\n <CurrencySymbol>$</CurrencySymbol>\n <CurrencyCode>USD</CurrencyCode>\n </MarketData>\n </App>\n <Product ProductId="RemoveAds" LicenseDuration="1" ProductType="Durable">\n <MarketData xml:lang="en-US">\n <Name>RemoveAds</Name>\n <Price>1.00</Price>\n <CurrencySymbol>$</CurrencySymbol>\n <CurrencyCode>USD</CurrencyCode>\n </MarketData>\n </Product> \n </ListingInformation>\n <LicenseInformation>\n <App>\n <IsActive>true</IsActive>\n <IsTrial>false</IsTrial>\n </App>\n <Product ProductId="1">\n <IsActive>true</IsActive>\n </Product>\n </LicenseInformation>\n <ConsumableInformation>\n <Product ProductId="RemoveAds" TransactionId="10000000-0000-0000-0000-000000000000" Status="Active" />\n </ConsumableInformation>\n</CurrentApp>\nRun Code Online (Sandbox Code Playgroud)我想指出的另一件事是,CurrentAppSimulator.RequestProductPurchaseAsync带有两个参数已经过时了。保留 true 参数,您将得到 PurchaseResults实例作为结果,其中包含属性中的收据ReceiptXML。