我的编程空间,编程开发者的网络收藏夹
学习永远不晚

亚马逊SP-API自发货标记发货对接

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

亚马逊SP-API自发货标记发货对接

基本思路:

拉取sdk

 createFeedDocument -> uploadFeedDocument -> createFeed

 getOrder查看订单状态

实现过程:

github找到一个比较好用的sdk

进入项目目录,运行 

composer require double-break/spapi-php

  执行流程,createFeedDocument -> uploadFeedDocument -> createFeed

直接上代码:

    public static function shipped($get, $post) {        $brushData = empty($post['data']) ? array() : json_decode(stripslashes($post['data']), true);        $token = empty($brushData['token']) ? [] : $brushData['token'];        $xml = empty($brushData['xml']) ? '' : $brushData['xml'];        $host = empty($brushData['host']) ? '' : $brushData['host'];        if (empty($token)) {            $result = array(                'state' => '301',                'info' => '缺少必要参数,token'            );        }        if (empty($brushData['platformOrder'])) {            $result = array(                'state' => '302',                'info' => '缺少必要参数,platformOrder'            );        }        if (empty($host)) {            $result = array(                'state' => '303',                'info' => '缺少必要参数,host'            );        }        if (empty($token['spRefreshToken']) || empty($token['spClientId']) || empty($token['spClientSecret']) ||            empty($token['spAccessKeyId']) || empty($token['spSecretKey']) || empty($token['spRoleArn']) || empty($token['spRegion'])) {            $result = array(                'state' => '304',                'info' => 'token缺少必要参数,spRefreshToken/spClientId/spClientSecret/spAccessKeyId/spSecretKey/spRoleArn/spRegion'            );        }        if (empty($xml)) {            $result = array(                'state' => '305',                'info' => '标记内容为空'            );        }        if (!empty($result)) return $result;            include ROOT_DIR . '/vendor/autoload.php';                $config = [            'http' => [                'verify' => true,                'debug' => false            ],            'refresh_token' => $token['spRefreshToken'],            'client_id' => $token['spClientId'],            'client_secret' => $token['spClientSecret'],            //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' => $token['spAccessKeyId'],            'secret_key' => $token['spSecretKey'],            'role_arn' => $token['spRoleArn'] ,            //API: Actual configuration related to the SP API :)            'region' => $token['spRegion'],            'host' => $host        ];        //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, $token['account']);        $cred = $credentials->getCredentials();        // content type of the feed data to be uploaded.        $contentType = 'text/xml; charset=UTF-8';        // create feed document        $feedClient = new \DoubleBreak\Spapi\Api\Feeds($cred, $config);        $response = $feedClient->createFeedDocument(["contentType" => $contentType]);        $payload = $response;        $result = (new \DoubleBreak\Spapi\Helper\Feeder())->uploadFeedDocument($payload,$contentType,$xml);        if ($result === 'Done') {            $body = [                'feedType' => 'POST_ORDER_FULFILLMENT_DATA',                "marketplaceIds" => [                    $token['marketplace_id']                ],                "inputFeedDocumentId" => $payload['feedDocumentId']            ];            $res = $feedClient->createFeed($body);            if (!empty($res['feedId'])) {                return array('state' => 200, 'info' => $res);            }        } else {            return array('state' => 30, 'info' => 'xml文件上传失败');        }    }

下一次标记时查询订单状态,若订单状态已经变成Shipped,则表示上一次标记成功,不再进行标记,否则重试。

查询订单方法:

    public static function getOrder($get, $post) {        $brushData = empty($post['data']) ? array() : json_decode(stripslashes($post['data']), true);        $token = empty($brushData['token']) ? [] : $brushData['token'];        $host = empty($brushData['host']) ? '' : $brushData['host'];        if (empty($token)) {            $result = array(                'state' => '301',                'info' => '缺少必要参数,token'            );        }        if (empty($brushData['platformOrder'])) {            $result = array(                'state' => '302',                'info' => '缺少必要参数,platformOrder'            );        }        if (empty($host)) {            $result = array(                'state' => '303',                'info' => '缺少必要参数,host'            );        }        if (empty($token['spRefreshToken']) || empty($token['spClientId']) || empty($token['spClientSecret']) ||            empty($token['spAccessKeyId']) || empty($token['spSecretKey']) || empty($token['spRoleArn']) || empty($token['spRegion'])) {            $result = array(                'state' => '304',                'info' => 'token缺少必要参数,spRefreshToken/spClientId/spClientSecret/spAccessKeyId/spSecretKey/spRoleArn/spRegion'            );        }        if (!empty($result)) return $result;        include ROOT_DIR . '/vendor/autoload.php';                $config = [            'http' => [                'verify' => true,                'debug' => false            ],            'refresh_token' => $token['spRefreshToken'],            'client_id' => $token['spClientId'],            'client_secret' => $token['spClientSecret'],            //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' => $token['spAccessKeyId'],            'secret_key' => $token['spSecretKey'],            'role_arn' => $token['spRoleArn'] ,            //API: Actual configuration related to the SP API :)            'region' => $token['spRegion'],            'host' => $host        ];        //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, $token['account']);        $cred = $credentials->getCredentials();        $orderClient = new DoubleBreak\Spapi\Api\Orders($cred, $config);        $res = $orderClient->getOrder($brushData['platformOrder']);        $result = [            'state' => 200,            'info' => $res        ];        return $result;    }

实现过程就是这么简单,希望能帮到有需要的人。

附加参数格式:

shipped方法传参的token参数:

{    "account":"xxx",    "merchant_id":"xxx",    "marketplace_id":"xxx",    "shorthand_code":"DE",    "accountId":"xxx",    "authorizeState":1,    "expireState":null,    "spAccessKeyId":"xxx",    "spClientId":"xxx",    "spClientSecret":"a9059aff31f3fab2a96ed4fb851a0f9bfb04e859d2483266ca01c7781659b84f",    "spRefreshToken":"xxx",    "spRegion":"eu-west-1",    "spRoleArn":"arn:aws:iam::429211419775:role\/PlsSellingPartnerAPIRole",    "spSecretKey":"xxx"}

xml模版:

                   
1.02
OrderFulfillment true 1 305-0942001-3129934 2022-08-29T03:15:59.000Z GLS 103389001671 33520471730635 1

官方文档的流程 Feeds API v2021-06-30 Use Case Guide

sdk需要修改或替换的地方:
4.1》vendor/guzzlehttp/guzzle/class="lazy" data-src/functions.php 默认linux系统,可以改下同时支持window和linux运行

function debug_resource($value = null){    if (is_resource($value)) {        return $value;    } elseif (defined('STDOUT')) {        return STDOUT;    }    $agent = $_SERVER['HTTP_USER_AGENT'];    if (strpos($agent, "Window") === false) {        return fopen('php://output', 'w');    } else {        return fopen('php://stdout','w');    }}

2> vendor/double-break/spapi-php/class="lazy" data-src/Credentials.php
vendor/double-break/spapi-php/class="lazy" data-src/SimpleTokenStorage.php

两个文件适当修改以便支持多账号使用(原SDK只使用单独一个帐号使用), 我的方式是将写入和读取aws-tokens文件写成多维数组,用账号名为key值。

附加api返回格式:

createFeed请求的数据:
{"feedType":"POST_ORDER_FULFILLMENT_DATA","marketplaceIds":["ATVPDKIKX0DER"],"inputFeedDocumentId":"amzn1.tortuga.3.d1dbeb92-b475-46d4-946c-491f46724dc0.TJG1LXE67GBUR"}

createFeed返回的数据:
Array ( [feedId] => 204332019186 )

getFeed返回的结果:
Array ( [processingEndTime] => 2022-07-13T10:26:53+00:00 [processingStatus] => DONE [marketplaceIds] => Array ( [0] => ATVPDKIKX0DER ) [feedId] => 204332019186 [feedType] => POST_ORDER_FULFILLMENT_DATA [createdTime] => 2022-07-13T10:26:13+00:00 [processingStartTime] => 2022-07-13T10:26:28+00:00 [resultFeedDocumentId] => amzn1.tortuga.3.9f6c8425-58a5-4031-851c-65142aaafa75.T3JQMGCAVP75PJ )


4. getFeedDocument返回:
Array ( [feedDocumentId] => amzn1.tortuga.3.21b9cb2c-f796-4d59-b37a-2b7b60121f23.TFG3R55E0799T [url] => https://tortuga-prod-na.s3-external-1.amazonaws.com/%2FNinetyDays/amzn1.tortuga.3.2e5b624c-93ee-475b-baee-5754483f3a5c.T2YQZUNM2Y0QBM?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20220713T102852Z&X-Amz-SignedHeaders=host&X-Amz-Expires=300&X-Amz-Credential=AKIA5U6MO6RAJ4ZS7WYA%2F20220713%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=4e978cd0907b625e21c6b05c1b53cb3d912d3ed34244561d8fd73991147ce84a )

附加站点节点url配置:

array(        'CA' => array('region' => 'us-east-1','marketplace_id' => 'A2EUQ1WTGCTBG2','service_url_report' => 'https://sellingpartnerapi-na.amazon.com'), //加拿大        'US' => array('region' => 'us-east-1','marketplace_id' => 'ATVPDKIKX0DER','service_url_report' => 'https://sellingpartnerapi-na.amazon.com'), //美国        'MX' => array('region' => 'us-east-1','marketplace_id' => 'A1AM78C64UM0Y8','service_url_report' => 'https://sellingpartnerapi-na.amazon.com'), //墨西哥        'BR' => array('region' => 'us-east-1','marketplace_id' => 'A2Q3Y263D00KWC','service_url_report' => 'https://sellingpartnerapi-na.amazon.com'), //巴西        'ES' => array('region' => 'eu-west-1','marketplace_id' => 'A1RKKUPIHCS9HS','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //西班牙        'UK' => array('region' => 'eu-west-1','marketplace_id' => 'A1F83G8C2ARO7P','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //英国        'GB' => array('region' => 'eu-west-1','marketplace_id' => 'A1F83G8C2ARO7P','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //英国        'FR' => array('region' => 'eu-west-1','marketplace_id' => 'A13V1IB3VIYZZH','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //法国        'NL' => array('region' => 'eu-west-1','marketplace_id' => 'A1805IZSGTT6HS','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //荷兰        'DE' => array('region' => 'eu-west-1','marketplace_id' => 'A1PA6795UKMFR9','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //德国        'IT' => array('region' => 'eu-west-1','marketplace_id' => 'APJ6JRA9NG5V4','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //意大利        'SE' => array('region' => 'eu-west-1','marketplace_id' => 'A2NODRKZP88ZB9','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //瑞典        'PL' => array('region' => 'eu-west-1','marketplace_id' => 'A1C3SOZRARQ6R3','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //波兰        'EG' => array('region' => 'eu-west-1','marketplace_id' => 'ARBP9OOSHTCHU','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //埃及        'TR' => array('region' => 'eu-west-1','marketplace_id' => 'A33AVAJ2PDY3EV','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //土耳其        'SA' => array('region' => 'eu-west-1','marketplace_id' => 'A17E79C6D8DWNP','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //沙特阿拉伯        'AE' => array('region' => 'eu-west-1','marketplace_id' => 'A2VIGQ35RCS4UG','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //阿拉伯联合酋长国        'IN' => array('region' => 'eu-west-1','marketplace_id' => 'A21TJRUUN4KGV','service_url_report' => 'https://sellingpartnerapi-eu.amazon.com'), //印度        'SG' => array('region' => 'us-west-2','marketplace_id' => 'A19VAU5U5O7RUS','service_url_report' => 'https://sellingpartnerapi-fe.amazon.com'), //新加坡        'AU' => array('region' => 'us-west-2','marketplace_id' => 'A39IBJ37TRP1C6','service_url_report' => 'https://sellingpartnerapi-fe.amazon.com'), //澳大利亚        'JP' => array('region' => 'us-west-2','marketplace_id' => 'A1VC38T7YXB528','service_url_report' => 'https://sellingpartnerapi-fe.amazon.com') //日本    ),

来源地址:https://blog.csdn.net/Happy1314515/article/details/126580578

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

亚马逊SP-API自发货标记发货对接

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

亚马逊自发货中转仓

在亚马逊的物流服务提供商中,有些是独立的第三方物流公司,它们提供亚马逊物流服务,并负责处理所有的订单交付和库存管理。还有一些是亚马逊的自有物流服务提供商,它们拥有自己的仓库和运输网络,可以更好地控制物流服务和订单交付的质量。总之,亚马逊自发货中转仓是亚马逊为自有品牌卖家提供的一种物流解决方案,它们可以帮助亚马逊更好地管理和交付产品。
2023-10-27

亚马逊自养号发货怎么接收

亚马逊自营号发货的接收方式有多种,以下是其中几种常见的方式:亚马逊物流:如果你选择使用亚马逊物流服务,亚马逊将会负责将你的商品存储在他们的仓库中,并在你的订单生成后进行包装和发货。你可以在亚马逊卖家中心的“库存”页面中查看你的库存情况和订单状态。自行发货:如果你选择自行发货,你需要在订单生成后及时将商品发出,并在亚马逊卖家中心中更新订单状态和提供物流信息。你可以选择使用自己的物流渠道或第三方物流服...
2023-10-27

亚马逊店铺odr自发货超过1%怎么办

确认订单缺陷率:首先,确认您的订单缺陷率是否达到1%。如果是,则可能需要考虑提高产品质量、缩短交货时间或减少缺货频率等措施。检查库存:一旦您确定有足够的产品供应,就可以检查库存中是否存在缺货情况。如果库存充足,可以考虑将产品下架并重新安排发货时间。提高客户服务:通过提高客户服务水平,以及回复客户的邮件和评论,可以让客户感到满意并减少客户投诉的概率。重新评估销售策略:如果您的销售策略已经调整,那么需要...
2023-10-27

编程热搜

  • Python 学习之路 - Python
    一、安装Python34Windows在Python官网(https://www.python.org/downloads/)下载安装包并安装。Python的默认安装路径是:C:\Python34配置环境变量:【右键计算机】--》【属性】-
    Python 学习之路 - Python
  • chatgpt的中文全称是什么
    chatgpt的中文全称是生成型预训练变换模型。ChatGPT是什么ChatGPT是美国人工智能研究实验室OpenAI开发的一种全新聊天机器人模型,它能够通过学习和理解人类的语言来进行对话,还能根据聊天的上下文进行互动,并协助人类完成一系列
    chatgpt的中文全称是什么
  • C/C++中extern函数使用详解
  • C/C++可变参数的使用
    可变参数的使用方法远远不止以下几种,不过在C,C++中使用可变参数时要小心,在使用printf()等函数时传入的参数个数一定不能比前面的格式化字符串中的’%’符号个数少,否则会产生访问越界,运气不好的话还会导致程序崩溃
    C/C++可变参数的使用
  • css样式文件该放在哪里
  • php中数组下标必须是连续的吗
  • Python 3 教程
    Python 3 教程 Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。 Python
    Python 3 教程
  • Python pip包管理
    一、前言    在Python中, 安装第三方模块是通过 setuptools 这个工具完成的。 Python有两个封装了 setuptools的包管理工具: easy_install  和  pip , 目前官方推荐使用 pip。    
    Python pip包管理
  • ubuntu如何重新编译内核
  • 改善Java代码之慎用java动态编译

目录