commentsold / commentsold-sdk-php
CommentSold SDK
v0.4.0
2024-05-16 20:41 UTC
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.2
Requires (Dev)
- laravel/pint: 1.10.5
- mockery/mockery: ^1.4.4
- phpstan/phpstan: ^1.9
- phpstan/phpstan-mockery: ^1.1
- phpunit/phpunit: ^9.5.10
This package is auto-updated.
Last update: 2024-09-16 21:31:23 UTC
README
此 SDK 可以通过它们的 RESTful API 与 CommentSold 集成。API 文档可以在 https://docs.commentsold.com/api/openapi 找到。
需求
PHP 8.1 及以上版本。
Composer
您可以通过 Composer 安装绑定。运行以下命令
composer require commentsold/commentsold-sdk-php
入门指南
在使用 SDK 之前,您需要从 CommentSold 获取 合作伙伴 ID
和 私钥
。
API 有两个主要部分。一个是全局合作伙伴函数,另一个是特定于商店的函数。SDK 被划分为对应这两个范围。两者都需要自己的令牌,所以请注意在哪里使用哪个。
无论是哪个,第一步都是获取令牌。令牌有效期为 24 小时,因此您应将其保存到本地并重复使用,以减少不必要的 API 调用。
示例全局范围 SDK 使用
require __DIR__.'/vendor/autoload.php'; $environment = new CommentSold\Resources\TokenizerEnvironment(CommentSold\Enums\Environment::PRODUCTION); $tokenizer = new CommentSold\Tokenizer('my_private_key', 'my_partner_id', $environment); $token = $tokenizer->getPartnerToken(); $environment = new CommentSold\Resources\ClientEnvironment(CommentSold\Enums\Environment::PRODUCTION); $client = new CommentSold\GlobalClient($token, $environment); $api = new CommentSold\Services\AccountApi($client); $request = new CommentSold\Resources\Request\Account\GetOauthUrlRequest(['all'], 'https://my-return-url.com/oauth'); $oauthUrl = $api->getOauthUrl($request);
示例商店范围 SDK 使用
require __DIR__.'/vendor/autoload.php'; $environment = new CommentSold\Resources\TokenizerEnvironment(CommentSold\Enums\Environment::PRODUCTION); $tokenizer = new CommentSold\Tokenizer('my_private_key', 'my_partner_id', $environment); $token = $tokenizer->getShopToken('my-shop'); $environment = new CommentSold\Resources\ClientEnvironment(CommentSold\Enums\Environment::PRODUCTION); $client = new CommentSold\ShopClient('my-shop', $token, $environment); $api = new CommentSold\Services\ProductApi($client); $request = new CommentSold\Resources\Request\Product\GetProductsRequest(); // raw response object $response = $api->getProducts($request); // the response data object (in this case an array of product objects) $products = $response->getData(); // if you would rather work with the response as an array $productsAsArray = $response->getData()->toArray(); // the pagination detail object $pagination = $response->getPagination(); // the total number of results $totalCount = $pagination->total;