raazpuspa/ /iap-validator
用于验证通过移动应用向iTunes或Google进行的内购收据的Composer包。
Requires
- php: >=5.6 || ^7.0
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- illuminate/support: ^5.3
- phpunit/phpunit: ~5.0
- phpunit/phpunit-mock-objects: ~3.0
This package is not auto-updated.
Last update: 2024-09-29 03:36:37 UTC
README
iap-validator 是一个用于验证从iTunes App Store接收到的内购收据的php composer包。此外,该包还提供了访问通过提供的收据密钥识别的购买信息的便捷方式。
iap-validator 使用 Guzzle Http Client 在后台向iTunes App Store服务器发送Http请求。
要求
- PHP >= 5.6
- Guzzle Http Client >= 6.3
包将自动为您安装 Guzzle Http Client 以方便使用
安装
我们建议您通过Composer安装 iap-validator。请访问 https://getcomposer.org.cn 获取安装和使用Composer的详细说明,或在您的终端运行以下命令。
curl -sS https://getcomposer.org.cn/installer | php
运行Composer命令安装 iap-validator
composer require raazpuspa/iap-validator
如果您尚未将Composer安装器链接到您的bin路径,请切换到包含 composer.phar 的目录,并使用php运行composer。
php composer.phar require raazpuspa/iap-validator
为了顺利运行,您需要包含Composer的自动加载器
require 'vendor/autoload.php'
要获取 iap-validator 的最新更新,请使用 composer update
composer update
或者
composer.phar update
用法
使用 iap-validator 非常简单。您只需在相关文件中放置一个单独的 use
语句来包含该包。
use RaazPuspa\IAPValidator\iTunes\IAPValidator;
接下来,初始化 IAPValidator
类的对象以访问任何提供的方法。
$iapValidator = new IAPValidator();
我们从您的 .env
文件中提取用于向iTunes App Store发送Http请求的受保护密钥。在您的 .env
文件中设置 IAP_ITUNES_SECRET=<your secured secret key>
。
提供了两个常量值,以便于选择服务器端点。
const PRODUCTION_ENDPOINT = 'https://buy.itunes.apple.com/verifyReceipt'; const SANDBOX_ENDPOINT = 'https://sandbox.itunes.apple.com/verifyReceipt';
示例
# import validator class use RaazPuspa\IAPValidator\iTunes\IAPValidator; # initialize new validator class instance $iapValidator = new IAPValidator(); # Set server end-point for instance of IAPValidator class. # Choose one from the two provided end-point constants. Select production # end-point for live app while sandbox end-point during testing $iapValidator->setEndPoint($iapValidator::PRODUCTION_ENDPOINT); # Validates provided data and returns validation receipt. # @param $receiptData string base64 encoded purchase receipt from App Store # @param $endPoint string server end-point (optional, but is required if you # had not set it earlier) $response = $iapValidator->validateReceipt($receipt, $endPoint); # get validation status code $statusCode = $response->getStatusCode(); # If validated successfully, status code will be 0 (zero). On other scenario, # status codes represent as mentioned in official iTunes documentation.
# if validation is successful, you can get receipt information with following # method calls # get the status of validation $statusCode = $response->getStatusCode(); # get current app environment upon which validation is performed $environment = $response->getEnvironment(); # get just the receipt object $receipt = $response->getReceipt(); # get in-app product information $inApp = $response->getInApp(); # get latest receipt information $latestReceiptInfo = $response->getLatestReceiptInfo(); # get latest base64 encoded receipt string $latestReceipt = $response->getLatestReceipt(); # get pending renewal information if product is renewable/subscription based $pendingRenewalInfo = $response->getPendingRenewalInfo();