首页
/ InAppPy 项目使用教程

InAppPy 项目使用教程

2024-09-10 08:08:15作者:何举烈Damon

1. 项目的目录结构及介绍

InAppPy/
├── LICENSE
├── README.md
├── inapppy/
│   ├── __init__.py
│   ├── googleplay.py
│   ├── appstore.py
│   ├── errors.py
│   ├── asyncio/
│   │   ├── __init__.py
│   │   ├── googleplay.py
│   │   ├── appstore.py
│   └── tests/
│       ├── __init__.py
│       ├── test_googleplay.py
│       ├── test_appstore.py
├── setup.py
└── requirements.txt

目录结构介绍

  • LICENSE: 项目的开源许可证文件。
  • README.md: 项目的基本介绍和使用说明。
  • inapppy/: 项目的主要代码目录。
    • init.py: 初始化文件,使得 inapppy 成为一个 Python 包。
    • googleplay.py: 包含 Google Play 内购验证的实现。
    • appstore.py: 包含 Apple App Store 内购验证的实现。
    • errors.py: 定义了项目中可能出现的错误类型。
    • asyncio/: 异步版本的实现。
      • init.py: 初始化文件,使得 asyncio 成为一个子包。
      • googleplay.py: 异步版本的 Google Play 内购验证实现。
      • appstore.py: 异步版本的 Apple App Store 内购验证实现。
    • tests/: 项目的测试代码。
      • init.py: 初始化文件,使得 tests 成为一个包。
      • test_googleplay.py: 测试 Google Play 内购验证的代码。
      • test_appstore.py: 测试 Apple App Store 内购验证的代码。
  • setup.py: 用于安装项目的配置文件。
  • requirements.txt: 项目依赖的 Python 包列表。

2. 项目的启动文件介绍

InAppPy 项目没有传统意义上的“启动文件”,因为它是一个库,而不是一个独立的应用程序。用户在使用时,通常会直接导入 inapppy 包中的模块来使用内购验证功能。

例如,验证 Google Play 内购的代码如下:

from inapppy import GooglePlayValidator, InAppValidationError

bundle_id = 'com.yourcompany.yourapp'
api_key = 'API key from the developer console'
validator = GooglePlayValidator(bundle_id, api_key)

try:
    validation_result = validator.validate('receipt', 'signature')
except InAppValidationError:
    # 处理验证错误
    pass

3. 项目的配置文件介绍

InAppPy 项目没有专门的配置文件,用户在使用时需要根据具体需求传递参数。例如,验证 Google Play 内购时需要传递 bundle_idapi_key,验证 Apple App Store 内购时需要传递 bundle_id 和可选的 shared_secret

示例配置

  • Google Play:

    • bundle_id: 应用的包名。
    • api_key: 从 Google Play 开发者控制台获取的 API 密钥。
  • Apple App Store:

    • bundle_id: 应用的包名。
    • shared_secret: 可选的共享密钥,用于验证订阅。

使用示例

from inapppy import AppStoreValidator, InAppValidationError

bundle_id = 'com.yourcompany.yourapp'
shared_secret = 'your_shared_secret'  # 可选
validator = AppStoreValidator(bundle_id, shared_secret)

try:
    validation_result = validator.validate('receipt')
except InAppValidationError:
    # 处理验证错误
    pass

通过以上配置和使用示例,用户可以轻松地在项目中集成 InAppPy 进行内购验证。

登录后查看全文
热门项目推荐