tanghengzhi / app-store-server-api-client
用于 App Store Server API 的 PHP 客户端。
Requires
- php: ^7.2|^8.0
- ext-json: *
- firebase/php-jwt: ^5.5|^6.4
- guzzlehttp/guzzle: ^6.5|^7.4
- nullform/http-status: ^1.1
- symfony/uid: ^5.4|^6.0
This package is auto-updated.
Last update: 2024-09-16 04:04:11 UTC
README
非官方的 PHP 客户端,用于 App Store Server API。
要求
- PHP >= 7.2
安装
composer require nullform/app-store-server-api-client
使用方法
创建 API Key 实例
$apiKey = new class extends AbstractApiKey {}; $apiKey->setPrivateKey(\file_get_contents($privateKeyFile)); $apiKey->setPrivateKeyId('Your private key id'); $apiKey->setIssuerId('Your issuer id'); $apiKey->setName('Key name (optional)');
创建 Bundle 实例(s)
$bundle = new class extends AbstractBundle {}; $bundle->setBundleId('Your bundle id'); $bundle->setName('Bundle name (optional)'); $bundle2 = new class extends AbstractBundle {}; $bundle2->setBundleId('Your bundle #2 id');
创建 API 客户端实例
$client = new AppStoreServerApiClient($apiKey, $bundle, Environment::PRODUCTION);
使用客户端处理一个或多个 Bundle
try { $historyResponse = $client->getTransactionHistory($originalTransactionId); $transactions = $historyResponse->getDecodedTransactions(); } catch (HttpClientException $httpClientException) { echo "HTTP client error: " . $httpClientException->getMessage(); } catch (AppleException $appleException) { echo "Apple error ({$appleException->getCode()}): " . $appleException->getMessage(); } try { $bundle2HistoryResponse = $client->setBundle($bundle2)->getTransactionHistory($originalTransactionId); } catch (\Exception $e) { echo "Error: " . $e->getMessage(); }
方法
AppStoreServerApiClient::getTransactionHistory
AppStoreServerApiClient::getTransactionHistory(string $originalTransactionId, ?string $revision = null): HistoryResponse
获取您应用程序中客户的内购交易历史。
https://developer.apple.com/documentation/appstoreserverapi/get_transaction_history
AppStoreServerApiClient::getAllTransactionHistory
AppStoreServerApiClient::getAllTransactionHistory(string $originalTransactionId): JWSTransactionDecodedPayload[]
递归获取完整交易历史。
AppStoreServerApiClient::getAllSubscriptionStatuses
AppStoreServerApiClient::getAllSubscriptionStatuses(string $originalTransactionId): StatusResponse
获取您应用程序中客户所有订阅的状态。
https://developer.apple.com/documentation/appstoreserverapi/get_all_subscription_statuses
AppStoreServerApiClient::sendConsumptionInformation
AppStoreServerApiClient::sendConsumptionInformation(string $originalTransactionId, ConsumptionRequest $request): void
在您的服务器接收到消耗请求通知后,将消耗信息发送到 App Store。
https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information
AppStoreServerApiClient::lookUpOrderId
AppStoreServerApiClient::lookUpOrderId(string $orderId): OrderLookupResponse
使用订单 ID 从收据中获取客户的内购项目。
https://developer.apple.com/documentation/appstoreserverapi/look_up_order_id
AppStoreServerApiClient::getRefundHistory
AppStoreServerApiClient::getRefundHistory(string $originalTransactionId): RefundLookupResponse
获取客户在您的应用程序中所有已退还的内购项目的列表。
https://developer.apple.com/documentation/appstoreserverapi/get_refund_history
AppStoreServerApiClient::extendSubscriptionRenewalDate
AppStoreServerApiClient::extendSubscriptionRenewalDate( string $originalTransactionId, ExtendRenewalDateRequest $request ): ExtendRenewalDateResponse
使用原始交易标识符扩展客户活跃订阅的续订日期。
https://developer.apple.com/documentation/appstoreserverapi/extend_a_subscription_renewal_date
AppStoreServerApiClient::setBundle
AppStoreServerApiClient::setBundle(BundleInterface $bundle): self
设置 App Store Bundle 以授权您的 API 调用。
AppStoreServerApiClient::setTokenTtl
AppStoreServerApiClient::setTokenTtl(int $ttl): self
设置 JWT TTL 的新值(以秒为单位)。最大值:3600。
https://developer.apple.com/documentation/appstoreserverapi/generating_tokens_for_api_requests
AppStoreServerApiClient::setHttpClientRequestTimeout
AppStoreServerApiClient::setHttpClientRequestTimeout(float $timeout): self
设置 HTTP 客户端请求超时的新值(以秒为单位)。
接收 App Store Server 通知 V2
要接收 App Store Server 通知,请使用 AppStoreServerNotificationsClient
$notificationClient = new AppStoreServerNotificationsClient(); try { $payload = $notificationClient->receive($requestBody); } catch (NotificationBadRequestException $exception) { echo $exception->getMessage(); }
注意:AppStoreServerNotificationsClient 仅适用于版本 2 通知。