亚马逊ERP开发之 Seller partner api PHP版本
推荐一个SPAPI PHP API套件,这个套件解决了签名,获取/更新TOKEN等功能,只需要稍加改动,就可以做出一个支持管理多个账户的亚马逊ERP。安装环境必须要PHP7.3以上版本,支持composer,但是,在使用之前,最好先看一遍 Amazon SP API 文档。
GITHUB: https://github.com/double-break/spapi-php
安装方法:
composer require double-break/spapi-php
更新方法:
composer update double-break/spapi-php
使用方法:建议在命令行模式下运行,不建议用http请求多方式开发,如果不知道怎么用命令行运行PHP,建议多学习。
<?php
include __DIR__ . '/vendor/autoload.php';
/** The Setup **/
$config = [
//Guzzle configuration
'http' => [
'verify' => false, //<--- NOT SAFE FOR PRODUCTION
'debug' => true //<--- NOT SAFE FOR PRODUCTION
],
//LWA: Keys needed to obtain access token from Login With Amazon Service
'refresh_token' => '<YOUR-REFRESH-TOKEN>',
'client_id' => '<CLINET-ID-IN-SELLER-CONSOLE>',
'client_secret' => '<CLIENT_SECRET>',
//STS: Keys of the IAM role which are needed to generate Secure Session
// (a.k.a Secure token) for accessing and assuming the IAM role
'access_key' => '<STS-ACCESS_KEY>',
'secret_key' => '<STS-SECRET-KEY>',
'role_arn' => '<ROLE-ARN>' ,
//API: Actual configuration related to the SP API :)
'region' => 'eu-west-1',
'host' => 'sellingpartnerapi-eu.amazon.com'
];
//Create token storage which will store the temporary tokens
$tokenStorage = new DoubleBreak\Spapi\SimpleTokenStorage('./aws-tokens');
//Create the request signer which will be automatically used to sign all of the
//requests to the API
$signer = new DoubleBreak\Spapi\Signer();
//Create Credentials service and call getCredentials() to obtain
//all the tokens needed under the hood
$credentials = new DoubleBreak\Spapi\Credentials($tokenStorage, $signer, $config);
$cred = $credentials->getCredentials();
/** The application logic implementation **/
//Create SP API Catalog client and execute one ot its REST methods.
$catalogClient = new DoubleBreak\Spapi\Api\CatalogItems($cred, $config);
//Check the catalog info for B074Z9QH5F ASIN
$result = $catalogClient->getCatalogItem('B074Z9QH5F', [
'MarketplaceId' => 'A1PA6795UKMFR9',
])['payload'];
print_r($result);
