作者 竞泽

init

/vendor/
composer.lock
.idea
\ No newline at end of file
... ...
# 配置gitlab仓库
```composer
"repositories": {
"lackoxygen/top-warehouse": {
"type": "git",
"url": "http://47.107.73.162:8099/lackoxygen/tiktok_shop.git"
},
}
```
# 安装
```
composer require lackoxygen/tiktok_shop
```
# 配置文件
```
//路径 config/tiktok.shop.php
[
'app_key' => env('TIKTOK_APP_KEY', '7044793792079201799'),
'app_secret' => env('TIKTOK_APP_SECRET', '303fe8fc-5986-4be3-a210-4c4c217880a1'),
'enable_mock' => env('TIKTOK_ENABLE_MOCK', false),
'base_uri' => env('TIKTOK_BASE_URI', 'https://openapi-sandbox.jinritemai.com'),
'timeout' => env('TIKTOK_TIMEOUT', 30),
];
```
# 使用方法
1. 门面调用
```php
use Lackoxygen\TiktokShop\Facade\TiktokShop;
$obj = TiktokShop::alliance();
```
2. 直接使用
```php
use Lackoxygen\TiktokShop\TiktokShop;
$config = Lackoxygen\TiktokShop\TiktokShop::newConfig(config('some'));
$obj = new Lackoxygen\TiktokShop\TiktokShop($config);
```
3.接口判断请求成功
```php
use Lackoxygen\TiktokShop\Facade\TiktokShop;
$resultSet = TiktokShop::alliance()->materialsProductsSearch([]);
if ($resultSet->isSuccess()){
exit(0)
}
exit(1)
```
4.签名(只支持md5)
```php
use Lackoxygen\TiktokShop\Facade\TiktokShop;
$resultSet = TiktokShop::verify()->md5('some', 'body');
if ($resultSet->isSuccess()){
exit(0)
}
exit(1)
```
5.超时异常
```php
use Lackoxygen\TiktokShop\Facade\TiktokShop;
try {
$resultSet = TiktokShop::alliance()->materialsProductsSearch([]);
}catch (\Lackoxygen\TiktokShop\Exception\RetryException $retryException){
exit(0)
}
exit(1)
```
... ...
{
"name": "lackoxygen/tiktok_shop",
"type": "library",
"description": "抖店php-sdk",
"autoload": {
"psr-4": {
"Lackoxygen\\TiktokShop\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Lackoxygen\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "ojz",
"email": "jingzeou@outlook.com"
}
],
"require": {
"php": ">=7.4",
"illuminate/support": "^5.8"
},
"require-dev": {
"phpunit/phpunit": "^9.5.10"
},
"laravel": {
"providers": [
"Lackoxygen\\TiktokShop\\TiktokShopProvider"
]
}
}
... ...
<?php
return [
'app_key' => env('TIKTOK_APP_KEY', ''),
'app_secret' => env('TIKTOK_APP_SECRET', ''),
'enable_mock' => env('TIKTOK_ENABLE_MOCK', false),
'base_uri' => env('TIKTOK_BASE_URI', 'https://openapi-sandbox.jinritemai.com'),
'timeout' => env('TIKTOK_TIMEOUT', 30),
];
... ...
<?php
namespace Lackoxygen\TiktokShop\Attribute;
class Config
{
private string $appKey = '';
private string $appSecret = '';
private bool $enableMock = false;
private string $baseUri = '';
private string $accessToken = '';
private float $timeout;
public function __construct(
string $appKey = '',
string $appSecret = '',
string $baseUri = '',
float $timeout = 30.0,
bool $enableMock = false
) {
$this->appKey = $appKey;
$this->appSecret = $appSecret;
$this->baseUri = $baseUri;
$this->timeout = $timeout;
$this->enableMock = $enableMock;
}
/**
* @param mixed $appKey
*/
public function setAppKey(string $appKey): void
{
$this->appKey = $appKey;
}
/**
* @return string
*/
public function getAppKey(): ?string
{
return $this->appKey;
}
/**
* @param mixed $appSecret
*/
public function setAppSecret($appSecret): void
{
$this->appSecret = $appSecret;
}
/**
* @return string
*/
public function getAppSecret(): ?string
{
return $this->appSecret;
}
/**
* @param bool $enableMock
*/
public function setEnableMock(bool $enableMock): void
{
$this->enableMock = $enableMock;
}
/**
* @return bool
*/
public function isEnableMock(): bool
{
return $this->enableMock;
}
/**
* @param string $baseUri
*/
public function setBaseUri(string $baseUri): void
{
$this->baseUri = $baseUri;
}
/**
* @return string
*/
public function getBaseUri(): string
{
return $this->baseUri;
}
/**
* @param string $accessToken
*/
public function setAccessToken(string $accessToken): void
{
$this->accessToken = $accessToken;
}
/**
* @return string
*/
public function getAccessToken(): string
{
return $this->accessToken;
}
/**
* @param float $timeout
*/
public function setTimeout(float $timeout): void
{
$this->timeout = $timeout;
}
/**
* @return float
*/
public function getTimeout(): float
{
return $this->timeout;
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Attribute;
class Request
{
private string $service = '';
private string $timestamp = '';
private string $v = '2';
private string $method = 'GET';
private array $params = [];
protected string $path = '';
private bool $signature = true;
private Config $config;
/**
* @param mixed $config
*/
public function setConfig(Config $config): void
{
$this->config = $config;
}
/**
* @return mixed
*/
public function getConfig(): Config
{
return $this->config;
}
/**
* @return string
*/
public function getService(): string
{
return $this->service;
}
/**
* @param mixed $service
*/
public function setService($service): void
{
$this->service = $service;
}
/**
* @return string
*/
public function getTimestamp(): string
{
return $this->timestamp ?: date('Y-m-d H:i:s');
}
/**
* @param mixed $timestamp
*/
public function setTimestamp($timestamp): void
{
$this->timestamp = $timestamp;
}
/**
* @return string
*/
public function getV(): string
{
return $this->v;
}
/**
* @param mixed $v
*/
public function setV($v): void
{
$this->v = $v;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
* @param mixed $method
*/
public function setMethod($method): void
{
$this->method = $method;
}
/**
* @return array
*/
public function getParams(): array
{
return $this->params;
}
/**
* @param mixed $params
*/
public function setParams(array $params): void
{
$this->params = $params;
}
/**
* @return bool
*/
public function isSignature(): bool
{
return $this->signature;
}
/**
* @param bool $signature
*/
public function setSignature(bool $signature): void
{
$this->signature = $signature;
}
/**
* @return string
*/
public function getPath(): string
{
return $this->path;
}
/**
* @param string $path
*/
public function setPath(string $path): void
{
$this->path = $path;
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Exception;
class ClientException extends \Exception
{
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Exception;
class MockException extends \Exception
{
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Exception;
class RetryException extends ClientException
{
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Facade;
use Illuminate\Support\Facades\Facade;
use Lackoxygen\TiktokShop\Passage\Alliance\Alliance;
use Lackoxygen\TiktokShop\Passage\Authorize;
use Lackoxygen\TiktokShop\Passage\Order\OrderInterface;
use Lackoxygen\TiktokShop\Passage\Product\ProductInterface;
use Lackoxygen\TiktokShop\Passage\Shop\ShopInterface;
use Lackoxygen\TiktokShop\Passage\Verify;
/**
* @method static OrderInterface order()
* @method static ShopInterface shop()
* @method static ProductInterface product()
* @method static Authorize authorize()
* @method static Verify verify()
* @method static Alliance alliance()
*/
class TiktokShop extends Facade
{
/**
* @return string
*/
protected static function getFacadeAccessor(): string
{
return \Lackoxygen\TiktokShop\TiktokShop::class;
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Mock;
use Lackoxygen\TiktokShop\Util\Preg;
class Annotation
{
public function method($class, $method): array
{
$ref = new \ReflectionClass($class);
$interfaces = $ref->getInterfaces();
/**
* @var \ReflectionClass $interface
*/
$interface = array_shift($interfaces);
if (is_null($interface)) {
return [];
}
$method = $interface->getMethod($method);
$docs = $method->getDocComment();
$docsItems = Preg::annotation($docs);
if (!$docsItems) {
return [];
}
$docsArray = [];
foreach ($docsItems as $item) {
$line = Preg::mergeSpaces($item);
$lineParts = explode(' ', $line);
$key = array_shift($lineParts);
$docsArray[$key] = $lineParts;
}
return $docsArray;
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Mock;
use App\Pkgs\TiktokShop\Attribute\Config;
use App\Pkgs\TiktokShop\Attribute\Request;
use App\Pkgs\TiktokShop\Exception\ClientException;
use App\Pkgs\TiktokShop\Exception\MockException;
use App\Pkgs\TiktokShop\Utils\Json;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\RequestOptions;
use Illuminate\Support\Arr;
class Mock
{
protected string $passage, $method;
protected Annotation $annotation;
public function __construct(string $passage, string $method)
{
$this->passage = $passage;
$this->method = $method;
$this->annotation = new Annotation;
}
/**
* @param string $url
* @return Response
* @throws ClientException
* @throws MockException
*/
protected function request(string $url): Response
{
if (empty($url)) {
throw new MockException('Unable to simulate data, no document address provided');
}
$pathInfo = parse_url($url, PHP_URL_PATH);
$pathParts = explode('/', $pathInfo);
$articleId = end($pathParts);
$client = new Client([
'base_uri' => 'https://op.jinritemai.com'
]);
try {
$response = $client->get('doc/external/open/queryDocArticleDetail', [
RequestOptions::QUERY => [
'articleId' => $articleId,
'onlyView' => false
]
]);
} catch (GuzzleException $e) {
throw new ClientException($e);
}
$content = $response->getBody()->getContents();
$array = Json::unmarshal($content);
if (0 !== $array['code']) {
throw new MockException(sprintf('Abnormal response error, %s', $array['message']));
}
$articleContent = Json::unmarshal($array['data']['article']['content']);
return new Response(
200,
['server' => 'mock', 'version' => $array['data']['article']['info']['version']],
new Stream($articleContent['demo']['responseDemo']['responseSuccess'])
);
}
public function response(): Response
{
$methodAnnotation = $this->annotation->method(
$this->passage,
$this->method
);
$url = $this->extractUrlAnnotation(
$methodAnnotation
);
try {
$response = $this->request($url);
} catch (ClientException|MockException $e) {
return new Response(
500,
['server' => 'mock'],
new Stream($e->getMessage())
);
}
return $response;
}
protected function extractUrlAnnotation(array $methodAnnotation)
{
$tag = '@link';
$line = $methodAnnotation[$tag] ?? [];
return $line ? $line[0] : false;
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Mock;
use Lackoxygen\TiktokShop\Util\Json;
class Stream
{
protected string $content;
public function __construct($content)
{
if (is_array($content)) {
$content = Json::marshal($content);
}
$this->content = $content;
}
public function __toString(): string
{
return $this->content;
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage\Alliance;
use Lackoxygen\TiktokShop\Passage\Passage;
class Alliance extends Passage implements AllianceInterface
{
/**
* @inheritDoc
*/
public function simplePlan(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/simplePlan')->service('buyin.simplePlan');
}
/**
* @inheritDoc
*/
public function exclusivePlan(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/exclusivePlan')->service('buyin.exclusivePlan');
}
/**
* @inheritDoc
*/
public function activitySearch(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/activitySearch')->service('buyin.activitySearch');
}
/**
* @inheritDoc
*/
public function applyActivities(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/applyActivities')
->service('buyin.applyActivities');
}
/**
* @inheritDoc
*/
public function createOrUpdateOrienPlan(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/createOrUpdateOrienPlan')
->service('buyin.createOrUpdateOrienPlan');
}
/**
* @inheritDoc
*/
public function orienPlanList(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/orienPlanList')->service('buyin.orienPlanList');
}
/**
* @inheritDoc
*/
public function orienPlanAuthors(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/orienPlanAuthors')
->service('buyin.orienPlanAuthors');
}
/**
* @inheritDoc
*/
public function orienPlanCtrl(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/orienPlanCtrl')->service('buyin.orienPlanCtrl');
}
/**
* @inheritDoc
*/
public function orienPlanAuthorsAdd(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/orienPlanAuthorsAdd')
->service('buyin.orienPlanAuthorsAdd');
}
/**
* @inheritDoc
*/
public function orienPlanAudit(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/orienPlanAudit')->service('buyin.orienPlanAudit');
}
/**
* @inheritDoc
*/
public function colonelActivityCreateOrUpdate(array $params)
{
$this->builder->method('POST')
->params($params)
->path('alliance/colonelActivityCreateOrUpdate')
->service('alliance.colonelActivityCreateOrUpdate');
}
/**
* @inheritDoc
*/
public function activityProductCategoryList(array $params)
{
$this->builder->method('POST')
->params($params)
->path('alliance/activityProductCategoryList')
->service('alliance.activityProductCategoryList');
}
/**
* @inheritDoc
*/
public function instituteColonelActivityList(array $params)
{
$this->builder->method('POST')
->params($params)
->path('alliance/instituteColonelActivityList')
->service('alliance.instituteColonelActivityList');
}
/**
* @inheritDoc
*/
public function instituteColonelActivityOperate(array $params)
{
$this->builder->method('POST')
->params($params)
->path('alliance/instituteColonelActivityOperate')
->service('alliance.instituteColonelActivityOperate');
}
/**
* @inheritDoc
*/
public function colonelActivityProduct(array $params)
{
$this->builder->method('POST')
->params($params)
->path('alliance/colonelActivityProduct')
->service('alliance.colonelActivityProduct');
}
/**
* @inheritDoc
*/
public function colonelActivityProductAudit(array $params)
{
$this->builder->method('POST')
->params($params)
->path('alliance/colonelActivityProductAudit')
->service('alliance.colonelActivityProductAudit');
}
/**
* @inheritDoc
*/
public function colonelActivityProductExtension(array $params)
{
$this->builder->method('POST')
->params($params)
->path('alliance/colonelActivityProductExtension')
->service('alliance.colonelActivityProductExtension');
}
/**
* @inheritDoc
*/
public function specialApplyList(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin.colonel/specialApplyList')
->service('buyin.colonel.specialApplyList');
}
/**
* @inheritDoc
*/
public function specialApplyDeal(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin.colonel/specialApplyDeal')
->service('buyin.colonel.specialApplyDeal');
}
/**
* @inheritDoc
*/
public function materialsProductsSearch(array $params)
{
$this->builder->method('POST')
->params($params)
->path('alliance/materialsProductsSearch')
->service('alliance.materialsProductsSearch');
}
/**
* @inheritDoc
*/
public function materialsProductsDetails(array $params)
{
$this->builder->method('POST')
->params($params)
->path('alliance/materialsProductsDetails')
->service('alliance.materialsProductsDetails');
}
/**
* @inheritDoc
*/
public function materialsProductCategory(array $params)
{
$this->builder->method('POST')
->params($params)
->path('alliance/materialsProductCategory')
->service('alliance.materialsProductCategory');
}
/**
* @inheritDoc
*/
public function materialsProductStatus(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/materialsProductStatus')
->service('buyin.materialsProductStatus');
}
/**
* @inheritDoc
*/
public function queryInstituteOrders(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/queryInstituteOrders')
->service('buyin.queryInstituteOrders');
}
/**
* @inheritDoc
*/
public function kolPidCreate(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/kolPidCreate')->service('buyin.kolPidCreate');
}
/**
* @inheritDoc
*/
public function kolPidList(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/kolPidList')->service('buyin.kolPidList');
}
/**
* @inheritDoc
*/
public function kolPidEdit(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/kolPidEdit')->service('buyin.kolPidEdit');
}
/**
* @inheritDoc
*/
public function kolPidDel(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/kolPidDel')->service('buyin.kolPidDel');
}
/**
* @inheritDoc
*/
public function kolProductShare(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/kolProductShare')
->service('buyin.kolProductShare');
}
/**
* @inheritDoc
*/
public function institutePidCreate(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/institutePidCreate')
->service('buyin.institutePidCreate');
}
/**
* @inheritDoc
*/
public function institutePidList(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/institutePidList')
->service('buyin.institutePidList');
}
/**
* @inheritDoc
*/
public function institutePidEdit(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/institutePidEdit')
->service('buyin.institutePidEdit');
}
/**
* @inheritDoc
*/
public function institutePidDel(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/institutePidDel')
->service('buyin.institutePidDel');
}
/**
* @inheritDoc
*/
public function liveShareMaterial(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/liveShareMaterial')
->service('buyin.liveShareMaterial');
}
/**
* @inheritDoc
*/
public function instituteLiveShare(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/instituteLiveShare')
->service('buyin.instituteLiveShare');
}
/**
* @inheritDoc
*/
public function instituteOrderAds(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/instituteOrderAds')
->service('buyin.instituteOrderAds');
}
/**
* @inheritDoc
*/
public function kolOrderAds(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/kolOrderAds')->service('buyin.kolOrderAds');
}
/**
* @inheritDoc
*/
public function shopPidMemberCreate(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/shopPidMemberCreate')
->service('buyin.shopPidMemberCreate');
}
/**
* @inheritDoc
*/
public function kolMaterialsProductsDetails(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/kolMaterialsProductsDetails')
->service('buyin.kolMaterialsProductsDetails');
}
/**
* @inheritDoc
*/
public function getProductShareMaterial(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/getProductShareMaterial')
->service('buyin.getProductShareMaterial');
}
/**
* @inheritDoc
*/
public function getProductSkus(array $params)
{
$this->builder->method('POST')->params($params)->path('buyin/productSkus')->service('buyin.productSkus');
}
/**
* @inheritDoc
*/
public function shareCommandParse(array $params)
{
$this->builder->method('POST')
->params($params)
->path('buyin/shareCommandParse')
->service('buyin.shareCommandParse');
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage\Alliance;
use Lackoxygen\TiktokShop\Passage\ResultSet;
interface AllianceInterface
{
/**
* @link https://op.jinritemai.com/docs/api-docs/61/923
* @param array $params
* @return ResultSet
*/
public function simplePlan(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/922
* @param array $params
* @return ResultSet
*/
public function exclusivePlan(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/743
* @param array $params
* @return ResultSet
*/
public function activitySearch(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/744
* @param array $params
* @return ResultSet
*/
public function applyActivities(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/708
* @param array $params
* @return ResultSet
*/
public function createOrUpdateOrienPlan(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/705
* @param array $params
* @return ResultSet
*/
public function orienPlanList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/709
* @param array $params
* @return ResultSet
*/
public function orienPlanAuthors(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/706
* @param array $params
* @return ResultSet
*/
public function orienPlanCtrl(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/706
* @param array $params
* @return ResultSet
*/
public function orienPlanAuthorsAdd(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/707
* @param array $params
* @return ResultSet
*/
public function orienPlanAudit(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/966
* @param array $params
* @return ResultSet
*/
public function colonelActivityCreateOrUpdate(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/970
* @param array $params
* @return ResultSet
*/
public function activityProductCategoryList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1330
* @param array $params
* @return ResultSet
*/
public function instituteColonelActivityList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/972
* @param array $params
* @return ResultSet
*/
public function instituteColonelActivityOperate(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/968
* @param array $params
* @return ResultSet
*/
public function colonelActivityProduct(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/971
* @param array $params
* @return ResultSet
*/
public function colonelActivityProductAudit(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/967
* @param array $params
* @return ResultSet
*/
public function colonelActivityProductExtension(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1552
* @param array $params
* @return ResultSet
*/
public function specialApplyList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1553
* @param array $params
* @return ResultSet
*/
public function specialApplyDeal(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/924
* @param array $params
* @return ResultSet
*/
public function materialsProductsSearch(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1356
* @param array $params
* @return ResultSet
*/
public function materialsProductsDetails(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/637
* @param array $params
* @return ResultSet
*/
public function materialsProductCategory(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1497
* @param array $params
* @return ResultSet
*/
public function materialsProductStatus(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1398
* @param array $params
* @return ResultSet
*/
public function queryInstituteOrders(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1460
* @param array $params
* @return ResultSet
*/
public function kolPidCreate(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1461
* @param array $params
* @return ResultSet
*/
public function kolPidList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1462
* @param array $params
* @return ResultSet
*/
public function kolPidEdit(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1463
* @param array $params
* @return ResultSet
*/
public function kolPidDel(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1464
* @param array $params
* @return ResultSet
*/
public function kolProductShare(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1273
* @param array $params
* @return ResultSet
*/
public function institutePidCreate(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1269
* @param array $params
* @return ResultSet
*/
public function institutePidList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1270
* @param array $params
* @return ResultSet
*/
public function institutePidEdit(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1271
* @param array $params
* @return ResultSet
*/
public function institutePidDel(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1396
* @param array $params
* @return ResultSet
*/
public function liveShareMaterial(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1297
* @param array $params
* @return ResultSet
*/
public function instituteLiveShare(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1296
* @param array $params
* @return ResultSet
*/
public function instituteOrderAds(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1459
* @param array $params
* @return ResultSet
*/
public function kolOrderAds(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1493
* @param array $params
* @return ResultSet
*/
public function shopPidMemberCreate(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1589
* @param array $params
* @return ResultSet
*/
public function kolMaterialsProductsDetails(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1588
* @param array $params
* @return ResultSet
*/
public function getProductShareMaterial(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1626
* @param array $params
* @return mixed
*/
public function getProductSkus(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/61/1726
* @param array $params
* @return mixed
*/
public function shareCommandParse(array $params);
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage;
use Illuminate\Support\Arr;
class Authorize extends Passage
{
/**
* @param string $code
* @param string $grantType {authorization_self, authorization_code}
* @param bool $sandbox
* @return ResultSet
*/
public function token(string $code, string $grantType = 'authorization_code', bool $sandbox = false)
{
$params = ['code' => $code, 'grant_type' => $grantType];
if ($sandbox) {
if ($grantType === 'authorization_self') {
if ($code == '4463798') {
Arr::set($params, 'test_shop', 1);
} else {
Arr::set($params, 'shop_id', $code);
}
}
}
$this->builder->service('token.create');
$this->builder
->method('GET')
->path('/token/create')
->service('token.create')
->params($params);
}
/**
* @param string $refreshToken
* @param string $grantType
* @return ResultSet
*/
public function refresh(string $refreshToken, string $grantType = 'refresh_token')
{
$this->builder
->method('POST')
->service('token.refresh')
->params(['refresh_token' => $refreshToken, 'grant_type' => $grantType]);
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage\Order;
use Lackoxygen\TiktokShop\Passage\Passage;
class Order extends Passage implements OrderInterface
{
/**
* @inheritDoc
*/
public function searchList(array $params)
{
$this->builder->method('POST')->service('order.searchList')->path('/order/searchList')->params($params);
}
/**
* @inheritDoc
*/
public function orderDetail(array $params)
{
$this->builder->method('POST')->service('order.orderDetail')->path('/order/orderDetail')->params($params);
}
/**
* @inheritDoc
*/
public function batchDecrypt(array $params)
{
$this->builder->method('POST')->service('order.batchDecrypt')->path('/order/batchDecrypt')->params($params);
}
/**
* @inheritDoc
*/
public function addOrderRemark(array $params)
{
$this->builder->method('POST')->service('order.addOrderRemark')->path('/order/addOrderRemark')->params($params);
}
/**
* @inheritDoc
*/
public function updatePostAmount(array $params)
{
$this->builder->method('POST')
->service('order.updatePostAmount')
->path('/order/updatePostAmount')
->params($params);
}
/**
* @inheritDoc
*/
public function addressAppliedSwitch(array $params)
{
$this->builder->method('POST')
->service('order.AddressAppliedSwitch')
->path('/order/AddressAppliedSwitch')
->params($params);
}
/**
* @inheritDoc
*/
public function updateOrderAmount(array $params)
{
$this->builder->method('POST')->service('order.updateOrderAmount')->path('')->params($params);
}
public function addressConfirm(array $params)
{
$this->builder->method('POST')->service('order.addressConfirm')->params($params);
}
/**
* @inheritDoc
*/
public function addressModify(array $params)
{
$this->builder->method('POST')->service('order.addressModify')->params($params);
}
/**
* @inheritDoc
*/
public function addressSwitchConfig(array $params)
{
$this->builder->method('POST')->service('order.addresSwitchConfig')->params($params);
}
/**
* @inheritDoc
*/
public function invoiceList(array $params)
{
$this->builder->method('POST')->service('order.invoiceList')->params($params);
}
/**
* @inheritDoc
*/
public function batchEncrypt(array $params)
{
$this->builder->method('POST')->service('order.batchEncrypt')->params($params);
}
/**
* @inheritDoc
*/
public function batchSensitive(array $params)
{
$this->builder->method('POST')->service('order.batchSensitive')->params($params);
}
public function invoiceUpload(array $params)
{
$this->builder->method('POST')->service('order.stockUp')->params($params);
}
/**
* @inheritDoc
*/
public function batchSearchIndex(array $params)
{
$this->builder->method('POST')->service('order.BatchSearchIndex')->params($params);
}
/**
* @inheritDoc
*/
public function antispamOrderSend(array $params)
{
$this->builder->method('POST')->service('antispam.orderSend')->params($params);
}
/**
* @inheritDoc
*/
public function antispamOrderQuery(array $params)
{
$this->builder->method('POST')->service('antispam.orderQuery')->params($params);
}
/**
* @inheritDoc
*/
public function getCrossBorderFulfillInfo(array $params)
{
$this->builder->method('POST')->service('order.getCrossBorderFulfillInfo')->params($params);
}
/**
* @inheritDoc
*/
public function getServiceList(array $params)
{
$this->builder->method('POST')->service('order.getServiceList')->params($params);
}
/**
* @inheritDoc
*/
public function addSerialNumber(array $params)
{
$this->builder->method('POST')->service('order.addSerialNumber')->params($params);
}
/**
* @inheritDoc
*/
public function replyService(array $params)
{
$this->builder->method('POST')->service('order.replyService')->params($params);
}
/**
* @inheritDoc
*/
public function serviceDetail(array $params)
{
$this->builder->method('POST')->service('order.serviceDetail')->params($params);
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage\Order;
use Lackoxygen\TiktokShop\Passage\ResultSet;
/**
* @link https://op.jinritemai.com/docs/api-docs/15/1343
*/
interface OrderInterface
{
/**
* @link https://op.jinritemai.com/docs/api-docs/15/1342
* @param array $params
* @return ResultSet
*/
public function searchList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/1343
* @param array $params
* @return ResultSet
*/
public function orderDetail(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/982
* @param array $params
* @return ResultSet
*/
public function batchDecrypt(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/568
* @param array $params
* @return ResultSet
*/
public function addOrderRemark(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/264
* @param array $params
* @return ResultSet
*/
public function updatePostAmount(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/500
* @param array $params
* @return ResultSet
*/
public function addressAppliedSwitch(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/263
* @param array $params
* @return ResultSet
*/
public function updateOrderAmount(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/505
* @param array $params
* @return ResultSet
*/
public function addressConfirm(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/290
* @param array $params
* @return ResultSet
*/
public function addressModify(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/501
* @param array $params
* @return ResultSet
*/
public function addressSwitchConfig(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/660
* @param array $params
* @return ResultSet
*/
public function invoiceList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/487
* @param array $params
* @return ResultSet
*/
public function batchEncrypt(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/508
* @param array $params
* @return ResultSet
*/
public function batchSensitive(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/892
* @param array $params
* @return ResultSet
*/
public function invoiceUpload(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/516
* @param array $params
* @return ResultSet
*/
public function batchSearchIndex(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/649
* @param array $params
* @return ResultSet
*/
public function antispamOrderSend(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/650
* @param array $params
* @return ResultSet
*/
public function antispamOrderQuery(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/495
* @param array $params
* @return ResultSet
*/
public function getCrossBorderFulfillInfo(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/266
* @param array $params
* @return ResultSet
*/
public function getServiceList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/1289
* @param array $params
* @return ResultSet
*/
public function addSerialNumber(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/75
* @param array $params
* @return ResultSet
*/
public function replyService(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/15/253
* @param array $params
* @return ResultSet
*/
public function serviceDetail(array $params);
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage;
use Lackoxygen\TiktokShop\Attribute\Config;
use Lackoxygen\TiktokShop\Exception\ClientException;
use Lackoxygen\TiktokShop\Transmit\Builder;
abstract class Passage
{
protected Config $config;
protected Builder $builder;
/**
* @param Config $config
* @param string $method
*/
public function __construct(Config $config, string $method)
{
$this->config = $config;
$this->builder = Builder::create($config, get_class($this), $method);
}
/**
* @return \Psr\Http\Message\ResponseInterface
* @throws ClientException
*/
public function __invoke(): \Psr\Http\Message\ResponseInterface
{
return $this->builder->request();
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage;
use Lackoxygen\TiktokShop\Attribute\Config;
use Lackoxygen\TiktokShop\Exception\{ClientException, ExpiredException};
class PassageProxy
{
protected string $passage;
protected Config $config;
protected function __construct(string $passage, Config $config)
{
$this->passage = $passage;
$this->config = $config;
}
public static function proxy(string $passage, Config $config): PassageProxy
{
return new self($passage, $config);
}
/**
* @throws ClientException
* @throws ExpiredException
*/
public function __call($name, $arguments): ResultSet
{
/**
* @var Passage $passage
*/
$passage = new $this->passage($this->config, $name);
$result = call_user_func_array([$passage, $name], $arguments);
if (!is_null($result)) {
return new ResultSet($result);
}
return new ResultSet($passage());
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage\Product;
use Lackoxygen\TiktokShop\Passage\Passage;
class Product extends Passage implements ProductInterface
{
/**
* @inheritDoc
*/
public function listV2(array $params)
{
$this->builder->method('POST')->service('product.listV2')->params($params);
}
/**
* @inheritDoc
*/
public function getCateProperty(array $params)
{
$this->builder->method('POST')->service('product.getCateProperty')->params($params);
}
/**
* @inheritDoc
*/
public function addV2(array $params)
{
$this->builder->method('POST')->service('product.addV2')->params($params);
}
/**
* @inheritDoc
*/
public function editV2(array $params)
{
$this->builder->method('POST')->service('product.editV2')->params($params);
}
/**
* @inheritDoc
*/
public function detail(array $params)
{
$this->builder->method('POST')->service('product.detail')->params($params);
}
/**
* @inheritDoc
*/
public function del(array $params)
{
$this->builder->method('POST')->service('product.del')->params($params);
}
/**
* @inheritDoc
*/
public function skuDetail(array $params)
{
$this->builder->method('POST')->service('sku.detail')->params($params);
}
/**
* @inheritDoc
*/
public function freightTemplateList(array $params)
{
$this->builder->method('POST')->service('freightTemplate.list')->params($params);
}
/**
* @inheritDoc
*/
public function brandList(array $params)
{
$this->builder->method('POST')->service('brand.list')->params($params);
}
/**
* @inheritDoc
*/
public function getCatePropertyV2(array $params)
{
$this->builder->method('POST')->service('product.getCatePropertyV2')->params($params);
}
/**
* @inheritDoc
*/
public function setOnline(array $params)
{
$this->builder->method('POST')->service('product.setOnline')->params($params);
}
/**
* @inheritDoc
*/
public function skuList(array $params)
{
$this->builder->method('POST')->service('sku.list')->params($params);
}
/**
* @inheritDoc
*/
public function skuSyncStockBatch(array $params)
{
$this->builder->method('POST')->service('sku.syncStockBatch')->params($params);
}
/**
* @inheritDoc
*/
public function setOffline(array $params)
{
$this->builder->method('POST')->service('product.setOffline')->params($params);
}
/**
* @inheritDoc
*/
public function qualityList(array $params)
{
$this->builder->method('POST')->service('product.qualityList')->params($params);
}
/**
* @inheritDoc
*/
public function editSkuPrice(array $params)
{
$this->builder->method('POST')->service('sku.editPrice')->params($params);
}
/**
* @inheritDoc
*/
public function qualityDetail(array $params)
{
$this->builder->method('POST')->service('product.qualityDetail')->params($params);
}
/**
* @inheritDoc
*/
public function editBuyerLimit(array $params)
{
$this->builder->method('POST')->service('product.editBuyerLimit')->params($params);
}
/**
* @inheritDoc
*/
public function qualityTask(array $params)
{
$this->builder->method('POST')->service('product.qualityTask')->params($params);
}
/**
* @inheritDoc
*/
public function getSpuKeyPropertyByCid(array $params)
{
$this->builder->method('POST')->service('spu.getKeyPropertyByCid')->params($params);
}
/**
* @inheritDoc
*/
public function editSkuCode(array $params)
{
$this->builder->method('POST')->service('sku.editCode')->params($params);
}
/**
* @inheritDoc
*/
public function getSpuInfoBySpuId(array $params)
{
$this->builder->method('POST')->service('spu.getSpuInfoBySpuId')->params($params);
}
/**
* @inheritDoc
*/
public function getSpuTpl(array $params)
{
$this->builder->method('POST')->service('spu.getSpuTpl')->params($params);
}
/**
* @inheritDoc
*/
public function addShopSpu(array $params)
{
$this->builder->method('POST')->service('spu.addShopSpu')->params($params);
}
/**
* @inheritDoc
*/
public function opptyProductApply(array $params)
{
$this->builder->method('POST')->service('opptyProduct.apply')->params($params);
}
/**
* @inheritDoc
*/
public function opptyProductClue(array $params)
{
$this->builder->method('POST')->service('opptyProduct.clue')->params($params);
}
/**
* @inheritDoc
*/
public function getOpptyProductApplyProgress(array $params)
{
$this->builder->method('POST')->service('opptyProduct.getApplyProgress')->params($params);
}
/**
* @inheritDoc
*/
public function allianceMaterialsProductCategory(array $params)
{
$this->builder->method('POST')->service('alliance.materialsProductCategory')->params($params);
}
/**
* @inheritDoc
*/
public function qualificationConfig(array $params)
{
$this->builder->method('POST')->service('product.qualificationConfig')->params($params);
}
/**
* @inheritDoc
*/
public function getBrandSug(array $params)
{
$this->builder->method('POST')->service('brand.getSug')->params($params);
}
/**
* @inheritDoc
*/
public function promiseDeliveryList(array $params)
{
$this->builder->method('POST')->service('promise.deliveryList')->params($params);
}
/**
* @inheritDoc
*/
public function brandConvert(array $params)
{
$this->builder->method('POST')->service('brand.convert')->params($params);
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage\Product;
use Lackoxygen\TiktokShop\Passage\ResultSet;
interface ProductInterface
{
/**
* @link https://op.jinritemai.com/docs/api-docs/14/633
* @param array $params
* @return ResultSet
*/
public function listV2(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/94
* @param array $params
* @return ResultSet
*/
public function getCateProperty(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/249
* @param array $params
* @return ResultSet
*/
public function addV2(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/250
* @param array $params
* @return ResultSet
*/
public function editV2(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/56
* @param array $params
* @return ResultSet
*/
public function detail(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/61
* @param array $params
* @return ResultSet
*/
public function del(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/566
* @param array $params
* @return ResultSet
*/
public function skuDetail(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/565
* @param array $params
* @return ResultSet
*/
public function freightTemplateList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/1267
* @param array $params
* @return ResultSet
*/
public function brandList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/1373
* @param array $params
* @return ResultSet
*/
public function getCatePropertyV2(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/251
* @param array $params
* @return ResultSet
*/
public function setOnline(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/82
* @param array $params
* @return ResultSet
*/
public function skuList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/298
* @param array $params
* @return ResultSet
*/
public function skuSyncStockBatch(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/252
* @param array $params
* @return ResultSet
*/
public function setOffline(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/938
* @param array $params
* @return ResultSet
*/
public function qualityList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/84
* @param array $params
* @return ResultSet
*/
public function editSkuPrice(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/939
* @param array $params
* @return ResultSet
*/
public function qualityDetail(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/262
* @param array $params
* @return ResultSet
*/
public function editBuyerLimit(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/937
* @param array $params
* @return ResultSet
*/
public function qualityTask(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/642
* @param array $params
* @return ResultSet
*/
public function getSpuKeyPropertyByCid(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/86
* @param array $params
* @return ResultSet
*/
public function editSkuCode(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/643
* @param array $params
* @return ResultSet
*/
public function getSpuInfoBySpuId(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/644
* @param array $params
* @return ResultSet
*/
public function getSpuTpl(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/645
* @param array $params
* @return ResultSet
*/
public function addShopSpu(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/738
* @param array $params
* @return ResultSet
*/
public function opptyProductApply(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/739
* @param array $params
* @return ResultSet
*/
public function opptyProductClue(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/740
* @param array $params
* @return ResultSet
*/
public function getOpptyProductApplyProgress(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/637
* @param array $params
* @return ResultSet
*/
public function allianceMaterialsProductCategory(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/1382
* @param array $params
* @return ResultSet
*/
public function qualificationConfig(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/1436
* @param array $params
* @return ResultSet
*/
public function getBrandSug(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/1529
* @param array $params
* @return ResultSet
*/
public function promiseDeliveryList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/14/1500
* @param array $params
* @return ResultSet
*/
public function brandConvert(array $params);
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage;
use Lackoxygen\TiktokShop\Util\Json;
use GuzzleHttp\Psr7\Response;
use Illuminate\Support\Arr;
class ResultSet
{
protected array $items = [];
protected $result;
public function __construct($result)
{
$this->result = $result;
if ($this->isResponse()) {
$this->items = Json::unmarshal($result->getBody()->getContents());
} else {
$this->items = is_array($result) ? $result : [$result];
}
}
protected function isResponse(): bool
{
return $this->result instanceof Response;
}
public function toArray(): array
{
return $this->items;
}
public function isSuccess(): bool
{
$array = $this->toArray();
if ($this->isResponse()) {
return 10000 === $array['code'];
}
return true === Arr::first($array);
}
public function getMessage(): string
{
$array = $this->toArray();
return (string) $array['message'] ?? '';
}
public function getData(): array
{
$array = $this->toArray();
return (array) Arr::get($array, 'data', []);
}
public function get(string $key, $default = '')
{
return Arr::get($this->getData(), $key, $default);
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage\Shop;
use Lackoxygen\TiktokShop\Passage\Passage;
class Shop extends Passage implements ShopInterface
{
/**
* @inheritDoc
*/
public function brandList(array $params)
{
$this->builder->service('POST')->params($params)->service('shop.brandList');
}
/**
* @inheritDoc
*/
public function searchMemberList(array $params)
{
$this->builder->service('POST')->params($params)->service('member.searchList');
}
/**
* @inheritDoc
*/
public function userLogin(array $params)
{
$this->builder->service('POST')->params($params)->service('antispam.userLogin');
}
/**
* @inheritDoc
*/
public function getShopCategory(array $params)
{
$this->builder->service('POST')->params($params)->service('shop.getShopCategory');
}
/**
* @inheritDoc
*/
public function addressUpdate(array $params)
{
$this->builder->service('POST')->params($params)->service('address.update');
}
/**
* @inheritDoc
*/
public function addressCreate(array $params)
{
$this->builder->service('POST')->params($params)->service('address.create');
}
/**
* @inheritDoc
*/
public function getShopShortLink(array $params)
{
$this->builder->service('POST')->params($params)->service('member.getShopShortLink');
}
/**
* @inheritDoc
*/
public function addressList(array $params)
{
$this->builder->service('POST')->params($params)->service('address.list');
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage\Shop;
use Lackoxygen\TiktokShop\Passage\ResultSet;
interface ShopInterface
{
/**
* @link https://op.jinritemai.com/docs/api-docs/13/54
* @param array $params
* @return ResultSet
*/
public function brandList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/13/366
* @param array $params
* @return ResultSet
*/
public function searchMemberList(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/13/635
* @param array $params
* @return ResultSet
*/
public function userLogin(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/13/821
* @param array $params
* @return ResultSet
*/
public function getShopCategory(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/13/1511
* @param array $params
* @return ResultSet
*/
public function addressUpdate(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/13/1510
* @param array $params
* @return ResultSet
*/
public function addressCreate(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/13/1455
* @param array $params
* @return ResultSet
*/
public function getShopShortLink(array $params);
/**
* @link https://op.jinritemai.com/docs/api-docs/13/1435
* @param array $params
* @return ResultSet
*/
public function addressList(array $params);
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Passage;
class Verify extends Passage
{
public function md5($sign, string $body): bool
{
$md5 = md5($this->config->getAppKey() .
$body .
$this->config->getAppSecret());
return $md5 === $sign;
}
public function sha256($sign, string $body): bool
{
return true;
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop;
use Illuminate\Support\Arr;
use Lackoxygen\TiktokShop\Attribute\Config;
use Lackoxygen\TiktokShop\Passage\Alliance\Alliance;
use Lackoxygen\TiktokShop\Passage\Authorize;
use Lackoxygen\TiktokShop\Passage\Order\OrderInterface;
use Lackoxygen\TiktokShop\Passage\PassageProxy;
use Lackoxygen\TiktokShop\Passage\Product\ProductInterface;
use Lackoxygen\TiktokShop\Passage\Shop\ShopInterface;
use Lackoxygen\TiktokShop\Passage\Verify;
/**
* @method OrderInterface order()
* @method ShopInterface shop()
* @method ProductInterface product()
* @method Authorize authorize()
* @method Verify verify()
* @method Alliance alliance()
*/
class TiktokShop
{
/**
* @var Config
*/
protected Config $config;
/**
* @var array|string[]
*/
protected static array $passages = [
'order' => Passage\Order\Order::class, 'shop' => Passage\Shop\Shop::class,
'product' => Passage\Product\Product::class, 'authorize' => Authorize::class, 'verify' => Verify::class,
'alliance' => Alliance::class
];
/**
* @param $config
*/
public function __construct($config = null)
{
if (!$config instanceof Config) {
$default = \config(TiktokShopProvider::$name);
if (!is_array($default)) {
return;
}
$config = static::newConfig($default);
}
$this->config = $config;
}
/**
* @param array $options
*
* @return Config
*/
public static function newConfig(array $options): Config
{
return new Config(Arr::get($options, 'app_key'), Arr::get($options, 'app_secret'),
Arr::get($options, 'base_uri'), (float) Arr::get($options, 'timeout'), Arr::get($options, 'enable_mock'));
}
/**
* @param Config $config
*
* @return TiktokShop
*/
public static function use(Config $config): TiktokShop
{
return new static($config);
}
/**
* @param string $accessToken
*
* @return void
*/
public function setAccessToken(string $accessToken): void
{
$this->config->setAccessToken($accessToken);
}
/**
* @param $name
* @param array $arguments
*
* @return PassageProxy
*/
public function __call($name, array $arguments = [])
{
$passage = static::$passages[$name];
return PassageProxy::proxy($passage, $this->config);
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop;
use Illuminate\Support\ServiceProvider;
class TiktokShopProvider extends ServiceProvider
{
/**
* @var string
*/
public static string $name = 'tiktok.shop';
/**
* @return void
*/
public function boot()
{
$configPath = __DIR__.'/../publish/tiktok.php';
$this->publishes([
$configPath => config_path('tiktok.php')
], 'lackoxygen-tiktok');
}
/**
* @return string[]
*/
public function provides(): array
{
return [static::$name, TiktokShop::class];
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Transmit;
use Lackoxygen\TiktokShop\Attribute\Config;
use Lackoxygen\TiktokShop\Attribute\Request;
use Lackoxygen\TiktokShop\Exception\ClientException;
use Lackoxygen\TiktokShop\Mock\Mock;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
class Builder
{
protected Request $request;
protected Config $config;
protected string $passage, $method;
public function __construct(Config $config, string $passage, string $method)
{
$this->request = new Request;
$this->config = $config;
$this->request->setConfig($config);
$this->passage = $passage;
$this->method = $method;
}
public static function create(Config $config, string $passage, string $method): Builder
{
return new static(...func_get_args());
}
public function method(string $method): Builder
{
$this->request->setMethod($method);
return $this;
}
public function params(array $params): Builder
{
$this->request->setParams($params);
return $this;
}
public function v(string $v): Builder
{
$this->request->setV($v);
return $this;
}
public function timestamp($timestamp): Builder
{
$this->request->setTimestamp($timestamp);
return $this;
}
public function service(?string $service): Builder
{
$this->request->setService($service);
return $this;
}
public function signature(bool $signature): Builder
{
$this->request->setSignature($signature);
return $this;
}
public function path(string $path): Builder
{
$this->request->setPath($path);
return $this;
}
/**
* @return Request
*/
public function getRequest(): Request
{
return $this->request;
}
/**
* @return ResponseInterface
* @throws ClientException
*/
public function request(): ResponseInterface
{
$client = Client::create();
if ($this->config->isEnableMock()) {
$mock = new Mock($this->passage, $this->method);
return $mock->response();
}
try {
return $client->request($this->request);
} catch (GuzzleException $e) {
throw new ClientException($e);
}
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Transmit;
use Lackoxygen\TiktokShop\Attribute\Config;
use Lackoxygen\TiktokShop\Attribute\Request;
use Lackoxygen\TiktokShop\Exception\ClientException;
use Lackoxygen\TiktokShop\Exception\RetryException;
use Lackoxygen\TiktokShop\Util\Json;
use Lackoxygen\TiktokShop\Util\Signature;
use Lackoxygen\TiktokShop\Util\Sort;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\RequestOptions;
use Illuminate\Support\Str;
class Client
{
public static function create(): Client
{
return new self;
}
/**
* @param string $service
*
* @return string
*/
protected function serviceToPath(string $service): string
{
return '/'.ltrim(Str::replace('.', '/', $service), '/');
}
/**
* @param Request $request
*
* @return false|string
*/
protected function signature(Request $request): ?string
{
$sig = new Signature;
$sig->setTimestamp($request->getTimestamp());
$sig->setMethod($request->getService());
$sig->setAppKey($request->getConfig()->getAppKey());
$sig->setAppSecret($request->getConfig()->getAppSecret());
$sig->setVersion($request->getV());
$params = $request->getParams();
Sort::ksort($params);
$sig->setParamJson(Json::marshal($params));
return $sig->generate();
}
/**
* @param Request $request
*
* @return array
*/
protected function withSignatureQuery(Request $request): array
{
$params = $request->getParams();
Sort::ksort($params);
return [
'method' => $request->getService(), 'app_key' => $request->getConfig()->getAppKey(),
'access_token' => $request->getConfig()->getAccessToken(), 'param_json' => Json::marshal($params),
'timestamp' => $request->getTimestamp(), 'v' => $request->getV(), 'sign' => $this->signature($request),
'sign_method' => 'hmac-sha256',
];
}
protected function withQuery(Request $request): array
{
return [
'app_id' => $request->getConfig()->getAppKey(), 'app_secret' => $request->getConfig()->getAppSecret(),
];
}
public function guzzleHttp(Config $config): \GuzzleHttp\Client
{
return new \GuzzleHttp\Client([
'base_uri' => $config->getBaseUri(), 'timeout' => $config->getTimeout(), 'verify' => false
]);
}
/**
* @param Request $request
*
* @return \Psr\Http\Message\ResponseInterface
* @throws ClientException
* @throws RetryException
*/
public function request(Request $request): \Psr\Http\Message\ResponseInterface
{
if ($request->isSignature()) {
$query = $this->withSignatureQuery($request);
} else {
$query = $this->withQuery($request);
}
$options = [
RequestOptions::HEADERS => [
'Content-type' => 'application/json'
]
];
$options[RequestOptions::QUERY] = $query;
$options[RequestOptions::JSON] = $request->getParams();
$retry = new Retry(function () use ($request, $options) {
return $this->guzzleHttp($request->getConfig())
->request($request->getMethod(), $request->getPath() ? : $this->serviceToPath($request->getService()),
$options);
}, function ($e) {
return $e instanceof ConnectException;
});
return $retry();
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Transmit;
use Lackoxygen\TiktokShop\Exception\ClientException;
use Lackoxygen\TiktokShop\Exception\RetryException;
class Retry
{
protected \Closure $execute;
protected \Closure $when;
/**
* @param \Closure $execute
* @param \Closure $when
*/
public function __construct(\Closure $execute, \Closure $when)
{
$this->execute = $execute;
$this->when = $when;
}
/**
* @param int $retries
* @param int $waitMilliseconds
*
* @return mixed|void
* @throws ClientException
* @throws RetryException
*/
public function __invoke(int $retries = 3, int $waitMilliseconds = 500)
{
$callback = $this->execute;
$when = $this->when;
$attempts = 0;
do {
try {
return $callback($retries);
} catch (\Throwable $e) {
if (!$when($e)) {
throw new ClientException($e);
}
$waitMilliseconds && usleep($waitMilliseconds * 1000);
}
finally {
++$attempts;
}
} while ($attempts < $retries);
throw new RetryException(sprintf('maximum number of attempts(%d) reached', $attempts));
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Util;
class Json
{
public static function marshal(array $array)
{
return \json_encode($array, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
public static function unmarshal(string $value, $associative = true)
{
return \json_decode($value, $associative);
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Util;
class Preg
{
public static function annotation(string $docs)
{
preg_match_all('/@.*?/U', $docs, $matches);
return $matches[0] ?? [];
}
public static function mergeSpaces($string)
{
return preg_replace("/\s(?=\s)/", "\\1", $string);
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Util;
class Signature
{
private string $appKey;
private string $appSecret;
private string $method;
private string $timestamp;
private string $paramJson;
private string $version;
/**
* @param mixed $appKey
*/
public function setAppKey(string $appKey): Signature
{
$this->appKey = $appKey;
return $this;
}
/**
* @param mixed $method
*/
public function setMethod($method): Signature
{
$this->method = $method;
return $this;
}
/**
* @param mixed $timestamp
*/
public function setTimestamp($timestamp): Signature
{
$this->timestamp = $timestamp;
return $this;
}
/**
* @param mixed $appSecret
*/
public function setAppSecret($appSecret): Signature
{
$this->appSecret = $appSecret;
return $this;
}
/**
* @param mixed $paramJson
*/
public function setParamJson($paramJson): Signature
{
$this->paramJson = $paramJson;
return $this;
}
/**
* @param mixed $version
*/
public function setVersion($version): Signature
{
$this->version = $version;
return $this;
}
public function generate()
{
$paramPattern = 'app_key' . $this->appKey . 'method' .
$this->method . 'param_json' . $this->paramJson .
'timestamp' . $this->timestamp . 'v' . $this->version;
$signPattern = $this->appSecret . $paramPattern . $this->appSecret;
return hash_hmac("sha256", $signPattern, $this->appSecret);
}
}
... ...
<?php
namespace Lackoxygen\TiktokShop\Util;
class Sort
{
public static function kSort(array &$arr)
{
$kstring = true;
foreach ($arr as $k => &$v) {
if (!is_string($k)) {
$kstring = false;
}
if (is_array($v)) {
self::ksort($v);
}
}
if ($kstring) {
ksort($arr);
}
}
}
... ...
<?php
namespace Lackoxygen\Tests;
use Lackoxygen\TiktokShop\Facade\TiktokShop;
use Lackoxygen\TiktokShop\Passage\ResultSet;
class FetchTest extends \PHPUnit\Framework\TestCase
{
public function testRequest()
{
$obj = TiktokShop::alliance()->materialsProductsSearch([]);
$this->assertInstanceOf($obj, ResultSet::class);
}
}
\ No newline at end of file
... ...