IAPUserData.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // IAPUserData.hpp
  3. // TileManor
  4. //
  5. // Created by 徐炼新 on 2024/9/30.
  6. //
  7. #ifndef IAPUserData_hpp
  8. #define IAPUserData_hpp
  9. #include <cocos2d.h>
  10. #include "IAPDefine.hpp"
  11. NS_IAPSHOP_BEGIN
  12. class IAPUserData {
  13. public:
  14. static IAPUserData* getInstance();
  15. IAPUserData();
  16. ~IAPUserData();
  17. // 添加购买信息
  18. // 参数说明 : 商品id
  19. void addBuyInfo(std::string commodityID);
  20. void addBuyInfo(std::vector<std::string> commodityIDs);
  21. // 获取用户购买记录
  22. std::vector<std::string> getBuyInfos();
  23. // 清除所有购买信息
  24. void clearBuyInfo();
  25. private:
  26. void init();
  27. std::string serialize(const std::vector<std::string>& vec);
  28. std::vector<std::string> deserialize(const std::string& str);
  29. void saveVectorString(const std::vector<std::string>& vec, const std::string& key);
  30. std::vector<std::string> loadVectorString(const std::string& key);
  31. private:
  32. static IAPUserData* _instance;
  33. std::vector<std::string> _buyInfos; // 用户购买信息
  34. };
  35. NS_IAPSHOP_END
  36. #endif /* IAPUserData_hpp */