定制 readdle/app-store-server-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

readdle/app-store-server-api

Composer 安装命令:

composer require readdle/app-store-server-api

包简介

Pure-PHP library that allows managing customer transactions using the App Store Server API and handling server-to-server notifications using the App Store Server Notifications V2

README 文档

README

This is a zero-dependencies* pure PHP library that allows managing customer transactions using the App Store Server API and handling server-to-server notifications by providing everything you need to implement the App Store Server Notifications V2 endpoint.

* Zero-dependencies means this library doesn't rely on any third-party library. At the same time, this library relies on such essential PHP extensions as json and openssl

NOTE

If you need to deal with receipts instead of (or additionally to) API, check out this library.

App Store Server API version compatibility: 1.15 - 2025/02/21

Installation

Nothing special here, just use composer to install the package:

composer require readdle/app-store-server-api

Usage

App Store Server API

API initialization:

try {
    $api = new \Readdle\AppStoreServerAPI\AppStoreServerAPI(
        \Readdle\AppStoreServerAPI\Environment::PRODUCTION,
        '1a2b3c4d-1234-4321-1111-1a2b3c4d5e6f',
        'com.readdle.MyBundle',
        'ABC1234DEF',
        "-----BEGIN PRIVATE KEY-----\n<base64-encoded private key goes here>\n-----END PRIVATE KEY-----"
    );
} catch (\Readdle\AppStoreServerAPI\Exception\WrongEnvironmentException $e) {
    exit($e->getMessage());
}

Performing API call:

try {
    $transactionHistory = $api->getTransactionHistory($transactionId, ['sort' => GetTransactionHistoryQueryParams::SORT__DESCENDING]);
    $transactions = $transactionHistory->getTransactions();
} catch (\Readdle\AppStoreServerAPI\Exception\AppStoreServerAPIException $e) {
    exit($e->getMessage());
}

App Store Server Notifications

try {
    $responseBodyV2 = \Readdle\AppStoreServerAPI\ResponseBodyV2::createFromRawNotification(
        '{"signedPayload":"..."}',
        \Readdle\AppStoreServerAPI\Util\Helper::toPEM(file_get_contents('https://www.apple.com/certificateauthority/AppleRootCA-G3.cer'))
    );
} catch (\Readdle\AppStoreServerAPI\Exception\AppStoreServerNotificationException $e) {
    exit('Server notification could not be processed: ' . $e->getMessage());
}

Examples

In examples/ directory you can find examples for all implemented endpoints. Initialization of the API client is separated into client.php and used in all examples.

In order to run examples you have to create credentials.json and/or notifications.json inside examples/ directory.

credentials.json structure should be as follows:

{
  "env": "Production",
  "issuerId": "1a2b3c4d-1234-4321-1111-1a2b3c4d5e6f",
  "bundleId": "com.readdle.MyBundle",
  "keyId": "ABC1234DEF",
  "key": "-----BEGIN PRIVATE KEY-----\n<base64-encoded private key goes here>\n-----END PRIVATE KEY-----",
  "orderId": "ABC1234DEF",
  "transactionId": "123456789012345"
}

In most examples transactionId is used. Please, consider that transactionId is related to environment, so if you put transactionId from the sandbox the environment property should be Sandbox as well, otherwise you'll get {"errorCode":4040010,"errorMessage":"Transaction id not found."} error.

For Order ID lookup you have to specify orderId. This endpoint (and, consequently, the example) is not available in the sandbox environment.

notification.json structure is the same as you receive it in your server-to-server notification endpoint:

{"signedPayload":"<JWT token goes here>"}

What is covered

In-app purchase history V1 (Deprecated, but left for backwards compatibility)

Get Transaction History

AppStoreServerAPI::getTransactionHistory(string $transactionId, array $queryParams)

Get a customer’s in-app purchase transaction history for your app.

In-app purchase history V2

Get Transaction History

AppStoreServerAPI::getTransactionHistoryV2(string $transactionId, array $queryParams)

Get a customer’s in-app purchase transaction history for your app.

Transaction Info

Get Transaction Info

AppStoreServerAPI::getTransactionInfo(string $transactionId)

Get information about a single transaction for your app.

Subscription status

Get All Subscription Statuses

AppStoreServerAPI::getAllSubscriptionStatuses(string $transactionId, array $queryParams = [])

Get the statuses for all of a customer’s auto-renewable subscriptions in your app.

Consumption information

Send Consumption Information

AppStoreServerAPI::sendConsumptionInformation(string $transactionId, array $requestBody)

Send consumption information about a consumable in-app purchase to the App Store after your server receives a consumption request notification.

Order ID lookup

Look Up Order ID

AppStoreServerAPI::lookUpOrderId(string $orderId)

Get a customer’s in-app purchases from a receipt using the order ID.

Refund lookup

Get Refund History

AppStoreServerAPI::getRefundHistory(string $transactionId)

Get a list of all of a customer’s refunded in-app purchases for your app.

Subscription-renewal-date extension

Extend a Subscription Renewal Date

AppStoreServerAPI::extendSubscriptionRenewalDate(string $originalTransactionId, array $requestBody)

Extends the renewal date of a customer’s active subscription using the original transaction identifier.

Extend Subscription Renewal Dates for All Active Subscribers

AppStoreServerAPI::massExtendSubscriptionRenewalDate(array $requestBody)

Uses a subscription’s product identifier to extend the renewal date for all of its eligible active subscribers.

Get Status of Subscription Renewal Date Extensions

AppStoreServerAPI::getStatusOfSubscriptionRenewalDateExtensionsRequest(string $productId, string $requestIdentifier)

Checks whether a renewal date extension request completed, and provides the final count of successful or failed extensions.

App Store Server Notifications history

Get Notification History

AppStoreServerAPI::getNotificationHistory(array $requestBody)

Get a list of notifications that the App Store server attempted to send to your server.

App Store Server Notifications testing

Request a Test Notification

AppStoreServerAPI::requestTestNotification()

Ask App Store Server Notifications to send a test notification to your server.

Get Test Notification Status

AppStoreServerAPI::getTestNotificationStatus(string $testNotificationToken)

Check the status of the test App Store server notification sent to your server.

readdle/app-store-server-api 适用场景与选型建议

readdle/app-store-server-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 459.38k 次下载、GitHub Stars 达 74, 最近一次更新时间为 2022 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「parser」 「apple」 「itunes」 「purchase」 「in app」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 readdle/app-store-server-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 readdle/app-store-server-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 readdle/app-store-server-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 459.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 74
  • 点击次数: 31
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 74
  • Watchers: 6
  • Forks: 25
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-25