commentsold/commentsold-sdk-php
最新稳定版本:v0.4.0
Composer 安装命令:
composer create-project commentsold/commentsold-sdk-php
包简介
CommentSold SDK
关键字:
README 文档
README
This SDK can be used to integrate with CommentSold via their RESTful API. Documentation for the API can be found at https://docs.commentsold.com/api/openapi
Requirements
PHP 8.1 and later.
Composer
You can install the bindings via Composer. Run the following command:
composer require commentsold/commentsold-sdk-php
Getting Started
Before using the SDK you will need to get a Partner ID and Private Key from CommentSold.
There are two main sections of the API. There are the global partner functions and then the shop specific functions. The SDK is broken up to correspond to those two scopes. Both require their own token, so be mindful of which you are using where.
The first step for either is to obtain a token. Tokens are valid for 24 hours, so you should save them locally and reuse them in order to reduce unnecessary API calls.
Example global scope SDK usage:
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);
Example shop scope SDK usage:
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;
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-03