123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- //
- // IAPUtils.h
- // cocos2d_libs
- //
- // Created by ZhengSong on 2021/5/6.
- //
- #ifndef IAPUtils_h
- #define IAPUtils_h
- #include <string>
- #include <map>
- #include "IAPProductInfo.h"
- namespace iap {
- class IAPDelegate;
- enum IAPProductType {
- Consumable = 0, //消耗品
-
- // 暂不支持以下类型
- // Non_Consumable = 1, //非消耗品(永久拥有)
- // Subscribe = 2, //订阅类型
- // SubscribeAutoRenew = 3 //自动续期订阅型
- };
- class IAPUtils {
- public:
- IAPUtils();
- ~IAPUtils();
-
- static IAPUtils* getInstance();
- void setDelegate(IAPDelegate* delegate) { _delegate = delegate; }
-
- // 建议在收到Delegate的onProductInfoSyncFinished回调之后,再调用会比较安全
- // !!! 可能为空
- IAPProductInfo getProductInfo(const std::string &productId);
-
- // 购买
- void purchase(const std::string &productId);
- // 用指定的ID进行初始化
- void initWithProductIds(const std::map<std::string, IAPProductType>& productIds);
-
- void setLogMode(bool isLog);
- // 加载iap.json配置
- void loadIAPConfig();
-
- public:
- // 平台事件回调
-
- // 商品信息同步完成
- void nativeCallback_onProductInfoSyncFinished();
- // 内购成功
- void nativeCallback_onPurchaseSuccess(const std::string& productId);
- void nativeCallback_onPurchaseFail(const std::string& productId, int errorCode, const std::string& errorMsg);
- // 同步已购商品(特例)
- void nativeCallback_onSyncPurchasedProducts(const std::string& productIdListJson);
-
- private:
- IAPDelegate *_delegate;
- // 保证只初始化一次
- bool _isInited = false;
- };
- }; // end of namespace iap
- #endif /* IAPUtils_h */
|