qaqa12345667 发表于 2015-5-22 12:27:20

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.Name,
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.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.IsActive 会返回true
  CurrentApp.ReportProductFulfillment 是告知 MSservice 完成购买。

  
  当然在判断支付成功后如果有需要的话还要和自己或product service同步。如果你没有开发者账号和应用 也可以自己搭建测试环境 请参考
  相信我说到这里大家已经对 windows phone 8 应用内购买 / 应用内支付 有了大概的了解,同时欢迎大家在这里和我沟通交流或者在新浪微博上 @王博_Nick
  
  
  
页: [1]
查看完整版本: Windows Phone 8 In app purchase 应用内购买 / 应用内支付