mallgroup / mpapi-client
Mall 商场 API 的 PHP 客户端
v5.0.0
2023-02-01 08:33 UTC
Requires
- php-64bit: ^7.4 || ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- codeception/codeception: ^4.1
- codeception/module-asserts: ^1.0.0
- codeception/module-phpbrowser: ^1.0.0
- phpmd/phpmd: ^2.10
- phpstan/phpstan: ^0.12.88
- slevomat/coding-standard: ^7.0
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^4.7
- vlucas/phpdotenv: ^5.3
- dev-master
- v5.0.0
- v4.1.4
- v4.1.3
- v4.1.2
- v4.1.0
- v4.0.0
- v4.0.0-beta.4
- v4.0.0-beta
- v3.x-dev
- 3.14.0
- 3.13.0
- 3.12.2
- 3.12.1
- 3.12.0
- 3.11.6
- 3.11.5
- 3.11.4
- 3.11.3
- 3.11.1
- 3.11.0
- 3.10.1
- 3.10.0
- 3.9.3
- 3.9.2
- 3.9.1
- 3.9.0
- 3.8.3
- 3.8.2
- 3.8.0
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.1
- 3.5.0
- 3.4.0
- 3.3.2
- 3.3.1
- 3.2.0
- 3.1.0
- 3.0.0
- 2.16.2
- 2.15.0
- 2.14.2
- 2.14.1
- 2.14.0
- 2.13.0
- 2.12.2
- 2.12.1
- 2.12.0
- 2.11.6
- 2.11.5
- 2.11.4
- 2.11.3
- 2.11.2
- 2.11.1
- 2.11.0
- 2.10.2
- 2.10.0
- 2.9.0
- 2.8.0
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.1
- 2.4.0
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.9.7
- 1.9.5
- 1.9.4
- 1.9.3
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8
- 1.7.1
- 1.6.3
- 1.6.2
- 1.6.1
- v1.6
- 1.5.0
- 1.4.1
- v1.4
- 1.3.1
- 1.3.0
- v1.2
- dev-dependabot/composer/guzzlehttp/psr7-2.5.0
- dev-dependabot/composer/guzzlehttp/guzzle-7.4.5
- dev-client-v4-ci
This package is auto-updated.
Last update: 2024-09-19 21:26:38 UTC
README
商场市场 API 客户端
描述
MPAPI 客户端是一个工具,旨在帮助 Internet Mall, a. s. 合作伙伴使用 Mall 商场 API 容易地管理商品目录、配送、订单等。
要求
PHP 7.4
或PHP 8
的 64 位版本- Guzzle 7
安装
要在您的存储库中安装客户端,请使用 Composer 运行以下命令
composer require mallgroup/mpapi-client
实现
信息
客户端由一个主要客户端和多个独立的域名客户端组成。
主要客户端将所有域名客户端分组在一个对象下,以便于实现,但每个域名客户端都可以独立初始化和使用。
每个客户端都提供一个接口,应将其用作代码中的参数类型,而不是客户端类本身(即,使用 MpApiClientInterface $client
或 BrandsClientInterface $client
而不是 MpApiClient $client
或 BrandsClient $client
)。
初始化客户端时,您必须提供
- 实现 AuthMiddlewareInterface 的验证器
- 目前,只提供了 ClientIdAuthenticator,它接受
my-client-id
- 将来,将发布新的验证器(例如 OAuth)
- 目前,只提供了 ClientIdAuthenticator,它接受
- 使用 API 的应用程序的名称
- 它随每个请求发送到 Mall API,以便更容易识别请求和调试报告的问题
- 请提供一个简单但具有意义的名称,例如
MyAppName CRM
或MyAppName Order sync
,而不是随机字符串
示例
初始化客户端有两种主要方法
1. 使用默认配置的 MpApiClient
<?php declare(strict_types=1); use MpApiClient\Common\Authenticators\ClientIdAuthenticator; use MpApiClient\MpApiClient; use MpApiClient\MpApiClientOptions; require 'vendor/autoload.php'; // 1. Initialize client options with request authenticator $options = new MpApiClientOptions( new ClientIdAuthenticator('my-client-id') ); // 2. Initialize MP API Client $client = MpApiClient::createFromOptions('my-app-name', $options); // 3. Get brand client $brandClient = $client->brand();
2. 使用 MpApiClient(或任何其他域名客户端)和自定义 HTTP 客户端
- 每个域名客户端都可以以此方式初始化为独立的客户端
- 初始化自定义 HTTP 客户端时,必须提供带有
AuthMiddlewareInterface
的handler
栈!
<?php declare(strict_types=1); use GuzzleHttp\Client; use GuzzleHttp\Handler\CurlHandler; use GuzzleHttp\HandlerStack; use MpApiClient\Brand\BrandClient; use MpApiClient\Common\Authenticators\ClientIdAuthenticator; use MpApiClient\MpApiClient; use MpApiClient\MpApiClientOptions; require 'vendor/autoload.php'; // 1. Initialize request authenticator $authenticator = new ClientIdAuthenticator('my-client-id'); // 2. Create custom Guzzle http client with authenticator middleware // 2.1 Create CurlHandler stack and Guzzle http client manually $handler = new CurlHandler(); $handlerStack = HandlerStack::create($handler); $handlerStack->push($authenticator->getHandler()); $httpClient = new Client( [ 'base_uri' => 'https://mpapi.mallgroup.com/v1/', 'timeout' => 10, 'allow_redirects' => true, 'handler' => $handlerStack, ] ); // 2.2. Create Guzzle client using MpApiClientOptions object $options = new MpApiClientOptions($authenticator); $options->setTimeout(30); $httpClient = new Client($options->getGuzzleOptionsArray()); // 3. Create MpApiClient and BrandClient using custom Guzzle client $client = new MpApiClient($httpClient, 'my-app-name') $brandClient = new BrandClient($httpClient, 'my-app-name')
所有客户端域的示例
在此客户端中抛出的自定义异常列表可在此处找到 这里
⚠ 警告
- 客户端不包括对将来将更改、替换或删除的已弃用端点的支持(例如
/v1/deliveries
或/v1/gifts
)
ℹ 已知缺失或不完整的功能
/v2/transports
端点的支持