caponica/amazon-mws-complete
Composer 安装命令:
composer require caponica/amazon-mws-complete
包简介
Complete Amazon MWS PHP SDK, including all libraries
README 文档
README
This is an attempt to simplify access to the full range of MWS API calls from a single package.
Installation
Into a Symfony project
Add the reference into your composer.json :
"caponica/amazon-mws-complete": "dev-master"
Use in controller :
$client = new \MwsProductClient(/* args */);
Accessing the API
You can access each API directly if you want to:
use CaponicaAmazonMwsComplete\AmazonClient\MwsProductClient;
$mwsProductClientUsa = new MwsProductClient(
'YOUR_ACCESS_KEY',
'YOUR_SECRET_KEY',
'YOUR_APP_NAME',
'YOUR_APP_VERSION',
[ 'ServiceURL' => 'https://mws.amazonservices.com/Products/2011-10-01' ]
);
$mwsResponse = $mwsProductClientUsa->getCompetitivePricingForASIN([
'SellerId' => 'YOUR_SELLER_ID',
'MarketplaceId' => 'MARKETPLACE_ID',
'ASINList' => array('ASIN' => 'YOUR_ASIN_SEARCH'),
]);
// ... do something with the response ...
However, there is a better way! The MwsClientPool encapsulates all configuration shared between all different Amazon API services. So create that once (for each marketplace/seller combination you want to work with) and then retrieve 'ClientPacks' from the pool. A ClientPack includes configuration for a single Seller and Marketplace and these can be pre-filled into API calls by using the callXyz() methods (e.g. callGetCompetitivePricingForASIN() to call the API's getCompetitivePricingForASIN() method. This makes your API calls much cleaner:
use CaponicaAmazonMwsComplete\ClientPool\MwsClientPool;
use CaponicaAmazonMwsComplete\ClientPool\MwsClientPoolConfig;
$mwsClientPoolUsa = new MwsClientPool();
$mwsClientPoolUsa->setConfig([
'amazon_site' => MwsClientPoolConfig::SITE_US
'access_key' => 'YOUR_ACCESS_KEY'
'secret_key' => 'YOUR_SECRET_KEY'
'application_name' => 'YOUR_APP_NAME'
'application_version' => 'YOUR_APP_VERSION'
'seller_id' => 'YOUR_SELLER_ID'
]);
$productClientPackUsa = $mwsClientPoolUsa->getProductClientPack();
$mwsResponse = $productClientPackUsa->callGetCompetitivePricingForASIN('YOUR_ASIN_SEARCH');
There are also some helper methods that return objects (or arrays of objects) that are easier to work with than raw MWS responses:
/** @var MwsCompetitivePricing[] $compPricings */
$compPricings = $productClientPackUsa->retrieveCompetitivePricingForASIN('YOUR_ASIN_SEARCH');
foreach ($compPricings as $compPricing) {
echo $compPricing->asin;
}
MWSAuthToken
If you're using an MWSAuthToken then you can pass it in via the config:
$mwsClientPoolUsa->setConfig([
'auth_token' => 'YOUR_MWS_AUTH_TOKEN',
// ... other parameters ...
]);
Once set on the ClientPool, the token should be passed through to each Client and used in every API request.
REQUEST: Please feed back via github if this is the best way to set and use the MWSAuthToken, and if it all works as expected. I don't used this functionality myself so cannot test it properly.
Logging
The scripts no longer echo messages. Instead they use a Logger which you can define when you instantiate the ClientPool.
See https://github.com/php-fig/log and https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md for more details about setting up a Logger.
A basic Logger (which replicates the old echo behaviour), would look like this:
# EchoLogger.php
namespace Your\Path;
use Psr\Log\AbstractLogger;
class EchoLogger extends AbstractLogger
{
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
*
* @return void
*/
public function log($level, $message, array $context = array())
{
echo "$message\n";
}
}
You then simply pass an EchoLogger instance into the MwsClientPool constructor:
use CaponicaAmazonMwsComplete\ClientPool\MwsClientPool;
use Your\Path\EchoLogger;
$echoLogger = new EchoLogger();
$mwsClientPoolUsa = new MwsClientPool($echoLogger);
Working with reports
There are domain objects to help with reading reports. Not all reports have been implemented (by a long way!) but feel
free to implement any that you need to use and submit a PR. The basic structure is to have a ReportXyz class related
to the overall report and a ReportXyzRecord class relating to each record (row) in the report.
The basic usage would then look something like:
$reportFilePath = '/path/to/file.txt';
$reportType = MwsFeedAndReportClientPack::REPORT_FBA_INVENTORY_AFN;
$fileHandle = @fopen($reportFilePath, 'r');
if (!$fileHandle) {
return "Could not open $reportFilePath to read the report from";
}
try {
while (($lineFromFile = fgets($fileHandle)) !== false) {
if (!$checkedHeader) {
BaseMwsReport::validateHeaderRowForReportType($lineFromFile, $reportType);
$reportRecordClass = BaseMwsReport::convertReportTypeToReportRecordClass($reportType);
$checkedHeader = true;
continue;
}
$reportRecord = new $reportRecordClass($lineFromFile);
// do something with the record
echo "The SellerSku field value is" . $reportRecord->getSellerSku();
}
} catch (InvalidReportHeaderException $e) {
// Handle the exception, which is thrown if the header is not the expected format
} catch (InvalidReportRecordException $e) {
// Handle the exception, which is thrown if the row is not the expected format
}
Client library versions
| Library | API version | Library version |
|---|---|---|
| FBAInboundServiceMWS | 2010-10-01 | 2016-10-05 |
| FBAInventoryServiceMWS | 2010-10-01 | 2014-09-30 |
| FBAOutboundServiceMWS | 2010-10-01 | 2016-01-01 *1 |
| MarketplaceWebService | 2009-01-01 | 2016-09-21 |
| MarketplaceWebServiceOrders | 2013-09-01 | 2020-05-11 |
| MarketplaceWebServiceProducts | 2011-10-01 | 2017-03-22 |
| MarketplaceWebServiceSellers | 2011-07-01 | 2015-06-18 |
| MWSCartService | 2014-03-01 | 2015-06-18 ?? |
| MWSCustomerService | 2014-03-01 | 2015-06-18 ?? |
| MWSFinancesService | 2015-05-01 | 2020-02-21 |
| MWSMerchantFulfillmentService | 2015-06-01 | 2020-02-06 |
| MWSRecommendationsSectionService | 2013-04-01 | 2014-10-01 *1 |
| MWSSubscriptionsService | 2013-07-01 | 2013-11-01 *1 |
?? Amazon has deprecated these APIs, so they may be removed from this package in future.
*1 These libraries used to show later Library versions (dates) but this is what they say in the current Client.php files
The Off-Amazon Payments API is not currently included, since it is not directly linked to MWS activity. Off-Amazon Payments Technical Reference
caponica/amazon-mws-complete 适用场景与选型建议
caponica/amazon-mws-complete 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35.9k 次下载、GitHub Stars 达 55, 最近一次更新时间为 2016 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「amazon」 「mws」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 caponica/amazon-mws-complete 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 caponica/amazon-mws-complete 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 caponica/amazon-mws-complete 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package includes a script and fail2ban configuration that allows you to use fail2ban when utilizing AWS elastic load balancer (ELB) and an apache webserver.
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
Use Amazon's MWS web services with Laravel 5.x. Based on creacoon/amazon-mws-laravel package and modified to make it compatible with latest Laravel releases (+ bugfixes).
A simple Laravel 5/6/7/8 service provider for including the AWS SDK for PHP.
NinjaImg PHP SDK.
marketplaces-data-export is a library for generic data export from marketplaces
统计信息
- 总下载量: 35.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 55
- 点击次数: 6
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2016-04-17