主题
Skip to content 
核心模块位于 ZMYSDKManager 中
WARNING
💡 含有非消耗型内购的项目,需要在设置面加上恢复购买
按钮
支付模块的一些概念
- 商品按照类型分为:消耗性道具、非消耗性道具、订阅类型道具
c#
/// 非消耗性道具
NoConsumable = 0,
/// 消耗性道具
Consumable = 1,
/// 订阅类型道具
subscription = 2,
- 从商品获得的来源可以分为:
c#
/// 商品获取渠道
public enum CommdityChannel
{
/// 购买渠道
Buy = 0,
/// 复送渠道
FixOrders,
/// 失败订单渠道
FailedOrders,
/// 恢复购买渠道
RestoreOrders,
}
内购使用前的必须步骤
内购模块在使用前,需要先初始化内购模块;
c#
ZMYSDKManager.I.InitIap
SDK 需要得知目前游戏的商品信息,以 List<ProductData>数据结构传递给 SDK:
c#
/// 金币-消耗型商品
private const string globKey = "com.test.test.test.pigbank";
/// vip--非消耗型商品
private const string vipKey = "com.test.test.test.noad";
/// 月卡--订阅型商品
private const string monthlyCardKey= "test.tset";
//使用内购前,要先初始化
ZMYSDKManager.I.InitIap(new List<ProductData>()
{
new ProductData(){productID = globKey,productType = ProductType.Consumable},//金币
new ProductData(){productID = vipKey,productType = ProductType.NoConsumable},//vip
new ProductData(){productID = monthlyCardKey,productType = ProductType.subscription},//月卡
});
WARNING
💡 内购中涉及到的 productID,都应该在初始化时告知 SDK
初始化完成,即可开始内购功能使用
常用功能
购买
c#
/// 请求购买商品
/// <param name="productID">商品ID</param>
/// <param name="ext">预留扩展信息</param>
/// <param name="testIsSucceed">编辑器下是否购买成功</param>
ZMYSDKManager.I.RequestBuyProduct(string productID, string ext = "", bool testIsSucceed = true);
Iap\_ShowLoading
事件
c#
ZMYSDKManager.I.Iap_ShowLoading += ShowLoading;
发起购买后会触发Iap\_ShowLoading
事件,这是个全屏遮罩事件,业务研发应该监听此事件,并且阻断用户进一步操作,等待购买完成。
Iap\_CloseLoading
事件
c#
ZMYSDKManager.I.Iap_CloseLoading += CloseLoading;
购买流程结束后触发Iap\_CloseLoading
,业务方应该监听此事件,关闭全屏遮罩.
发货接口
根据商品类型不同,有 3 个发货接口
消耗性商品:
c#
//商品获取渠道,产品ID
Action<CommdityChannel, string> Iap_ReceiveConsumableCommodity
非消耗性商品:Iap_ReshNonConsumableState
c#
//商品获取渠道,产品ID
Action<CommdityChannel, string> Iap_ReshNonConsumableState
订阅商品:Iap\_ReshSubscriptionState
c#
Action<NonConsumableState> Iap_ReshSubscriptionState
c#
public struct NonConsumableState
{
/// 产品ID
public string productId;
/// 状态0-查询失败 1-订阅中 2-订阅过期
public int state;
/// 获取渠道
public CommdityChannel channel;
/// 到期事件
public string expiresDate;
}
WARNING
💡 当订阅商品的 state 为 0 时,不要做任何处理。为此之前的商品状态记录
恢复购买
恢复当前已经购买的非消耗性道具、订阅商品。(注意:消耗性道具不能恢复)
c#
ZMYSDKManager.I.RequestRestoreBuy();
恢复到的结果,会以发货接口发送给业务方
订阅查询
查询订阅产品信息
c#
ZMYSDKManager.I.RequestCheckSubscription(string productId);
查询到的结果,会以发货接口发送给业务方
失败、复送、服务器赠送道具订单
SDK 会在UpdateIap
方法中轮询调用查询失败订单、复送订单和服务器赠送道具订单接口,业务方不用处理。
查询到的结果,会以发货接口发送给业务方,业务方需要下发道具。
获取商品信息
c#
ZMYSDKManager.I.GetProductInfo(string productId);
c#
/* {
"sku": "com.test.test.test.pigbank",
"price": "2.99",
"title": "Piggy Bank",
"priceCountryApiType": "US$",
"priceCountryApiCode": "USD",
"description": "Offers up to 3200 coins upon purchasing."*/
public class ProductInfo
{
///商品ID
public string sku;
/// 标题
public string title;
/// 描述
public string description;
/// 价格
public string price;
/// 货币的符号
public string priceCountryApiType;
/// 币种
public string priceCountryApiCode;
/// 货币符号
public string Currency
{
get
{
if (string.IsNullOrEmpty(priceCountryApiType))
{
return priceCountryApiCode;
}
return priceCountryApiType;
}
}
}
pay_show 上报
当内购商品展示时,需要进行 pay_show 上报
c#
ZMYSDKManager.I.ReportPayShow(string productId);
IAPButton(推荐使用)
为了方便接入,集成商品购买、上报、获取信息功能,封装成IAPButton
组件

点我快速对接


