rocket-labs/sellercenter-sdk-php

20170331 2016-06-08 15:17 UTC

This package is not auto-updated.

Last update: 2024-09-17 04:29:20 UTC


README

PHP 5.5 及以上版本。

Composer

您可以通过 Composer 安装该 SDK。运行以下命令

composer require rocket-labs/sellercenter-sdk-php

要使用 SDK 代码,请使用 Composer 的 自动加载

require_once('vendor/autoload.php');

2) 实现的方法

这些方法可以通过 RocketLabs\SellerCenterSdk\Endpoint\Endpoints 类访问

  • 订单端点 - Endpoints::order()
    • 获取订单
    • 获取订单
    • 获取文档
    • 获取订单项目
    • 将状态设置为已取消
    • 将状态设置为已打包
    • 将状态设置为准备发货

您可以使用 GenericRequest 调用所有其他方法,更多详细信息请参阅 此示例(用于 GET 方法)或 此示例(用于 POST 方法)。

3) 示例

要了解如何使用 SDK,请参阅 示例。要使示例工作,请更改 samples/config/config.php 中的 API 设置。您需要设置卖家中心 URL(仅支持 https),您的登录名和 API 密钥。

API 密钥 可以在您的卖家中心账户的“设置”>“管理用户”下找到。如果指定的用户还没有 API 密钥,可以通过单击相应的链接生成。

之后,您可以运行任何示例并查看实际请求的结果。

请注意,POST 请求可能会影响您的真实产品、订单等。确保示例中的 SKUs 或订单 ID 与您的卖家中心账户中的数据不冲突。

3.1) 通用示例

您可以通过使用 GenericRequest 类和核心实现访问每个 API 方法。

查看示例操作

cd samples
php ./genericGetter.php

3.1) 端点示例

对于最重要的 API 端点,SDK 提供了简化 API 使用的代理。请参阅 端点示例

以下代码描述了如何使用端点实现的模式

<?php
    require __DIR__ . '/vendor/autoload.php';

    use RocketLabs\SellerCenterSdk\Core\Client;
    use RocketLabs\SellerCenterSdk\Core\Configuration;
    use RocketLabs\SellerCenterSdk\Endpoint\Endpoints;

    // create client instance with your credetials
    $client = Client::create(new Configuration(SC_API_URL, SC_API_USER, SC_API_KEY));

    // get response for a certain api call with fluent interface:
    // Endpoints - name of endpoint - api method to call - call($client)
    $response = Endpoints::order()->getOrder(12)->call($client);

    // Or, for some complex methods, RequestBuilders can be used,
    // In such cases API command will have following structure:
    // Endpoints - name of endpoint - api method to call - some builder's setters - build - call($client)
    $response = Endpoints::order()->getOrders()->setSorting('created_at', 'ASC')->setLimit(12)->build()->call($client);

查看示例操作

打开示例文件。例如 samples/endpoint/order/getOrder.php,并将变量 $orderId 中的订单 ID 更改为您的卖家订单 ID。然后在控制台中运行它

php ./samples/endpoint/order/getOrder.php