bricre/amazon-selling-partner-sdk-fba-inventory

由 Amazon Selling Partner API for FBA Inventory 的 OpenAPI 定义生成的 API 客户端

v1 2021-09-23 22:35 UTC

This package is auto-updated.

Last update: 2024-09-24 05:56:12 UTC


README

使用 Amazon 的 Swagger 文件通过 allansun/openapi-code-generator 生成的代码。

生成的代码有良好的自文档,带有适当的 PHPDoc 注释。

有关详细 API 行为说明,请参阅 Amazon 的文档

安装

composer require bricre/amazon-selling-partner-sdk-fba-inventory

您还需要一个基于 PSR-7 的客户端或 Symfony 的 HTTP Foundation 基于的客户端

所以您可以使用 Guzzle(或其他任何 PSR-7 兼容的客户端)

composer require guzzlehttp/guzzle

或者 Symfony HTTP 客户端

composer require symfony/http-client

版本控制

此项目与 Amazon 的 API 版本控制相匹配。

由于 Composer 的限制,版本号 '2021-01-01' 将更改为 '2021.01.01'。

如果您发现没有可用的匹配版本,请联系作者生成正确的版本。

用法

首先,您需要使用所需凭据和预定义的响应类型配置 OpenAPI\RunTime\Client。您只需这样做一次(或在您的依赖注入中创建一个服务)。

您还可以查看 Amazon 关于 如何授权您的请求 的文档。

<?php
use Amz\FbaInventory\ResponseTypes;
use OpenAPI\Runtime\Client;
use OpenAPI\Runtime\SimplePsrResponseHandlerStack;

Client::configure(
    new \GuzzleHttp\Client([
        'base_uri' => 'https://sellingpartnerapi-na.amazon.com/',
        'headers'=>[
            'Authorization'=> 'Bearer <accessToken>'
        ]
    ]),
    new SimplePsrResponseHandlerStack(new ResponseTypes())
);

然后,在您的业务逻辑中,您可以直接调用 API 操作

<?php
use Amz\AplusContent\Api\AplusContent;
use Ebay\Sell\Account\Api\Program;

$api = new AplusContent();

$docs = $api->searchContentDocuments(['marketplaceId'=>'xxxxxx']);

作者