今天来说一下应用程序内购的问题,这里面有坑,给自己做个笔记,也给需要的人提个醒。

我目前的需要是可以允许用户捐赠赞助App的形式内购,最终效果如下

只讲上面的列表部分,下面的就是图片布局啥的,没意思了

应用程序内购,在商店后台叫做“加载项”,你需要按照流程一步一步创建新的加载项即可。。。产品类型我选择的是耐用性(Durable),你也可以选择其他,具体看官方解释

创建好之后,需要提交应用商店审核。

注意!!!坑爹的地方来了

这面即使商店认证通过,你的App也获取不到你创建的加载项!!!【没错,微软经常把你们当爹的,坑的就是你们】

 解决办法:

App不是也有一个提交么,要提交一次App更新,并且认证通过,这样才能算是真正的审核通过!!!

=========================华丽丽的分割线=========================

下面开始撸xaml代码了

       <ListView Grid.Row="" x:Name="listProducts" IsItemClickEnabled="True" SelectionMode="Single" ItemClick="listProducts_ItemClick">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid BorderBrush="White" BorderThickness="0,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width=""/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Image Stretch="UniformToFill" Source="{Binding ProductImage}"/>
<Grid Grid.Column="">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="8*"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Title}" VerticalAlignment="Center"/>
<TextBlock Grid.Column="" FontWeight="Bold" Foreground="Green" Text="{Binding Price}" HorizontalAlignment="Right" VerticalAlignment="Center"/>
</Grid>
<TextBlock Grid.Row="" TextWrapping="WrapWholeWords" Text="{Binding Description}" VerticalAlignment="Center"/>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

用这个列表来装新建的加载项

然后在用户点击“赞助”按钮的时候相应一个事件,来向应用商店发送请求,下载你的加载项内容。

    StoreContext context = null;
    public async Task GetAddOnInfo()
{
if (context == null)
{
context = StoreContext.GetDefault();
// If your app is a desktop app that uses the Desktop Bridge, you
// may need additional code to configure the StoreContext object.
// For more info, see https://aka.ms/storecontext-for-desktop.
} // Specify the kinds of add-ons to retrieve.
string[] productKinds = { "Durable" };
List<String> filterList = new List<string>(productKinds); StoreProductQueryResult queryResult = await context.GetAssociatedStoreProductsAsync(productKinds); if (queryResult.ExtendedError != null)
{
// The user may be offline or there might be some other server failure.
return;
} //后面有代码接着
}

蓝后定义一个Product类

public class Product
{
public string StoreId { get; set; } public string Title { get; set; } public string Description { get; set; } public string Price { get; set; } public string ProductImage { get; set; } }

接上面的代码,根据返回的结果,循环添加在列表的 ItemsSource即可。

      foreach (KeyValuePair<string, StoreProduct> item in queryResult.Products)
{
// Access the Store product info for the add-on.
StoreProduct product = item.Value; // Use members of the product object to access listing info for the add-on...
Product pd = new Product()
{
StoreId = product.StoreId,
Title = product.Title,
Price = product.Price.FormattedPrice,
Description = product.Description,
ProductImage = product.Images[].Uri.OriginalString
}; lProducts.Add(pd);
} listProducts.ItemsSource = lProducts;

这样也就完成了加载项的列表显示。

=========================华丽丽的分割线=========================

但是你光显示也不行啊,我要点击,内购哇!!!

所以接着撸代码

private async void listProducts_ItemClick(object sender, ItemClickEventArgs e)
{
StoreContext context = StoreContext.GetDefault();
var product = e.ClickedItem as Product;
var result = await context.RequestPurchaseAsync(product.StoreId);
if (result.Status == StorePurchaseStatus.Succeeded)
{
// 成功购买
textPurchaseResult.Text = "Thank you.";
}
else if (result.Status == StorePurchaseStatus.AlreadyPurchased)
{
// 已经购买过了
textPurchaseResult.Text = "You have already purchased.";
}
else if (result.Status == StorePurchaseStatus.NotPurchased)
{
// 用户没购买,即用户中途取消了操作
textPurchaseResult.Text = "You have canceled the purchase.";
}
else if (result.Status == StorePurchaseStatus.ServerError || result.Status == StorePurchaseStatus.NetworkError)
{
// 发生错误
textPurchaseResult.Text = "Sorry, something went wrong with the microsoft server or something else.";
}
}

OK!!!碎觉!!!

UWP 应用程序内购的更多相关文章

  1. [Swift通天遁地]四、网络和线程-(15)程序内购功能

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. IAP 程序内购

    最近用到IAP内置购买,阅读官方文档,在网上找了些资料,在这里作下整理,以便日后查找和修改,主要流程方向确定,文档和相关转载内容截图不一一指出,google一堆. 1.查找官方文档,两张目录截图,对主 ...

  3. UWP: 体验应用内购新接口——StoreContext类

    Windows 1607 版本(内部版本 14393)之后,微软在 SDK 添加了一些与应用商店相关的新接口,像应用试用与购买.应用内购等.这些接口相对于原来的接口要方便很多.就拿应用内购来说,以前的 ...

  4. AppStore ipa (苹果内购)笔记

    内购示意图 准备条件 苹果的开发者证书,已经为应用启用App内购,并在Xcode更新配置文件 itunes store设置 itunes中创建App及其它设置 参考:iOS应用程序内购/内付费(一)  ...

  5. iOS开发系列--通讯录、蓝牙、内购、GameCenter、iCloud、Passbook系统服务开发汇总

    --系统应用与系统服务 iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用 ...

  6. iOS--通讯录、蓝牙、内购、GameCenter、iCloud、Passbook等系统服务开发汇总

    iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用系统应用.使用系统服务: ...

  7. 瘟疫公司中国版(Android)手动破解内购

    前言 洒家近日下载了个瘟疫公司中国版(安卓版)(com.easymobi.plagueinc.mi ,版本 1.1.2(5)(.mi 小米版)),发现游戏需要内购而且价格不菲. 需求 root权限 文 ...

  8. [IPA]IOS In App Purchase(内购)验证

    参考我之前的笔记 苹果内购笔记,在客户端向苹果购买成功之后,我们需要进行二次验证. 二次验证 IOS在沙箱环境下购买成功之后,向苹果进行二次验证,确认用户是否购买成功. 当应用向Apple服务器请求购 ...

  9. ios内购

    1.添加框架,storeKit.framework 需要真机调试 /* 内购五步: 1.请求可销售商品的列表 2.展示课销售的商品 3.点击购买 4.开具小票 5.创建交易对象并添加到交易队列 6.创 ...

随机推荐

  1. iOS之 NSTimer(二)

    1. Stopping a Timer  关闭定时器 if you create a non-repeating timer, there is no need to take any further ...

  2. 二、Tomcat配置以及IDEA运行第一个Jsp项目——JavaWeb点滴

    一.Tomcat配置环境变量 tomcat从官网下载最新的即可,本人下载的是安装版本.在安装过程中需要设置用户名和密码以及选择相应的JDK的安装目录.这些都比较简单直接下一步即可,安装完成之后就是配置 ...

  3. grunt-contrib-connect自动刷新html页面

    grunt-contrib-connect可以在我们开发的时候自动刷新页面,省去了手动刷新的时间. 下面说一下如何配置grunt-contrib-connect 1.下载插件包 npm install ...

  4. bootstrap折叠调用collapse()后data-parent不生效问题

    今天做的项目,用到了bootstrap的折叠功能,这个功能需要只展开一个折叠框,点击一个就会自动隐藏另一个,初始按照API做了一下,发现一切运行正常,但是测试的同事提了一个bug,说切换到其他模块后再 ...

  5. input框内的单引号,双引号转译

    主要是在后台传前端之前先把变量值替换单引号双引号成转译付. $bianlian是要替换的变量 两种方法 1.php后台输出值先转译 //双引号替换成转译符 $bianlian=preg_replace ...

  6. Lua 5.3 协程简单示例

    Lua 5.3 协程简单示例 来源 http://blog.csdn.net/vermilliontear/article/details/50547852 生产者->过滤器->消费者 模 ...

  7. zabbix 2.2.20 安装详解(Centos6.9)

    环境说明 [root@centos ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@centos ~]# uname -a L ...

  8. zookeeper分布式搭建

    1下载并解压zookeeper安装包 2进入zookeeper配置文件目录,找到zoo_sample.cfg,执行cp zoo_sample.cfg  zoo.cfg 3打开zoo.cfg文件,修改d ...

  9. this 和 new 构造函数

    function people(name) {     这样定义是在全局命名空间(global namespace)    name: name,    sayname: function() {   ...

  10. Java笔试题解答

    1. 下面哪些是Thread类的方法() A start()       B run()       C exit()       D getPriority() 答案:ABD 解析:看Java AP ...