Windows Phone 8 In app purchase 应用内购买、应用内支付
- 格式:doc
- 大小:693.50 KB
- 文档页数:9
Windows Phone 8 In app purchase 应用内购买/ 应用内支付
聊到应用内购买In app purchase 是目前来说应用最容易收益的一种做法,和7.5提供“试用“有异曲同工之处但WP8是做法更为友好贴近用户使用习惯,也为大家的应用带来更多赚钱的机会,因为In app purchase的商品分为(持久形- Durable)例如武游戏中的器装备和(消耗形- Consumable)游戏中的食品和金币并且支持简单的支持流程.
首先在我们的手机钱包中可以绑定支付宝Alipay 账户我们可以使用该账户进行应用购买和支付。
此文是升级到WP8必需知道的13个特性系列的一个更新希望这个系列可以给Windows Phone 8开发者带来一些开发上的便利。
同时欢迎大家在这里和我沟通交流或者在新浪微博上@王博_Nick
引用自MSDN 这里解释的非常清楚了所以我还是给出连接
按部就班我一个一个的来给大家介绍实现过程:
1. 商店提交应用我之前已经介绍过了参考
2. 提交你的应用内支付商品
visual studio 的设置
经过以上的操作在我们的应用中就可以拿到productID中的商品了当然是要审核通过的。
这里我们使用到了CurrentApp class 当然如果你没有通过审核也是可以使用CurrentAppSimulator class进行模拟的配置方法
这里常用的loadlistingInformationAsync() 来获取所有的商品
private async void btnListIAPProducts_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
try
{
var ProdList = await CurrentApp.LoadListingInformationAsync();
lbProductsList.Items.Clear();
string t = "";
foreach (var item in ProdList.ProductListings)
{
t = string.Format("{0}, {1}, {2},{3}, {4}",
item.Key,
,
item.Value.FormattedPrice,
item.Value.ProductType,
item.Value.Description);
lbProductsList.Items.Insert(0, t);
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
如图所示
既然可以拿到商品列表了怎么进行购买呢?其实代码也很简单还是CurrentApp private async void btnOrderProduct_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
var ProdList = await CurrentApp.LoadListingInformationAsync();
var Prod = ProdList.ProductListings.FirstOrDefault(p => p.Value.ProductType == ProductType.Consumable);
try
{
var Receipt = await CurrentApp.RequestProductPurchaseAsync(Prod.Value.ProductId, true);
if
(CurrentApp.LicenseInformation.ProductLicenses[Prod.V alue.ProductId].IsActive)
{
// do someting with this license...
// Notify the marketplace that the application has delivered the paid-for goods to the user.
CurrentApp.ReportProductFulfillment(Prod.Value.ProductId);
}
MessageBox.Show(Receipt, "Fatura", MessageBoxButton.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Fatura", MessageBoxButton.OK);
}
}
以上的代码也可以参考
CurrentApp.RequestProductPurchaseAsync 打开应用商店进入支付页面,支付成功后CurrentApp.LicenseInformation.ProductLicenses[Prod.Value.ProductId].IsActive 会返回true CurrentApp.ReportProductFulfillment 是告知MSservice 完成购买。
当然在判断支付成功后如果有需要的话还要和自己或product service同步。
如果你没有开发者账号和应用也可以自己搭建测试环境。