hoels/app-store-server-library-php
Composer 安装命令:
composer require hoels/app-store-server-library-php
包简介
The PHP server library for the App Store Server API and App Store Server Notifications.
README 文档
README
The unofficial PHP server library for the App Store Server API, App Store Server Notifications, and Retention Messaging API. Also available in Swift, Python, Node.js, and Java.
Table of Contents
Author
I am NOT associated with Apple in any way. I am an app developer and IT security specialist who developed this library because Apple does not offer a dedicated PHP library. Not offering a native and secure library leads to insecure third-party implementations imho. Therefore, this library is intended to mirror the native Apple libraries as closely as possible. Most of the functionality is an exact copy of Apple's Python library, with some PHP-specific modifications and influences from Apple's Swift library. I intend to keep this library and its major versions up-to-date with the Apple libraries.
Installation
Requirements
- PHP 8.1+
- OpenSSL and JSON PHP Extension
- Composer
Composer
composer require hoels/app-store-server-library-php
Documentation
Documentation of Python Library
Obtaining an In-App Purchase key from App Store Connect
To use the App Store Server API or create promotional offer signatures, a signing key downloaded from App Store Connect is required. To obtain this key, you must have the Admin role. Go to Users and Access > Integrations > In-App Purchase. Here you can create and manage keys, as well as find your issuer ID. When using a key, you'll need the key ID and issuer ID as well.
Obtaining Apple Root Certificates
Download and store the root certificates found in the Apple Root Certificates section of the Apple PKI site. Provide these certificates as an array to a SignedDataVerifier to allow verifying the signed data coming from Apple.
Usage
API Usage
use AppStoreServerLibrary\AppStoreServerAPIClient; use AppStoreServerLibrary\AppStoreServerAPIClient\APIException; use AppStoreServerLibrary\Models\Environment; $privateKey = file_get_contents("/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"); // Implementation will vary $keyId = "ABCDEFGHIJ"; $issuerId = "99b16628-15e4-4668-972b-eeff55eeff55"; $bundleId = "com.example"; $environment = Environment::SANDBOX; $client = new AppStoreServerAPIClient( signingKey: $privateKey, keyId: $keyId, issuerId: $issuerId, bundleId: $bundleId, environment: $environment ); try { $response = $client->requestTestNotification(); print_r($response); } catch (APIException $e) { print_r($e); }
Verification Usage
use AppStoreServerLibrary\Models\Environment; use AppStoreServerLibrary\SignedDataVerifier; use AppStoreServerLibrary\SignedDataVerifier\VerificationException; $rootCertificates = load_root_certificates(); // Implementation will vary $enableOnlineChecks = true; $bundleId = "com.example"; $environment = Environment::SANDBOX; $appAppleId = null; // appAppleId must be provided for the Production environment $signedDataVerifier = new SignedDataVerifier( rootCertificates: $rootCertificates, enableOnlineChecks: $enableOnlineChecks, environment: $environment, bundleId: $bundleId, appAppleId: $appAppleId ); try { $signedNotification = "ey.."; $payload = $signedDataVerifier->verifyAndDecodeNotification($signedNotification); print_r($payload); } catch (VerificationException $e) { print_r($e); }
Receipt Usage
use AppStoreServerLibrary\AppStoreServerAPIClient; use AppStoreServerLibrary\AppStoreServerAPIClient\APIException; use AppStoreServerLibrary\Models\Environment; use AppStoreServerLibrary\Models\TransactionHistoryRequest; use AppStoreServerLibrary\Models\TransactionHistoryRequest\Order; use AppStoreServerLibrary\Models\TransactionHistoryRequest\ProductType; use AppStoreServerLibrary\ReceiptUtility; $privateKey = file_get_contents("/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"); // Implementation will vary $keyId = "ABCDEFGHIJ"; $issuerId = "99b16628-15e4-4668-972b-eeff55eeff55"; $bundleId = "com.example"; $environment = Environment::SANDBOX; $client = new AppStoreServerAPIClient( signingKey: $privateKey, keyId: $keyId, issuerId: $issuerId, bundleId: $bundleId, environment: $environment ); $receiptUtility = new ReceiptUtility(); $appReceipt = "MI.."; try { $transactionId = $receiptUtility->extractTransactionIdFromAppReceipt($appReceipt); if ($transactionId !== null) { $transactions = []; $response = null; $request = new TransactionHistoryRequest( sort: Order::ASCENDING, revoked: false, productTypes: [ProductType::AUTO_RENEWABLE] ); while ($response === null || $response->getHasMore() === true) { $revision = $response?->getRevision(); $response = $client->getTransactionHistory( transactionId: $transactionId, revision: $revision, transactionHistoryRequest: $request ); foreach ($response->getSignedTransactions() as $transaction) { $transactions[] = $transaction; } } print_r($transactions); } } catch (APIException $e) { print_r($e); }
Promotional Offer Signature Creation
use AppStoreServerLibrary\PromotionalOfferSignatureCreator; $privateKey = file_get_contents("/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"); // Implementation will vary $keyId = "ABCDEFGHIJ"; $bundleId = "com.example"; $promotionalOfferSignatureCreator = new PromotionalOfferSignatureCreator( signingKey: $privateKey, keyId: $keyId, bundleId: $bundleId ); $productId = "<product_id>"; $subscriptionOfferId = "<subscription_offer_id>"; $applicationUsername = "<application_username>"; $nonce = "<nonce>"; $timestamp = time() * 1000; $base64EncodedSignature = $promotionalOfferSignatureCreator->createSignature( productIdentifier: $productId, subscriptionOfferId: $subscriptionOfferId, applicationUsername: $applicationUsername, nonce: $nonce, timestamp: $timestamp );
Support
Only the latest major version of the library will receive updates, including security updates. Therefore, it is recommended to update to new major versions.
hoels/app-store-server-library-php 适用场景与选型建议
hoels/app-store-server-library-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 204.67k 次下载、GitHub Stars 达 44, 最近一次更新时间为 2023 年 12 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hoels/app-store-server-library-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hoels/app-store-server-library-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 204.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 44
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-10