adolphyu/amazon-sp-api-php

v3.0.6 2024-03-11 07:48 UTC

This package is auto-updated.

Last update: 2024-09-19 11:35:46 UTC


README

个人使用!

这是一个针对新亚马逊卖家伙伴API的PHP绑定。

这个库基于swagger-codegen的输出以及亚马逊提供的OpenAPI文件,并由贡献者进行了修改。

此包的目的是通过简单的composer包轻松开始使用亚马逊卖家伙伴API。

要求

  • PHP >= 7.3
  • cURL扩展
  • JSON扩展
  • MBString扩展

安装

只需通过composer要求此包

composer require adolphyu/amazon-sp-api-php

详细文档

您可以在docs/Api目录中找到此PHP库的详细文档(请注意:命名空间和其他类可能已更改)

您可以在官方亚马逊开发者网站上找到有关亚马逊卖家伙伴API的一般信息。

示例

以下是一些简单的示例,仅用于展示如何开始调用API。

IAM角色

当你在开发者配置文件中输入了IAM角色ARN时使用

<?php

require_once './vendor/autoload.php';

$options = [
    'refresh_token' => '', // Aztr|...
    'client_id' => '', // App ID from Seller Central, amzn1.sellerapps.app.cfbfac4a-......
    'client_secret' => '', // The corresponding Client Secret
    'region' => \AdolphYu\AmazonSellingPartnerAPI\SellingPartnerRegion::$EUROPE, // or NORTH_AMERICA / FAR_EAST
    'access_key' => '', // Access Key of AWS IAM User, for example AKIAABCDJKEHFJDS
    'secret_key' => '', // Secret Key of AWS IAM User
    'endpoint' => \AdolphYu\AmazonSellingPartnerAPI\SellingPartnerEndpoint::$EUROPE, // or NORTH_AMERICA / FAR_EAST
    'role_arn' => '', // AWS IAM Role ARN for example: arn:aws:iam::123456789:role/Your-Role-Name
];
$accessToken = \AdolphYu\AmazonSellingPartnerAPI\SellingPartnerOAuth::getAccessTokenFromRefreshToken(
    $options['refresh_token'],
    $options['client_id'],
    $options['client_secret']
);
$assumedRole = \AdolphYu\AmazonSellingPartnerAPI\AssumeRole::assume(
    $options['region'],
    $options['access_key'],
    $options['secret_key'],
    $options['role_arn'],
);
$config = \AdolphYu\AmazonSellingPartnerAPI\Configuration::getDefaultConfiguration();
$config->setHost($options['endpoint']);
$config->setAccessToken($accessToken);
$config->setAccessKey($assumedRole->getAccessKeyId());
$config->setSecretKey($assumedRole->getSecretAccessKey());
$config->setRegion($options['region']);
$config->setSecurityToken($assumedRole->getSessionToken());
$apiInstance = new \AdolphYu\AmazonSellingPartnerAPI\Api\CatalogApi($config);
$marketplace_id = 'A1PA6795UKMFR9';
$asin = 'B0002ZFTJA';

$result = $apiInstance->getCatalogItem($marketplace_id, $asin);
echo $result->getPayload()->getAttributeSets()[0]->getTitle(); // Never Gonna Give You Up [Vinyl Single]

IAM用户

当你输入了用户ARN而不是角色ARN时,请使用此示例

<?php

require_once './vendor/autoload.php';

$options = [
    'refresh_token' => '', // Aztr|...
    'client_id' => '', // App ID from Seller Central, amzn1.sellerapps.app.cfbfac4a-......
    'client_secret' => '', // The corresponding Client Secret
    'region' => \AdolphYu\AmazonSellingPartnerAPI\SellingPartnerRegion::$EUROPE, // or NORTH_AMERICA / FAR_EAST
    'access_key' => '', // Access Key of AWS IAM User, for example AKIAABCDJKEHFJDS
    'secret_key' => '', // Secret Key of AWS IAM User
    'endpoint' => \AdolphYu\AmazonSellingPartnerAPI\SellingPartnerEndpoint::$EUROPE, // or NORTH_AMERICA / FAR_EAST
];
$accessToken = \AdolphYu\AmazonSellingPartnerAPI\SellingPartnerOAuth::getAccessTokenFromRefreshToken(
    $options['refresh_token'],
    $options['client_id'],
    $options['client_secret']
);
$config = \AdolphYu\AmazonSellingPartnerAPI\Configuration::getDefaultConfiguration();
$config->setHost($options['endpoint']);
$config->setAccessToken($accessToken);
$config->setAccessKey($options['access_key']);
$config->setSecretKey($options['secret_key']);
$config->setRegion($options['region']);
$apiInstance = new \AdolphYu\AmazonSellingPartnerAPI\Api\CatalogApi($config);
$marketplace_id = 'A1PA6795UKMFR9';
$asin = 'B0002ZFTJA';

$result = $apiInstance->getCatalogItem($marketplace_id, $asin);
echo $result->getPayload()->getAttributeSets()[0]->getTitle(); // Never Gonna Give You Up [Vinyl Single]

待办事项

  • 实现测试
  • 改进文档

欢迎功能请求和拉取请求!

备注

如果你在寻找一个完整的再定价和FBA退款解决方案,你可能想要尝试ClouSale.com

谢谢

感谢所有为这个包添加了PR并为之工作的人。