chunckchill / amazon-sp-api-php
v3.0.0
2021-05-30 04:20 UTC
Requires
- php: >=7.3
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^6.2|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: v2.17.3
- phpunit/phpunit: ^4.8
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ~2.6
README
这是为新的 Amazon Selling Partner API 编写的 PHP API 绑定。
这个库基于 swagger-codegen 的输出和 Amazon 提供的 OpenAPI 文件,并由贡献者进行了修改。
这个包的目的是通过简单的 composer 包,提供一个简单的方式来入门 Amazon Selling Partner API。
要求
- PHP >= 7.3
- cURL 扩展
- JSON 扩展
- MBString 扩展
安装
只需通过 composer 需求此包
composer require clousale/amazon-sp-api-php
详细文档
您可以在 docs/Api 目录 中找到此 PHP 库的详细文档(请注意:命名空间和其他类可能已更改)
您可以在 官方 Amazon 开发者网站 上找到有关 Amazon Selling Partner 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' => \ClouSale\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' => \ClouSale\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 = \ClouSale\AmazonSellingPartnerAPI\SellingPartnerOAuth::getAccessTokenFromRefreshToken( $options['refresh_token'], $options['client_id'], $options['client_secret'] ); $assumedRole = \ClouSale\AmazonSellingPartnerAPI\AssumeRole::assume( $options['region'], $options['access_key'], $options['secret_key'], $options['role_arn'], ); $config = \ClouSale\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 \ClouSale\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' => \ClouSale\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' => \ClouSale\AmazonSellingPartnerAPI\SellingPartnerEndpoint::$EUROPE, // or NORTH_AMERICA / FAR_EAST ]; $accessToken = \ClouSale\AmazonSellingPartnerAPI\SellingPartnerOAuth::getAccessTokenFromRefreshToken( $options['refresh_token'], $options['client_id'], $options['client_secret'] ); $config = \ClouSale\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 \ClouSale\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 和工作的人。