ixoplan/ixoplan-backend-sdk

后端Ixoplan API的客户端库

v1.0.3 2021-04-29 11:24 UTC

This package is auto-updated.

Last update: 2024-08-29 05:37:24 UTC


README

适用于Ixoplan后端API的PHP SDK

安装

简单地将ixoplan/ixoplan-backend-sdk和ixoplan/ixoplan-sdk-http(例如ixoplan/ixoplan-sdk-http-guzzle)提供者添加到您的composer.json中,例如

{
    "name": "myvendor/myproject",
    "description": "Using ixoplan-backend-sdk",
    "require": {
        "ixoplan/ixoplan-backend-sdk": "*"
        "ixoplan/ixoplan-sdk-http-guzzle": "*"
    }
}

使用

实例化客户端

客户端是为不同的传输层设计的。它需要一个RequestClient接口(例如HTTPRequestClient)来实际与Ixoplan通信。

use Ixolit\Dislo\Backend\Client;
use Ixolit\Dislo\HTTP\Guzzle\GuzzleHTTPClientAdapter;
use Ixolit\Dislo\Request\HTTPRequestClient;

$httpAdapter = new GuzzleHTTPClientAdapter();

$httpClient = new HTTPRequestClient(
    $httpAdapter,
    $host,
    $apiKey,
    $apiSecret
);

$apiClient = new Client($httpClient);

优惠券

通过多个请求检索所有优惠券列表,每个请求限制为十项

$apiClient = new \Ixolit\Dislo\Backend\Client($httpClient);

$limit = 10;
$offset = 0;
do {
    $couponListResponse = $apiClient->couponList($limit, $offset);
    foreach ($couponListResponse->getCoupons() as $coupon) {
        echo $coupon->getCode();
        $offset++;
    }
} while ($offset < $couponListResponse->getTotalCount());