亚马逊MWS PHP-SDK的应用

##简单记录一下工作

使用composer下载亚马逊mws PHP-SDK到系统目录
composer require cpigroup/php-amazon-mws
在这里插入图片描述
将 amazon-config.default copy.php文件复制一份到你喜欢的文件夹内并去掉copy,因为lan,我这就在该目录下了.。
配置信息
按要求配置一下亚马逊账号信息,log.txt为接口日志文件,调用时可以看该日志查看返回情况和错误提示,比较方便。

接下来就是去使用对应接口获取数据,可以看下下面文档
亚马逊MWS接口文档
亚马逊接口测试
github地址

以下为我自己写的案例(GET_FBA_FULFILLMENT_REMOVAL_SHIPMENT_DETAIL_DATA 这是移除货件追踪详情类型,我这里就是根据这个类型获取报告详情,可以得到退货物流包裹信息)

/**
 * 获取指定报告类型ReportId
 * _GET_FBA_FULFILLMENT_REMOVAL_SHIPMENT_DETAIL_DATA_
 * @return array
 * @throws \Exception
 */
    public function getReportList(){
        try {
             $amz = new AmazonReportList("myStore");
             $amz->setReportTypes("_GET_FBA_FULFILLMENT_REMOVAL_SHIPMENT_DETAIL_DATA_");
             $amz->setUseToken();
             $amz->fetchReportList();
             //return $amz->getReportRequestId();
             return $amz->getList(0);
        } catch (Exception $ex) {
             echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage();
         }
     }

/**
 * 获取指定报告内容
 * @param string $reportId 指定报告ID
 * @return string
 * @throws \Exception
 */
    public function getReportContent($reportId){
        try {
            $amz = new AmazonReport("myStore");
            $amz->setReportId($reportId);
            $amz->fetchReport();
             //return $amz->saveReport('1.txt');
            return $amz->getRawReport();
        } catch (Exception $ex) {
            echo 'There was a problem with the Amazon library. Error: '.$ex->getMessage();
        }
     }

至此,就完成了亚马逊MWS的简单调用啦,原创不易,觉得有用点个关注呗!

猜你喜欢

转载自blog.csdn.net/Fillthepit/article/details/122106921
今日推荐