定制 mantix/app-store-connect-api 二次开发

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

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

mantix/app-store-connect-api

Composer 安装命令:

composer require mantix/app-store-connect-api

包简介

A PHP client library for accessing App Store Connect APIs

README 文档

README

GitHub Release Packagist Downloads Packagist License Packagist Dependency Version

Overview

This library enables developers to automate their interactions with App Store Connect. It's a fork of the excellent cantie/app-store-connect-api-php package, updated to work with modern PHP frameworks including Laravel 10+ and Carbon 3.x.

The client was originally modified from Google API PHP Client with resources specifically added for App Store Connect APIs.

Why This Fork?

This fork was created to address the following needs:

  • Support for modern Laravel applications (10+)
  • Compatibility with Carbon 3.x
  • Future Laravel package development
  • Ongoing maintenance and updates
  • Enhanced documentation

We maintain high compatibility with the original package while ensuring it works in modern PHP environments.

Installation

The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

composer require mantix/app-store-connect-api

Coming Soon: Laravel Package

We're working on a dedicated Laravel package that will provide:

  • Simple configuration through Laravel's configuration system
  • Integration with Laravel's service container
  • Artisan commands for common App Store Connect operations
  • Middleware for API rate limiting and token management
  • Simple facade access to the API client

Stay tuned for mantix/laravel-app-store-connect.

Usage Examples

Basic Example

use AppleClient;
use AppleService_AppStore;
use Mantix\AppStoreConnect\Services\AppStore\CustomerReviewResponseV1CreateRequest;

$client = new AppleClient();
$client->setApiKey("PATH_TO_API_KEY");
$client->setIssuerId($issuerId);
$client->setKeyIdentifier($keyIdentifier);

$appstore = new AppleService_AppStore($client);
// Get apps by Bundle ID
$results = $appstore->apps->listApps([
    "filter[bundleId]" => "YOUR_BUNDLE_ID" // filter LIKE
]);

// Get all customer reviews for each app
foreach ($results->getData() as $app) {
    $appCustomerReviews = $appstore->apps->listAppsCustomerReviews($app->getId());
    foreach ($appCustomerReviews as $appCustomerReview) {
        // Print all reviewer's nickname
        echo $appCustomerReview->getAttributes()->getReviewerNickName(), "<br /> \n";

        // Get response for this review
        $customerReviewResponseV1Response = $appstore->customerReviews->getCustomerReviewsResponse($appCustomerReview->getId());

        // Create or update response for this review
        $postBody = new CustomerReviewResponseV1CreateRequest([
            'data' => [
                'attributes' => [
                    'responseBody' => "YOUR_REPLY_TEXT_HERE"
                ],
                'relationships' => [
                    'review' => [
                        'data' => [
                            'id' => $appCustomerReview->getId()
                        ]
                    ]
                ]
            ]
        ]);
        $customerReviewResponseV1Response = $appstore->customerReviewResponses->createCustomerReviewResponses($postBody);

        // Or just delete the response if existed
        $appstore->customerReviewResponses->deleteCustomerReviewResponses($customerReviewResponseV1Response->getData()->getId());
    }
}

Create New Client

use AppleClient;

$client = new AppleClient();
$client->setApiKey("PATH_TO_API_KEY");
$client->setIssuerId($issuerId);
$client->setKeyIdentifier($keyIdentifier);
// Optional: create new JWT token. If skip this step, token are auto generated when first request are sent
$client->generateToken();

Making a Request

For almost all requests except upload service, we use AppStore service:

use AppleService_AppStore;
// All resources and their methods parameters are listed in src/Service/AppStore.php
$appstore = new AppleService_AppStore($client);
// Make request, for example we call request for an Apps's resources
$appstore->apps->listAppsAppStoreVersions($APP_ID_HERE, $OPTIONAL_PARAMS);

For details, you can view the source code in src/Services/AppStore/Resource/*

Aliases

Basic classes are aliased for convenient use, see more at src/aliases.php

$classMap = [
    'Mantix\\AppStoreConnect\\Client' => 'AppleClient',
    'Mantix\\AppStoreConnect\\Service' => 'AppleService',
    'Mantix\\AppStoreConnect\\Services\\AppStore' => 'AppleService_AppStore',
    'Mantix\\AppStoreConnect\\Services\\Upload' => 'AppleService_Upload'
];

Upload Assets to App Store Connect

In this example we will upload one screenshot file to app screenshot set:

// Firstly, we get app screenshot set step by step, we can reduce steps by include[] parameters in query
use AppleService_Upload;
use Mantix\AppStoreConnect\Services\AppStore\AppScreenshotCreateRequest;
use Mantix\AppStoreConnect\Services\AppStore\AppScreenshotUpdateRequest;

$appId = $app->getId(); // $app from previous example
$appStoreVersions = $appstore->apps->listAppsAppStoreVersions($appId);
// Get first app store version id;
$appStoreVersionId = $appStoreVersions->getData()[0]->getId();
// Get list localizations of this version
$appStoreVersionLocalizations = $appstore->appStoreVersions->listAppStoreVersionsAppStoreVersionLocalizations($appStoreVersionId);
// Get first localization id
$appStoreVersionLocalizationId = $appStoreVersionLocalizations->getData()[0]->getId();
// Get list app screenshot sets for this localization
$appScreenshotSets = $appstore->appStoreVersionLocalizations->listAppStoreVersionLocalizationsAppScreenshotSets($appStoreVersionLocalizationId);
// Get first set id
$appScreenshotSetId = $appScreenshotSets->getData()[0]->getId();

// Now, we make an asset reservation
$fileName = "YOUR_FILE_NAME";
$filePath = "FULL_PATH_TO_YOUR_FILE" . $fileName;
$requestCreateAppScreenshot = new AppScreenshotCreateRequest([
    'data' => [
        'type' => 'appScreenshots',
        'attributes' => [
            'fileSize' => filesize($filePath),
            'fileName' => $fileName
        ],
        'relationships' => [
            'appScreenshotSet' => [
                'data' => [
                    'type' => 'appScreenshotSets',
                    'id' => $appScreenshotSetId
                ]
            ]
        ]
    ]
]);
// Create new app screenshot
$appScreenshot = $appstore->appScreenshots->createAppScreenshots($requestCreateAppScreenshot);
$appScreenshotId = $appScreenshot->getData()->getId();
// Follow instruction from UploadOperation[] return in $appScreenshot to upload part or whole asset file
// We can upload parts of your asset concurrently
foreach ($appScreenshot->getData()->getAttributes()->getUploadOperations() as $uploadOperation) {
    $upload = new AppleService_Upload($client, $uploadOperation); // $client from above example
    $ret = $upload->uploadAssets->upload($uploadOperation, $filePath);
}
// Finally, commit the reservation
$appScreenshotUpdateRequest = new AppScreenshotUpdateRequest([
    'data' => [
        'type' => 'appScreenshots',
        'id' => $appScreenshotId,
        'attributes' => [
            'sourceFileChecksum' => md5_file($filePath),
            'uploaded' => true
        ]
    ]
]);
$ret = $appstore->appScreenshots->updateAppScreenshots($appScreenshotId, $appScreenshotUpdateRequest); 

Initialize Classes

All object classes that extend from Model.php can be initialized with an array of attribute names and values, as in the previous example:

use Mantix\AppStoreConnect\Services\AppStore\AppScreenshotUpdateRequest;
$appScreenshotUpdateRequest = new AppScreenshotUpdateRequest([
    'data' => [
        'type' => 'appScreenshots',
        'id' => $appScreenshotId,
        'attributes' => [
            'sourceFileChecksum' => md5_file($filePath),
            'uploaded' => true
        ]
    ]
]);

Caching

JWT tokens are cached for 10 minutes and only generated if they don't exist or have expired. JWT tokens are not shared between clients. Each client has its own token as defined in src/Client.php:

public function generateToken()
{
    $tokenGenerator = new Generate($this->getApiKey(), $this->getKeyIdentifier(), $this->getIssuerId());
    $jwtToken = $tokenGenerator->generateToken();
    // cache for 10 minutes
    $this->jwtToken = $jwtToken;
    $this->jwtTokenExpTime = (new DateTime())->modify("+10 minutes")->getTimestamp();
    return $jwtToken;
}

Laravel Integration

While we're working on our dedicated Laravel package, here's a simple approach to integrate this library into your Laravel applications:

Service Provider

Create a service provider for App Store Connect API:

<?php

namespace App\Providers;

use AppleClient;
use AppleService_AppStore;
use Illuminate\Support\ServiceProvider;

class AppStoreConnectServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton(AppleClient::class, function ($app) {
            $client = new AppleClient();
            $client->setApiKey(storage_path('app/appstore_private_key.p8'));
            $client->setIssuerId(config('services.appstore.issuer_id'));
            $client->setKeyIdentifier(config('services.appstore.key_id'));
            return $client;
        });

        $this->app->singleton(AppleService_AppStore::class, function ($app) {
            return new AppleService_AppStore($app->make(AppleClient::class));
        });
    }
}

Configuration

Update your config/services.php file:

'appstore' => [
    'key_id' => env('APPSTORE_KEY_ID'),
    'issuer_id' => env('APPSTORE_ISSUER_ID'),
]

Usage in Laravel

Now you can inject the service where needed:

<?php

namespace App\Http\Controllers;

use AppleService_AppStore;

class AppStoreController extends Controller
{
    public function listApps(AppleService_AppStore $appStoreService)
    {
        $apps = $appStoreService->apps->listApps();
        return view('apps.index', compact('apps'));
    }
}

Acknowledgements

This package is a fork of cantie/app-store-connect-api-php. We express our gratitude to the original authors for their excellent work. Our goal is to build upon their foundation to ensure compatibility with modern PHP frameworks while maintaining the core functionality.

License

This library is licensed under the MIT License.

mantix/app-store-connect-api 适用场景与选型建议

mantix/app-store-connect-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 177 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 177
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-23