cocos2d-x2.2.4 wp8-xaml openxlive 支付接入问题总结

1 篇文章 0 订阅
0 篇文章 0 订阅

1、下载OpenXLive SDK 按照官网教程安装,在安装文件夹内可以找到OpenXlive个SDK教程。

2、直接将\OpenXLivePaymentSDK_WP_1.0.3.1_MSI\Payment\PaymentSLSample 内的Controls、Converter、Themes、文件夹以及内的文件

CustomerInfo.cs、ShopPage.xaml.cs、PurchasedPage.xaml.cs

3、再就是添加C# 与C++的互相调用类,可以参考http://www.cnblogs.com/zhxilin/archive/2013/03/20/2971331.html的方法。


附上 XLiveCallback.cs

namespace PhoneDirect3DXamlAppInterop
 {
       public sealed class XLiveCallback : ICallback
        {
           private MainPage m_mainPage = null;
           public void SetMainPage(MainPage page) 
           {
               m_mainPage = page;
           }
           public void payment(int price, int quantity, string goodId)
            {
                  m_mainPage.OnCreateShopPage();
            }
        }
 }

ICallback.h

namespace PhoneDirect3DXamlAppComponent
{
namespace OpenXLiveHelper
{
// A callback interface for C# code to implement.
public interface class ICallback
{
void payment(int price, int quantity, Platform::String^ goodId);
};
}
}


XLiveDelegate.h 文件

 #include "ICallback.h"


 namespace PhoneDirect3DXamlAppComponent


{
   namespace OpenXLiveHelper
    {
        // A native class to pass and store an ICallback instance, calling C# code via the ICallback object.
        [Windows::Foundation::Metadata::WebHostHidden]
        public ref class XLiveDelegate sealed   
         {
        public:
XLiveDelegate();
            // Gets the single XLiveDelegate instance.
            static XLiveDelegate^ GetInstance();
            // Set callback into the XLiveDelegate instance.
             void SetCallback(ICallback^ callback);
void SetCallback_buySucc(Platform::String^ goodId,int nCount);
Platform::String^ getChooseGoodsID();
           // Gets or sets the callback.
           property ICallback^ GlobalCallback;


  void pay(int price, int quantity, Platform::String^ goodId, int token);
        private:
           static XLiveDelegate^ m_Instance;
  int  m_Token;
  Platform::String^ m_goodId;
        };
  }
 }


//cpp

#include "pch.h"
#include "XLiveDelegate.h"
#include "GameStore.h"
#include "GameData.h"


namespace PhoneDirect3DXamlAppComponent
 {
     namespace OpenXLiveHelper
    {
       XLiveDelegate::XLiveDelegate()
       {
       }
         XLiveDelegate^ XLiveDelegate::GetInstance()
        {
           if (m_Instance == nullptr)
           {
                m_Instance = ref new XLiveDelegate();
           }
           return m_Instance;
        }
        void XLiveDelegate::SetCallback(ICallback^ callback)
       {
             GlobalCallback = callback;
       }
Platform::String^ XLiveDelegate::getChooseGoodsID()
{
return m_goodId;
}
void XLiveDelegate::SetCallback_buySucc(Platform::String^ goodId, int nCount)
{
GameStoreLayer* pStoreLayer = (GameStoreLayer*)GameData::getSharedGameData()->getDataPoint(DT_Shop);
if (pStoreLayer)
{
pStoreLayer->buySuccess(goodId,nCount);
}
}
       XLiveDelegate^ XLiveDelegate::m_Instance;


  void XLiveDelegate::pay(int price, int quantity, Platform::String^ goodId, int token)
  {
  if (GlobalCallback)
  {
  m_goodId = goodId;
  m_Token = token;
  GlobalCallback->payment(price, quantity, goodId);
  }

  }


  void XLiveDelegate::exitGame()
  {
  if (GlobalCallback)
  GlobalCallback->exitGame();
  }
  void XLiveDelegate::openUrl()
  {
  if (GlobalCallback)
  GlobalCallback->openUrl();
  }
   }
 }

//  MainPage.cs 下面添加一个调用ShopPage.xml 的逻辑

    public void OnCreateShopPage() 
        {
            if (XLivePayment.IsValid)
            {
                this.Dispatcher.BeginInvoke(() =>
                {
                    this.NavigationService.Navigate(new Uri("/ShopPage.xaml", UriKind.Relative));
                });
               
            }
        }

//此处是调用的充值返回数据;

 internal void UseAsset()
        {
            var assets = XLivePayment.CurrentService.Customer.Assets;
            foreach (var item in assets)
            {
                System.Diagnostics.Debug.WriteLine(item.ToString());
                // 根据需要调用Asset.Use方法使用该资产。
                switch (item.ProductInfo.Type)
                {
                    case ProductType.Durable:
                        // 耐用品会在资产列表中永久保存,应该直接给予用户,不需要调用Use方法。
                        break;
                    case ProductType.Consumable:
                    case ProductType.Once:
                        item.Use((s, e) =>
                            {
                                if (e.Result.ReturnValue)
                                {

//使用到游戏内。
                                    XLiveDelegate.GetInstance().SetCallback_buySucc(item.ProductInfo.ProductId, Convert.ToInt32(e.Result.Tag));
                        //            //只有在使用成功后,才应该将商品或道具给予用户。
                        //            //使用成功,玩家获得相应商品或道具。
                        //            //==========================================
                        //            //警告:必须将使用的数量算上,否则会导致玩家购买的商品与实际得到的不一致,e.Result.Tag保存了使用数量
                        //            //      此时玩家应该得到的商品为:item.ProductInfo 乘以 Convert.ToInt32(e.Result.Tag)
                                }
                            });
                        break;
                    default:
                        break;
                }
            }
        }
    }

// 在返回后台以后或者关闭第三方支付页面时,cocos2d-x2.2.4 wp8 会在reloadAllTexture 会崩溃,所以注释下面代码。可以解决。  

void Direct3DInterop::Disconnect()
{
    // m_renderer->Disconnect();  
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虾米神探

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值