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[Prod.Value.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同步。如果你沒有開發者賬號和應用 也可以自己搭建測試環境 請參考 

相信我說到這里大家已經對 windows phone 8 應用內購買 / 應用內支付 有了大概的了解,同時歡迎大家在這里和我溝通交流或者在新浪微博上 @王博_Nick

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM