微软支付接入

项目需要接入微软支付,折腾了两天终于搞好了,记录下接入流程:

1.发起支付;

2.支付成功通知后台验证发货;

3.发货成功,客户端上报微软该订单已完成;

4.启动时,检测是否有未完成订单,若存在则进行第二步;

发起支付:

void TKWinrtSdk::buyProduct(Platform::String^ productId, Platform::String^ orderId)
{
	auto panel = cocos2d::GLViewImpl::sharedOpenGLView()->getPanel();
	auto dispatcher = cocos2d::GLViewImpl::sharedOpenGLView()->getDispatcher();
	if (dispatcher && panel)
	{
		// run on main UI thread
		dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this, panel, productId, orderId]()
		{
			try
			{
				auto licenseInformation = CurrentApp::LicenseInformation;
				if (!licenseInformation->ProductLicenses->Lookup(productId)->IsActive)
				{
					ProductPurchaseDisplayProperties^ prop;
					create_task(CurrentApp::RequestProductPurchaseAsync(productId, orderId, prop)).then([this, productId, orderId](PurchaseResults^	result)
					{
						try
						{
							switch (result->Status)
							{
							case ProductPurchaseStatus::AlreadyPurchased:
								break;
							case ProductPurchaseStatus::NotPurchased:
								break;
							case ProductPurchaseStatus::Succeeded:
							case ProductPurchaseStatus::NotFulfilled:
								//CurrentApp::ReportProductFulfillment(productId);
								TKSdkUwp::getInstance()->tellServerForUwp(PlatformStrToStdStr(orderId), PlatformStrToStdStr(result->ReceiptXml),"");
								break;
							}
						}
						catch (Platform::Exception^ exception)
						{

						}
					});
				}
				else {
					this->checkNotCompleteOrders();
				}
			}
			catch (Platform::Exception^ exception)
			{

			}
		}));
	}
}

上报微软订单完成

void TKWinrtSdk::respondBuyProductSuc(Platform::String^ productId)
{
	auto panel = cocos2d::GLViewImpl::sharedOpenGLView()->getPanel();
	auto dispatcher = cocos2d::GLViewImpl::sharedOpenGLView()->getDispatcher();
	if (dispatcher && panel)
	{
		// run on main UI thread
		dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this, panel, productId]()
		{
			try {
				CurrentApp::ReportProductFulfillment(productId);
			}
			catch (Platform::Exception^ exception)
			{

			}
		}));
	}
}

检测未完成订单

void TKWinrtSdk::checkNotCompleteOrders()
{
	auto panel = cocos2d::GLViewImpl::sharedOpenGLView()->getPanel();
	auto dispatcher = cocos2d::GLViewImpl::sharedOpenGLView()->getDispatcher();
	if (dispatcher && panel)
	{
		// run on main UI thread
		dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new DispatchedHandler([this, panel]()
		{
			try{
				auto products = Concurrency::create_task(Windows::ApplicationModel::Store::CurrentApp::GetUnfulfilledConsumablesAsync());
				products.then([=](Windows::Foundation::Collections::IVectorView<Windows::ApplicationModel::Store::UnfulfilledConsumable^>^ Result) {
					for (int i = 0; i < Result->Size; ++i) {
						auto productID = Result->GetAt(i)->ProductId;
						auto offerId = Result->GetAt(i)->OfferId;
						auto requsetReceipt = Concurrency::create_task(Windows::ApplicationModel::Store::CurrentApp::GetProductReceiptAsync(productID));
						requsetReceipt.then([=](Platform::String^ ReceiptXml) {
							TKSdkUwp::getInstance()->tellServerForUwp(PlatformStrToStdStr(offerId), PlatformStrToStdStr(ReceiptXml), PlatformStrToStdStr(productID));
						});
					}
				});
			}
			catch (Exception^ e)
			{

			}
		}));
	}
}

注意调用checkNotCompleteOrders时需要保证微软商店登录了账户,否则会崩溃!!

字符串转换:

std::string PlatformStrToStdStr(Platform::String^ ms)
{
	std::wstring w_str(ms->Begin());
	return std::string(w_str.begin(), w_str.end());
}


std::wstring stows(std::string s)
{
	std::wstring ws;
	ws.assign(s.begin(), s.end());
	return ws;
}

Platform::String^ stops(std::string s)
{
	return ref new Platform::String(stows(s).c_str());
}

支付测试需要应用先传微软后台,审核成功后方能正常测试!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
接口特点: 1.同时提供银行卡在线支付、声讯电话支付、互联星空支付、手机短信注册、腾讯财付通、 腾讯Q币、神州行充值卡、盛大游戏点卡、支付宝、手机银行、北京宽带支付、联通充值卡 等支付途径。 2.银行卡在线支付支持国内60 余种银行卡(信用卡、储蓄卡、借记卡等)在线支付。 3.全国声讯电话支付支持全国所有省份固定电话、小灵通、中国移动、中国联通手机, 开通移动、联通、电信、网通多个声讯热线号码。 4.中国电信互联星空支付支持直接用163或ADSL上网帐号、各省互联星空网站注册用户支付。 5.支持中国移动、中国联通、中国电信小灵通手机用户发送短信点播赠送服务。 6.开放腾讯公司Q币和财付通支付接口。 7.支持50元、100元、300元、500元等多种面值的移动神州行和联通充值卡支付。 8.各支付途径可任意选择开启或关闭。 9.真正傻瓜式支付接口,提供示例程序,只需简单设置即可使用。 10.设置商户密钥,支付信息加密传递,加强支付安全性,加密系统与其他支付平台兼容。 11.贺喜支付平台(http://www.168reg.cn)提供完善的后台管理系统,提供定单管理、定单 统计、财务管理、用户资料修改、商户密钥设置、推荐用户及技术支持等功能。 12.提交支付信息时可设置服务名称、商户订单号和两个自定义字段,支付成功后实时将支 付结果返回商户网站。 13.提供接口的测试模式,方便商户快捷地开发支付接口程序。 14.您可以登录后台管理系统查看定单以下信息:定单号、用户支付金额、商户所得金额、 自定义订单号、支付日期、结帐信息等。 15.提供定单后台通知系统,彻底解决用户端返回造成的挂单、掉单现象。 16.提供宣传推广代码,推荐其他商户加盟可获得其收入的一定比例分成。 17.开放收费制商户,为商户降低支付成本。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值