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

我目前的需要是可以允许用户捐赠赞助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. 我的第一个python web开发框架(14)——后台管理系统登录功能

    接下来正式进入网站的功能开发.要完成后台管理系统登录功能,通过查看登录页面,我们可以了解到,我们需要编写验证码图片获取接口和登录处理接口,然后在登录页面的HTML上编写AJAX. 在进行接口开发之前, ...

  2. JPA的一对多映射(双向)关联

    实体Customer:用户. 实体Order:订单. Customer和Order是一对多关系.那么在JPA中,如何表示一对多的双向关联呢? JPA使用@OneToMany和@ManyToOne来标识 ...

  3. Ionic3 下拉刷新

    参考: http://ionicframework.com/docs/api/components/refresher/Refresher/

  4. 推荐一款不错的反编译软件:Reflector

    只需要把要反编译的dll拖放到程序窗口就可以看到code了.是不是很简单,快来试试吧.不只是可以反编译个人写的code,.Net库一样可以查看代码.想学习.Net核心代码的可以试试看.

  5. HDU X mod f(x)(题解注释)

    X mod f(x) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. js 时间字符串转化为时间

    对于时间字符串格式为:"2017-03-03 12:23:55"; IE:显示无效的日期 new Date("2017-03-3 12:23:55") //[d ...

  7. react-native多图选择、图片裁剪(支持ad/ios图片个数控制)

    扯淡: 目前关于rn比较知名并且封装好的图片选择控件很多,不过能同时支持多图片上传,个数控制兼容iOS/Ad的却寥寥无几,而今天介绍的这款框架可以实现:图片裁剪.最大图片个数限制.拍照.本地相册等功能 ...

  8. 一:Spring Boot、Spring Cloud

    上次写了一篇文章叫Spring Cloud在国内中小型公司能用起来吗?介绍了Spring Cloud是否能在中小公司使用起来,这篇文章是它的姊妹篇.其实我们在这条路上已经走了一年多,从16年初到现在. ...

  9. Maven的pom.xml文件详解------Build Settings

    根据POM 4.0.0 XSD,build元素概念性的划分为两个部分:BaseBuild(包含poject build和profile build的公共部分,见下)和poject buil   < ...

  10. 《天书夜读:从汇编语言到windows内核编程》四 windows内核调试环境搭建

    1) 基础篇是讲理论的,先跳过去,看不到代码运行的效果要去记代码是一个痛苦的事情.这里先跳入探索篇.其实今天的确也很痛苦,这作者对驱动开发的编译与调试环境介绍得太模糊了,我是各种尝试,对这个环境的搭建 ...