Windows商店应用内购接入

来源:互联网 发布:手机淘宝竟然被挤爆了 编辑:程序博客网 时间:2024/04/28 17:58

windows APP 和winPhone APP 接入,所用API是一样的,只是手动设置有所不同,

1、配置应用信息

可以将项目和应用商店关联,这样VS会自动下载所需信息;也可以手动设置(用别人账号╮(╯▽╰)╭)

winPhone设置Package.appxmanifest中:


Windows设置Package.appxmanifest中:


其中 Identity Name是包名称,也是发行商的名字;Publisher是发行商Id;PhoneProductId是appid;PhonePublisher同Publisher,这些都在开发者应用管理中可以查到。

2、请求购买

create_task(CurrentApp::RequestProductPurchaseAsync(product_id_rt)).then([=](task<PurchaseResults^> currentTask){try {auto result = currentTask.get();switch (result->Status){case ProductPurchaseStatus::NotFulfilled:
<span style="white-space:pre"></span>//未完成上次交易break;case ProductPurchaseStatus::NotPurchased:
break;case ProductPurchaseStatus::AlreadyPurchased:case ProductPurchaseStatus::Succeeded:{}break;}}catch (Platform::Exception^ exception) {}});}

用RequestProductPurchaseAsync请求购买,product_id_rt 是配置的IAP ID,当请求成功的时候会跳转到微软的支付,完成支付后result中Status为Success,这时将result中的收据ReceiptXml和交易idTransactionId发送给服务器,让无服务进行验证。

3、验证收据

.net服务器参考: https://msdn.microsoft.com/zh-cn/library/windows/apps/mt219692.aspx

其他服务器参考:http://www.scriptscoop.net/t/80d51c864ba8/verify-iap-receipt-from-windows-store-using-ruby.html

服务器验证成功后要告诉客户端验证成功,客户端收到信息后再想报告交易完成。

4、报告交易完成

在服务器确认购买成功后要想商店报告购买成功,否则这件商品不能再次购买。

create_task(CurrentApp::ReportConsumableFulfillmentAsync(ProductId, TransactionId)).then([product_id](task<FulfillmentResult> currentTask){auto fulfill_result = currentTask.get();switch (fulfill_result) {case FulfillmentResult::Succeeded:LOG(L"fulfillment succeeded!\r\n");break;default:LOG(L"fulfillment failed!\r\n");break;}});
5、检查未完成购买

有可能在交易完成时,断网导致支付验证未完成,所以在游戏启动时,应当验证是否有未完成订单,通过GetUnfulfilledConsumablesAsync请求信息,再通过GetProductReceiptAsync得到收据信息进行验证。

0 0
原创粉丝点击