作者 竞泽

init

  1 +/vendor/
  2 +composer.lock
  3 +.idea
  1 +# 配置gitlab仓库
  2 +
  3 +```composer
  4 + "repositories": {
  5 + "lackoxygen/top-warehouse": {
  6 + "type": "git",
  7 + "url": "http://47.107.73.162:8099/lackoxygen/tiktok_shop.git"
  8 + },
  9 + }
  10 +```
  11 +
  12 +# 安装
  13 +
  14 +```
  15 +composer require lackoxygen/tiktok_shop
  16 +```
  17 +
  18 +# 配置文件
  19 +
  20 +```
  21 +//路径 config/tiktok.shop.php
  22 + [
  23 + 'app_key' => env('TIKTOK_APP_KEY', '7044793792079201799'),
  24 + 'app_secret' => env('TIKTOK_APP_SECRET', '303fe8fc-5986-4be3-a210-4c4c217880a1'),
  25 + 'enable_mock' => env('TIKTOK_ENABLE_MOCK', false),
  26 + 'base_uri' => env('TIKTOK_BASE_URI', 'https://openapi-sandbox.jinritemai.com'),
  27 + 'timeout' => env('TIKTOK_TIMEOUT', 30),
  28 +];
  29 +```
  30 +
  31 +# 使用方法
  32 +
  33 +1. 门面调用
  34 +
  35 +```php
  36 +use Lackoxygen\TiktokShop\Facade\TiktokShop;
  37 +$obj = TiktokShop::alliance();
  38 +```
  39 +
  40 +2. 直接使用
  41 +
  42 +```php
  43 +use Lackoxygen\TiktokShop\TiktokShop;
  44 +$config = Lackoxygen\TiktokShop\TiktokShop::newConfig(config('some'));
  45 +$obj = new Lackoxygen\TiktokShop\TiktokShop($config);
  46 +```
  47 +
  48 +3.接口判断请求成功
  49 +
  50 +```php
  51 +use Lackoxygen\TiktokShop\Facade\TiktokShop;
  52 +$resultSet = TiktokShop::alliance()->materialsProductsSearch([]);
  53 +if ($resultSet->isSuccess()){
  54 + exit(0)
  55 +}
  56 +exit(1)
  57 +```
  58 +
  59 +4.签名(只支持md5)
  60 +
  61 +```php
  62 +use Lackoxygen\TiktokShop\Facade\TiktokShop;
  63 +$resultSet = TiktokShop::verify()->md5('some', 'body');
  64 +if ($resultSet->isSuccess()){
  65 + exit(0)
  66 +}
  67 +exit(1)
  68 +```
  69 +
  70 +5.超时异常
  71 +
  72 +```php
  73 +use Lackoxygen\TiktokShop\Facade\TiktokShop;
  74 +try {
  75 + $resultSet = TiktokShop::alliance()->materialsProductsSearch([]);
  76 + }catch (\Lackoxygen\TiktokShop\Exception\RetryException $retryException){
  77 + exit(0)
  78 + }
  79 +exit(1)
  80 +
  81 +```
  1 +{
  2 + "name": "lackoxygen/tiktok_shop",
  3 + "type": "library",
  4 + "description": "抖店php-sdk",
  5 + "autoload": {
  6 + "psr-4": {
  7 + "Lackoxygen\\TiktokShop\\": "src/"
  8 + }
  9 + },
  10 + "autoload-dev": {
  11 + "psr-4": {
  12 + "Lackoxygen\\Tests\\": "tests/"
  13 + }
  14 + },
  15 + "authors": [
  16 + {
  17 + "name": "ojz",
  18 + "email": "jingzeou@outlook.com"
  19 + }
  20 + ],
  21 + "require": {
  22 + "php": ">=7.4",
  23 + "illuminate/support": "^5.8"
  24 + },
  25 + "require-dev": {
  26 + "phpunit/phpunit": "^9.5.10"
  27 + },
  28 + "laravel": {
  29 + "providers": [
  30 + "Lackoxygen\\TiktokShop\\TiktokShopProvider"
  31 + ]
  32 + }
  33 +}
  1 +<?php
  2 +
  3 +return [
  4 + 'app_key' => env('TIKTOK_APP_KEY', ''),
  5 + 'app_secret' => env('TIKTOK_APP_SECRET', ''),
  6 + 'enable_mock' => env('TIKTOK_ENABLE_MOCK', false),
  7 + 'base_uri' => env('TIKTOK_BASE_URI', 'https://openapi-sandbox.jinritemai.com'),
  8 + 'timeout' => env('TIKTOK_TIMEOUT', 30),
  9 +];
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Attribute;
  4 +
  5 +class Config
  6 +{
  7 + private string $appKey = '';
  8 +
  9 + private string $appSecret = '';
  10 +
  11 + private bool $enableMock = false;
  12 +
  13 + private string $baseUri = '';
  14 +
  15 + private string $accessToken = '';
  16 +
  17 + private float $timeout;
  18 +
  19 + public function __construct(
  20 + string $appKey = '',
  21 + string $appSecret = '',
  22 + string $baseUri = '',
  23 + float $timeout = 30.0,
  24 + bool $enableMock = false
  25 + ) {
  26 + $this->appKey = $appKey;
  27 + $this->appSecret = $appSecret;
  28 + $this->baseUri = $baseUri;
  29 + $this->timeout = $timeout;
  30 + $this->enableMock = $enableMock;
  31 + }
  32 +
  33 + /**
  34 + * @param mixed $appKey
  35 + */
  36 + public function setAppKey(string $appKey): void
  37 + {
  38 + $this->appKey = $appKey;
  39 + }
  40 +
  41 + /**
  42 + * @return string
  43 + */
  44 + public function getAppKey(): ?string
  45 + {
  46 + return $this->appKey;
  47 + }
  48 +
  49 + /**
  50 + * @param mixed $appSecret
  51 + */
  52 + public function setAppSecret($appSecret): void
  53 + {
  54 + $this->appSecret = $appSecret;
  55 + }
  56 +
  57 + /**
  58 + * @return string
  59 + */
  60 + public function getAppSecret(): ?string
  61 + {
  62 + return $this->appSecret;
  63 + }
  64 +
  65 + /**
  66 + * @param bool $enableMock
  67 + */
  68 + public function setEnableMock(bool $enableMock): void
  69 + {
  70 + $this->enableMock = $enableMock;
  71 + }
  72 +
  73 + /**
  74 + * @return bool
  75 + */
  76 + public function isEnableMock(): bool
  77 + {
  78 + return $this->enableMock;
  79 + }
  80 +
  81 +
  82 + /**
  83 + * @param string $baseUri
  84 + */
  85 + public function setBaseUri(string $baseUri): void
  86 + {
  87 + $this->baseUri = $baseUri;
  88 + }
  89 +
  90 + /**
  91 + * @return string
  92 + */
  93 + public function getBaseUri(): string
  94 + {
  95 + return $this->baseUri;
  96 + }
  97 +
  98 + /**
  99 + * @param string $accessToken
  100 + */
  101 + public function setAccessToken(string $accessToken): void
  102 + {
  103 + $this->accessToken = $accessToken;
  104 + }
  105 +
  106 + /**
  107 + * @return string
  108 + */
  109 + public function getAccessToken(): string
  110 + {
  111 + return $this->accessToken;
  112 + }
  113 +
  114 + /**
  115 + * @param float $timeout
  116 + */
  117 + public function setTimeout(float $timeout): void
  118 + {
  119 + $this->timeout = $timeout;
  120 + }
  121 +
  122 + /**
  123 + * @return float
  124 + */
  125 + public function getTimeout(): float
  126 + {
  127 + return $this->timeout;
  128 + }
  129 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Attribute;
  4 +
  5 +class Request
  6 +{
  7 + private string $service = '';
  8 +
  9 + private string $timestamp = '';
  10 +
  11 + private string $v = '2';
  12 +
  13 + private string $method = 'GET';
  14 +
  15 + private array $params = [];
  16 +
  17 + protected string $path = '';
  18 +
  19 + private bool $signature = true;
  20 +
  21 + private Config $config;
  22 +
  23 + /**
  24 + * @param mixed $config
  25 + */
  26 + public function setConfig(Config $config): void
  27 + {
  28 + $this->config = $config;
  29 + }
  30 +
  31 + /**
  32 + * @return mixed
  33 + */
  34 + public function getConfig(): Config
  35 + {
  36 + return $this->config;
  37 + }
  38 +
  39 + /**
  40 + * @return string
  41 + */
  42 + public function getService(): string
  43 + {
  44 + return $this->service;
  45 + }
  46 +
  47 + /**
  48 + * @param mixed $service
  49 + */
  50 + public function setService($service): void
  51 + {
  52 + $this->service = $service;
  53 + }
  54 +
  55 + /**
  56 + * @return string
  57 + */
  58 + public function getTimestamp(): string
  59 + {
  60 + return $this->timestamp ?: date('Y-m-d H:i:s');
  61 + }
  62 +
  63 + /**
  64 + * @param mixed $timestamp
  65 + */
  66 + public function setTimestamp($timestamp): void
  67 + {
  68 + $this->timestamp = $timestamp;
  69 + }
  70 +
  71 + /**
  72 + * @return string
  73 + */
  74 + public function getV(): string
  75 + {
  76 + return $this->v;
  77 + }
  78 +
  79 + /**
  80 + * @param mixed $v
  81 + */
  82 + public function setV($v): void
  83 + {
  84 + $this->v = $v;
  85 + }
  86 +
  87 + /**
  88 + * @return string
  89 + */
  90 + public function getMethod(): string
  91 + {
  92 + return $this->method;
  93 + }
  94 +
  95 + /**
  96 + * @param mixed $method
  97 + */
  98 + public function setMethod($method): void
  99 + {
  100 + $this->method = $method;
  101 + }
  102 +
  103 +
  104 + /**
  105 + * @return array
  106 + */
  107 + public function getParams(): array
  108 + {
  109 + return $this->params;
  110 + }
  111 +
  112 + /**
  113 + * @param mixed $params
  114 + */
  115 + public function setParams(array $params): void
  116 + {
  117 + $this->params = $params;
  118 + }
  119 +
  120 + /**
  121 + * @return bool
  122 + */
  123 + public function isSignature(): bool
  124 + {
  125 + return $this->signature;
  126 + }
  127 +
  128 + /**
  129 + * @param bool $signature
  130 + */
  131 + public function setSignature(bool $signature): void
  132 + {
  133 + $this->signature = $signature;
  134 + }
  135 +
  136 + /**
  137 + * @return string
  138 + */
  139 + public function getPath(): string
  140 + {
  141 + return $this->path;
  142 + }
  143 +
  144 + /**
  145 + * @param string $path
  146 + */
  147 + public function setPath(string $path): void
  148 + {
  149 + $this->path = $path;
  150 + }
  151 +}
  152 +
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Exception;
  4 +
  5 +class ClientException extends \Exception
  6 +{
  7 +
  8 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Exception;
  4 +
  5 +class MockException extends \Exception
  6 +{
  7 +
  8 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Exception;
  4 +
  5 +class RetryException extends ClientException
  6 +{
  7 +
  8 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Facade;
  4 +
  5 +use Illuminate\Support\Facades\Facade;
  6 +use Lackoxygen\TiktokShop\Passage\Alliance\Alliance;
  7 +use Lackoxygen\TiktokShop\Passage\Authorize;
  8 +use Lackoxygen\TiktokShop\Passage\Order\OrderInterface;
  9 +use Lackoxygen\TiktokShop\Passage\Product\ProductInterface;
  10 +use Lackoxygen\TiktokShop\Passage\Shop\ShopInterface;
  11 +use Lackoxygen\TiktokShop\Passage\Verify;
  12 +
  13 +/**
  14 + * @method static OrderInterface order()
  15 + * @method static ShopInterface shop()
  16 + * @method static ProductInterface product()
  17 + * @method static Authorize authorize()
  18 + * @method static Verify verify()
  19 + * @method static Alliance alliance()
  20 + */
  21 +class TiktokShop extends Facade
  22 +{
  23 + /**
  24 + * @return string
  25 + */
  26 + protected static function getFacadeAccessor(): string
  27 + {
  28 + return \Lackoxygen\TiktokShop\TiktokShop::class;
  29 + }
  30 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Mock;
  4 +
  5 +use Lackoxygen\TiktokShop\Util\Preg;
  6 +
  7 +class Annotation
  8 +{
  9 + public function method($class, $method): array
  10 + {
  11 + $ref = new \ReflectionClass($class);
  12 +
  13 + $interfaces = $ref->getInterfaces();
  14 +
  15 + /**
  16 + * @var \ReflectionClass $interface
  17 + */
  18 + $interface = array_shift($interfaces);
  19 +
  20 + if (is_null($interface)) {
  21 + return [];
  22 + }
  23 +
  24 + $method = $interface->getMethod($method);
  25 +
  26 + $docs = $method->getDocComment();
  27 +
  28 + $docsItems = Preg::annotation($docs);
  29 +
  30 + if (!$docsItems) {
  31 + return [];
  32 + }
  33 +
  34 + $docsArray = [];
  35 +
  36 + foreach ($docsItems as $item) {
  37 + $line = Preg::mergeSpaces($item);
  38 +
  39 + $lineParts = explode(' ', $line);
  40 +
  41 + $key = array_shift($lineParts);
  42 +
  43 + $docsArray[$key] = $lineParts;
  44 + }
  45 +
  46 + return $docsArray;
  47 + }
  48 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Mock;
  4 +
  5 +use App\Pkgs\TiktokShop\Attribute\Config;
  6 +use App\Pkgs\TiktokShop\Attribute\Request;
  7 +use App\Pkgs\TiktokShop\Exception\ClientException;
  8 +use App\Pkgs\TiktokShop\Exception\MockException;
  9 +use App\Pkgs\TiktokShop\Utils\Json;
  10 +use GuzzleHttp\Client;
  11 +use GuzzleHttp\Exception\GuzzleException;
  12 +use GuzzleHttp\Psr7\Response;
  13 +use GuzzleHttp\RequestOptions;
  14 +use Illuminate\Support\Arr;
  15 +
  16 +class Mock
  17 +{
  18 + protected string $passage, $method;
  19 +
  20 + protected Annotation $annotation;
  21 +
  22 + public function __construct(string $passage, string $method)
  23 + {
  24 + $this->passage = $passage;
  25 + $this->method = $method;
  26 +
  27 + $this->annotation = new Annotation;
  28 + }
  29 +
  30 +
  31 + /**
  32 + * @param string $url
  33 + * @return Response
  34 + * @throws ClientException
  35 + * @throws MockException
  36 + */
  37 + protected function request(string $url): Response
  38 + {
  39 + if (empty($url)) {
  40 + throw new MockException('Unable to simulate data, no document address provided');
  41 + }
  42 + $pathInfo = parse_url($url, PHP_URL_PATH);
  43 +
  44 + $pathParts = explode('/', $pathInfo);
  45 +
  46 + $articleId = end($pathParts);
  47 +
  48 + $client = new Client([
  49 + 'base_uri' => 'https://op.jinritemai.com'
  50 + ]);
  51 +
  52 + try {
  53 + $response = $client->get('doc/external/open/queryDocArticleDetail', [
  54 + RequestOptions::QUERY => [
  55 + 'articleId' => $articleId,
  56 + 'onlyView' => false
  57 + ]
  58 + ]);
  59 + } catch (GuzzleException $e) {
  60 + throw new ClientException($e);
  61 + }
  62 +
  63 + $content = $response->getBody()->getContents();
  64 +
  65 + $array = Json::unmarshal($content);
  66 +
  67 + if (0 !== $array['code']) {
  68 + throw new MockException(sprintf('Abnormal response error, %s', $array['message']));
  69 + }
  70 +
  71 + $articleContent = Json::unmarshal($array['data']['article']['content']);
  72 +
  73 + return new Response(
  74 + 200,
  75 + ['server' => 'mock', 'version' => $array['data']['article']['info']['version']],
  76 + new Stream($articleContent['demo']['responseDemo']['responseSuccess'])
  77 + );
  78 + }
  79 +
  80 + public function response(): Response
  81 + {
  82 + $methodAnnotation = $this->annotation->method(
  83 + $this->passage,
  84 + $this->method
  85 + );
  86 +
  87 + $url = $this->extractUrlAnnotation(
  88 + $methodAnnotation
  89 + );
  90 +
  91 + try {
  92 + $response = $this->request($url);
  93 + } catch (ClientException|MockException $e) {
  94 + return new Response(
  95 + 500,
  96 + ['server' => 'mock'],
  97 + new Stream($e->getMessage())
  98 + );
  99 + }
  100 +
  101 + return $response;
  102 + }
  103 +
  104 + protected function extractUrlAnnotation(array $methodAnnotation)
  105 + {
  106 + $tag = '@link';
  107 +
  108 + $line = $methodAnnotation[$tag] ?? [];
  109 +
  110 + return $line ? $line[0] : false;
  111 + }
  112 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Mock;
  4 +
  5 +use Lackoxygen\TiktokShop\Util\Json;
  6 +
  7 +class Stream
  8 +{
  9 + protected string $content;
  10 +
  11 + public function __construct($content)
  12 + {
  13 + if (is_array($content)) {
  14 + $content = Json::marshal($content);
  15 + }
  16 + $this->content = $content;
  17 + }
  18 +
  19 + public function __toString(): string
  20 + {
  21 + return $this->content;
  22 + }
  23 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage\Alliance;
  4 +
  5 +use Lackoxygen\TiktokShop\Passage\Passage;
  6 +
  7 +class Alliance extends Passage implements AllianceInterface
  8 +{
  9 + /**
  10 + * @inheritDoc
  11 + */
  12 + public function simplePlan(array $params)
  13 + {
  14 + $this->builder->method('POST')->params($params)->path('buyin/simplePlan')->service('buyin.simplePlan');
  15 + }
  16 +
  17 + /**
  18 + * @inheritDoc
  19 + */
  20 + public function exclusivePlan(array $params)
  21 + {
  22 + $this->builder->method('POST')->params($params)->path('buyin/exclusivePlan')->service('buyin.exclusivePlan');
  23 + }
  24 +
  25 + /**
  26 + * @inheritDoc
  27 + */
  28 + public function activitySearch(array $params)
  29 + {
  30 + $this->builder->method('POST')->params($params)->path('buyin/activitySearch')->service('buyin.activitySearch');
  31 + }
  32 +
  33 + /**
  34 + * @inheritDoc
  35 + */
  36 + public function applyActivities(array $params)
  37 + {
  38 + $this->builder->method('POST')
  39 + ->params($params)
  40 + ->path('buyin/applyActivities')
  41 + ->service('buyin.applyActivities');
  42 + }
  43 +
  44 + /**
  45 + * @inheritDoc
  46 + */
  47 + public function createOrUpdateOrienPlan(array $params)
  48 + {
  49 + $this->builder->method('POST')
  50 + ->params($params)
  51 + ->path('buyin/createOrUpdateOrienPlan')
  52 + ->service('buyin.createOrUpdateOrienPlan');
  53 + }
  54 +
  55 + /**
  56 + * @inheritDoc
  57 + */
  58 + public function orienPlanList(array $params)
  59 + {
  60 + $this->builder->method('POST')->params($params)->path('buyin/orienPlanList')->service('buyin.orienPlanList');
  61 + }
  62 +
  63 + /**
  64 + * @inheritDoc
  65 + */
  66 + public function orienPlanAuthors(array $params)
  67 + {
  68 + $this->builder->method('POST')
  69 + ->params($params)
  70 + ->path('buyin/orienPlanAuthors')
  71 + ->service('buyin.orienPlanAuthors');
  72 + }
  73 +
  74 + /**
  75 + * @inheritDoc
  76 + */
  77 + public function orienPlanCtrl(array $params)
  78 + {
  79 + $this->builder->method('POST')->params($params)->path('buyin/orienPlanCtrl')->service('buyin.orienPlanCtrl');
  80 + }
  81 +
  82 + /**
  83 + * @inheritDoc
  84 + */
  85 + public function orienPlanAuthorsAdd(array $params)
  86 + {
  87 + $this->builder->method('POST')
  88 + ->params($params)
  89 + ->path('buyin/orienPlanAuthorsAdd')
  90 + ->service('buyin.orienPlanAuthorsAdd');
  91 + }
  92 +
  93 + /**
  94 + * @inheritDoc
  95 + */
  96 + public function orienPlanAudit(array $params)
  97 + {
  98 + $this->builder->method('POST')->params($params)->path('buyin/orienPlanAudit')->service('buyin.orienPlanAudit');
  99 + }
  100 +
  101 + /**
  102 + * @inheritDoc
  103 + */
  104 + public function colonelActivityCreateOrUpdate(array $params)
  105 + {
  106 + $this->builder->method('POST')
  107 + ->params($params)
  108 + ->path('alliance/colonelActivityCreateOrUpdate')
  109 + ->service('alliance.colonelActivityCreateOrUpdate');
  110 + }
  111 +
  112 + /**
  113 + * @inheritDoc
  114 + */
  115 + public function activityProductCategoryList(array $params)
  116 + {
  117 + $this->builder->method('POST')
  118 + ->params($params)
  119 + ->path('alliance/activityProductCategoryList')
  120 + ->service('alliance.activityProductCategoryList');
  121 + }
  122 +
  123 + /**
  124 + * @inheritDoc
  125 + */
  126 + public function instituteColonelActivityList(array $params)
  127 + {
  128 + $this->builder->method('POST')
  129 + ->params($params)
  130 + ->path('alliance/instituteColonelActivityList')
  131 + ->service('alliance.instituteColonelActivityList');
  132 + }
  133 +
  134 + /**
  135 + * @inheritDoc
  136 + */
  137 + public function instituteColonelActivityOperate(array $params)
  138 + {
  139 + $this->builder->method('POST')
  140 + ->params($params)
  141 + ->path('alliance/instituteColonelActivityOperate')
  142 + ->service('alliance.instituteColonelActivityOperate');
  143 + }
  144 +
  145 + /**
  146 + * @inheritDoc
  147 + */
  148 + public function colonelActivityProduct(array $params)
  149 + {
  150 + $this->builder->method('POST')
  151 + ->params($params)
  152 + ->path('alliance/colonelActivityProduct')
  153 + ->service('alliance.colonelActivityProduct');
  154 + }
  155 +
  156 + /**
  157 + * @inheritDoc
  158 + */
  159 + public function colonelActivityProductAudit(array $params)
  160 + {
  161 + $this->builder->method('POST')
  162 + ->params($params)
  163 + ->path('alliance/colonelActivityProductAudit')
  164 + ->service('alliance.colonelActivityProductAudit');
  165 + }
  166 +
  167 + /**
  168 + * @inheritDoc
  169 + */
  170 + public function colonelActivityProductExtension(array $params)
  171 + {
  172 + $this->builder->method('POST')
  173 + ->params($params)
  174 + ->path('alliance/colonelActivityProductExtension')
  175 + ->service('alliance.colonelActivityProductExtension');
  176 + }
  177 +
  178 + /**
  179 + * @inheritDoc
  180 + */
  181 + public function specialApplyList(array $params)
  182 + {
  183 + $this->builder->method('POST')
  184 + ->params($params)
  185 + ->path('buyin.colonel/specialApplyList')
  186 + ->service('buyin.colonel.specialApplyList');
  187 + }
  188 +
  189 + /**
  190 + * @inheritDoc
  191 + */
  192 + public function specialApplyDeal(array $params)
  193 + {
  194 + $this->builder->method('POST')
  195 + ->params($params)
  196 + ->path('buyin.colonel/specialApplyDeal')
  197 + ->service('buyin.colonel.specialApplyDeal');
  198 + }
  199 +
  200 + /**
  201 + * @inheritDoc
  202 + */
  203 + public function materialsProductsSearch(array $params)
  204 + {
  205 + $this->builder->method('POST')
  206 + ->params($params)
  207 + ->path('alliance/materialsProductsSearch')
  208 + ->service('alliance.materialsProductsSearch');
  209 + }
  210 +
  211 + /**
  212 + * @inheritDoc
  213 + */
  214 + public function materialsProductsDetails(array $params)
  215 + {
  216 + $this->builder->method('POST')
  217 + ->params($params)
  218 + ->path('alliance/materialsProductsDetails')
  219 + ->service('alliance.materialsProductsDetails');
  220 + }
  221 +
  222 + /**
  223 + * @inheritDoc
  224 + */
  225 + public function materialsProductCategory(array $params)
  226 + {
  227 + $this->builder->method('POST')
  228 + ->params($params)
  229 + ->path('alliance/materialsProductCategory')
  230 + ->service('alliance.materialsProductCategory');
  231 + }
  232 +
  233 + /**
  234 + * @inheritDoc
  235 + */
  236 + public function materialsProductStatus(array $params)
  237 + {
  238 + $this->builder->method('POST')
  239 + ->params($params)
  240 + ->path('buyin/materialsProductStatus')
  241 + ->service('buyin.materialsProductStatus');
  242 + }
  243 +
  244 + /**
  245 + * @inheritDoc
  246 + */
  247 + public function queryInstituteOrders(array $params)
  248 + {
  249 + $this->builder->method('POST')
  250 + ->params($params)
  251 + ->path('buyin/queryInstituteOrders')
  252 + ->service('buyin.queryInstituteOrders');
  253 + }
  254 +
  255 + /**
  256 + * @inheritDoc
  257 + */
  258 + public function kolPidCreate(array $params)
  259 + {
  260 + $this->builder->method('POST')->params($params)->path('buyin/kolPidCreate')->service('buyin.kolPidCreate');
  261 + }
  262 +
  263 + /**
  264 + * @inheritDoc
  265 + */
  266 + public function kolPidList(array $params)
  267 + {
  268 + $this->builder->method('POST')->params($params)->path('buyin/kolPidList')->service('buyin.kolPidList');
  269 + }
  270 +
  271 + /**
  272 + * @inheritDoc
  273 + */
  274 + public function kolPidEdit(array $params)
  275 + {
  276 + $this->builder->method('POST')->params($params)->path('buyin/kolPidEdit')->service('buyin.kolPidEdit');
  277 + }
  278 +
  279 + /**
  280 + * @inheritDoc
  281 + */
  282 + public function kolPidDel(array $params)
  283 + {
  284 + $this->builder->method('POST')->params($params)->path('buyin/kolPidDel')->service('buyin.kolPidDel');
  285 + }
  286 +
  287 + /**
  288 + * @inheritDoc
  289 + */
  290 + public function kolProductShare(array $params)
  291 + {
  292 + $this->builder->method('POST')
  293 + ->params($params)
  294 + ->path('buyin/kolProductShare')
  295 + ->service('buyin.kolProductShare');
  296 + }
  297 +
  298 + /**
  299 + * @inheritDoc
  300 + */
  301 + public function institutePidCreate(array $params)
  302 + {
  303 + $this->builder->method('POST')
  304 + ->params($params)
  305 + ->path('buyin/institutePidCreate')
  306 + ->service('buyin.institutePidCreate');
  307 + }
  308 +
  309 + /**
  310 + * @inheritDoc
  311 + */
  312 + public function institutePidList(array $params)
  313 + {
  314 + $this->builder->method('POST')
  315 + ->params($params)
  316 + ->path('buyin/institutePidList')
  317 + ->service('buyin.institutePidList');
  318 + }
  319 +
  320 + /**
  321 + * @inheritDoc
  322 + */
  323 + public function institutePidEdit(array $params)
  324 + {
  325 + $this->builder->method('POST')
  326 + ->params($params)
  327 + ->path('buyin/institutePidEdit')
  328 + ->service('buyin.institutePidEdit');
  329 + }
  330 +
  331 + /**
  332 + * @inheritDoc
  333 + */
  334 + public function institutePidDel(array $params)
  335 + {
  336 + $this->builder->method('POST')
  337 + ->params($params)
  338 + ->path('buyin/institutePidDel')
  339 + ->service('buyin.institutePidDel');
  340 + }
  341 +
  342 + /**
  343 + * @inheritDoc
  344 + */
  345 + public function liveShareMaterial(array $params)
  346 + {
  347 + $this->builder->method('POST')
  348 + ->params($params)
  349 + ->path('buyin/liveShareMaterial')
  350 + ->service('buyin.liveShareMaterial');
  351 + }
  352 +
  353 + /**
  354 + * @inheritDoc
  355 + */
  356 + public function instituteLiveShare(array $params)
  357 + {
  358 + $this->builder->method('POST')
  359 + ->params($params)
  360 + ->path('buyin/instituteLiveShare')
  361 + ->service('buyin.instituteLiveShare');
  362 + }
  363 +
  364 + /**
  365 + * @inheritDoc
  366 + */
  367 + public function instituteOrderAds(array $params)
  368 + {
  369 + $this->builder->method('POST')
  370 + ->params($params)
  371 + ->path('buyin/instituteOrderAds')
  372 + ->service('buyin.instituteOrderAds');
  373 + }
  374 +
  375 + /**
  376 + * @inheritDoc
  377 + */
  378 + public function kolOrderAds(array $params)
  379 + {
  380 + $this->builder->method('POST')->params($params)->path('buyin/kolOrderAds')->service('buyin.kolOrderAds');
  381 + }
  382 +
  383 + /**
  384 + * @inheritDoc
  385 + */
  386 + public function shopPidMemberCreate(array $params)
  387 + {
  388 + $this->builder->method('POST')
  389 + ->params($params)
  390 + ->path('buyin/shopPidMemberCreate')
  391 + ->service('buyin.shopPidMemberCreate');
  392 + }
  393 +
  394 + /**
  395 + * @inheritDoc
  396 + */
  397 + public function kolMaterialsProductsDetails(array $params)
  398 + {
  399 + $this->builder->method('POST')
  400 + ->params($params)
  401 + ->path('buyin/kolMaterialsProductsDetails')
  402 + ->service('buyin.kolMaterialsProductsDetails');
  403 + }
  404 +
  405 + /**
  406 + * @inheritDoc
  407 + */
  408 + public function getProductShareMaterial(array $params)
  409 + {
  410 + $this->builder->method('POST')
  411 + ->params($params)
  412 + ->path('buyin/getProductShareMaterial')
  413 + ->service('buyin.getProductShareMaterial');
  414 + }
  415 +
  416 + /**
  417 + * @inheritDoc
  418 + */
  419 + public function getProductSkus(array $params)
  420 + {
  421 + $this->builder->method('POST')->params($params)->path('buyin/productSkus')->service('buyin.productSkus');
  422 + }
  423 +
  424 + /**
  425 + * @inheritDoc
  426 + */
  427 + public function shareCommandParse(array $params)
  428 + {
  429 + $this->builder->method('POST')
  430 + ->params($params)
  431 + ->path('buyin/shareCommandParse')
  432 + ->service('buyin.shareCommandParse');
  433 + }
  434 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage\Alliance;
  4 +
  5 +use Lackoxygen\TiktokShop\Passage\ResultSet;
  6 +
  7 +interface AllianceInterface
  8 +{
  9 + /**
  10 + * @link https://op.jinritemai.com/docs/api-docs/61/923
  11 + * @param array $params
  12 + * @return ResultSet
  13 + */
  14 + public function simplePlan(array $params);
  15 +
  16 + /**
  17 + * @link https://op.jinritemai.com/docs/api-docs/61/922
  18 + * @param array $params
  19 + * @return ResultSet
  20 + */
  21 + public function exclusivePlan(array $params);
  22 +
  23 + /**
  24 + * @link https://op.jinritemai.com/docs/api-docs/61/743
  25 + * @param array $params
  26 + * @return ResultSet
  27 + */
  28 + public function activitySearch(array $params);
  29 +
  30 + /**
  31 + * @link https://op.jinritemai.com/docs/api-docs/61/744
  32 + * @param array $params
  33 + * @return ResultSet
  34 + */
  35 + public function applyActivities(array $params);
  36 +
  37 + /**
  38 + * @link https://op.jinritemai.com/docs/api-docs/61/708
  39 + * @param array $params
  40 + * @return ResultSet
  41 + */
  42 + public function createOrUpdateOrienPlan(array $params);
  43 +
  44 + /**
  45 + * @link https://op.jinritemai.com/docs/api-docs/61/705
  46 + * @param array $params
  47 + * @return ResultSet
  48 + */
  49 + public function orienPlanList(array $params);
  50 +
  51 + /**
  52 + * @link https://op.jinritemai.com/docs/api-docs/61/709
  53 + * @param array $params
  54 + * @return ResultSet
  55 + */
  56 + public function orienPlanAuthors(array $params);
  57 +
  58 + /**
  59 + * @link https://op.jinritemai.com/docs/api-docs/61/706
  60 + * @param array $params
  61 + * @return ResultSet
  62 + */
  63 + public function orienPlanCtrl(array $params);
  64 +
  65 + /**
  66 + * @link https://op.jinritemai.com/docs/api-docs/61/706
  67 + * @param array $params
  68 + * @return ResultSet
  69 + */
  70 + public function orienPlanAuthorsAdd(array $params);
  71 +
  72 + /**
  73 + * @link https://op.jinritemai.com/docs/api-docs/61/707
  74 + * @param array $params
  75 + * @return ResultSet
  76 + */
  77 + public function orienPlanAudit(array $params);
  78 +
  79 + /**
  80 + * @link https://op.jinritemai.com/docs/api-docs/61/966
  81 + * @param array $params
  82 + * @return ResultSet
  83 + */
  84 + public function colonelActivityCreateOrUpdate(array $params);
  85 +
  86 + /**
  87 + * @link https://op.jinritemai.com/docs/api-docs/61/970
  88 + * @param array $params
  89 + * @return ResultSet
  90 + */
  91 + public function activityProductCategoryList(array $params);
  92 +
  93 + /**
  94 + * @link https://op.jinritemai.com/docs/api-docs/61/1330
  95 + * @param array $params
  96 + * @return ResultSet
  97 + */
  98 + public function instituteColonelActivityList(array $params);
  99 +
  100 + /**
  101 + * @link https://op.jinritemai.com/docs/api-docs/61/972
  102 + * @param array $params
  103 + * @return ResultSet
  104 + */
  105 + public function instituteColonelActivityOperate(array $params);
  106 +
  107 + /**
  108 + * @link https://op.jinritemai.com/docs/api-docs/61/968
  109 + * @param array $params
  110 + * @return ResultSet
  111 + */
  112 + public function colonelActivityProduct(array $params);
  113 +
  114 + /**
  115 + * @link https://op.jinritemai.com/docs/api-docs/61/971
  116 + * @param array $params
  117 + * @return ResultSet
  118 + */
  119 + public function colonelActivityProductAudit(array $params);
  120 +
  121 + /**
  122 + * @link https://op.jinritemai.com/docs/api-docs/61/967
  123 + * @param array $params
  124 + * @return ResultSet
  125 + */
  126 + public function colonelActivityProductExtension(array $params);
  127 +
  128 + /**
  129 + * @link https://op.jinritemai.com/docs/api-docs/61/1552
  130 + * @param array $params
  131 + * @return ResultSet
  132 + */
  133 + public function specialApplyList(array $params);
  134 +
  135 + /**
  136 + * @link https://op.jinritemai.com/docs/api-docs/61/1553
  137 + * @param array $params
  138 + * @return ResultSet
  139 + */
  140 + public function specialApplyDeal(array $params);
  141 +
  142 + /**
  143 + * @link https://op.jinritemai.com/docs/api-docs/61/924
  144 + * @param array $params
  145 + * @return ResultSet
  146 + */
  147 + public function materialsProductsSearch(array $params);
  148 +
  149 + /**
  150 + * @link https://op.jinritemai.com/docs/api-docs/61/1356
  151 + * @param array $params
  152 + * @return ResultSet
  153 + */
  154 + public function materialsProductsDetails(array $params);
  155 +
  156 + /**
  157 + * @link https://op.jinritemai.com/docs/api-docs/61/637
  158 + * @param array $params
  159 + * @return ResultSet
  160 + */
  161 + public function materialsProductCategory(array $params);
  162 +
  163 + /**
  164 + * @link https://op.jinritemai.com/docs/api-docs/61/1497
  165 + * @param array $params
  166 + * @return ResultSet
  167 + */
  168 + public function materialsProductStatus(array $params);
  169 +
  170 + /**
  171 + * @link https://op.jinritemai.com/docs/api-docs/61/1398
  172 + * @param array $params
  173 + * @return ResultSet
  174 + */
  175 + public function queryInstituteOrders(array $params);
  176 +
  177 + /**
  178 + * @link https://op.jinritemai.com/docs/api-docs/61/1460
  179 + * @param array $params
  180 + * @return ResultSet
  181 + */
  182 + public function kolPidCreate(array $params);
  183 +
  184 + /**
  185 + * @link https://op.jinritemai.com/docs/api-docs/61/1461
  186 + * @param array $params
  187 + * @return ResultSet
  188 + */
  189 + public function kolPidList(array $params);
  190 +
  191 + /**
  192 + * @link https://op.jinritemai.com/docs/api-docs/61/1462
  193 + * @param array $params
  194 + * @return ResultSet
  195 + */
  196 + public function kolPidEdit(array $params);
  197 +
  198 + /**
  199 + * @link https://op.jinritemai.com/docs/api-docs/61/1463
  200 + * @param array $params
  201 + * @return ResultSet
  202 + */
  203 + public function kolPidDel(array $params);
  204 +
  205 + /**
  206 + * @link https://op.jinritemai.com/docs/api-docs/61/1464
  207 + * @param array $params
  208 + * @return ResultSet
  209 + */
  210 + public function kolProductShare(array $params);
  211 +
  212 + /**
  213 + * @link https://op.jinritemai.com/docs/api-docs/61/1273
  214 + * @param array $params
  215 + * @return ResultSet
  216 + */
  217 + public function institutePidCreate(array $params);
  218 +
  219 + /**
  220 + * @link https://op.jinritemai.com/docs/api-docs/61/1269
  221 + * @param array $params
  222 + * @return ResultSet
  223 + */
  224 + public function institutePidList(array $params);
  225 +
  226 + /**
  227 + * @link https://op.jinritemai.com/docs/api-docs/61/1270
  228 + * @param array $params
  229 + * @return ResultSet
  230 + */
  231 + public function institutePidEdit(array $params);
  232 +
  233 + /**
  234 + * @link https://op.jinritemai.com/docs/api-docs/61/1271
  235 + * @param array $params
  236 + * @return ResultSet
  237 + */
  238 + public function institutePidDel(array $params);
  239 +
  240 + /**
  241 + * @link https://op.jinritemai.com/docs/api-docs/61/1396
  242 + * @param array $params
  243 + * @return ResultSet
  244 + */
  245 + public function liveShareMaterial(array $params);
  246 +
  247 + /**
  248 + * @link https://op.jinritemai.com/docs/api-docs/61/1297
  249 + * @param array $params
  250 + * @return ResultSet
  251 + */
  252 + public function instituteLiveShare(array $params);
  253 +
  254 + /**
  255 + * @link https://op.jinritemai.com/docs/api-docs/61/1296
  256 + * @param array $params
  257 + * @return ResultSet
  258 + */
  259 + public function instituteOrderAds(array $params);
  260 +
  261 + /**
  262 + * @link https://op.jinritemai.com/docs/api-docs/61/1459
  263 + * @param array $params
  264 + * @return ResultSet
  265 + */
  266 + public function kolOrderAds(array $params);
  267 +
  268 + /**
  269 + * @link https://op.jinritemai.com/docs/api-docs/61/1493
  270 + * @param array $params
  271 + * @return ResultSet
  272 + */
  273 + public function shopPidMemberCreate(array $params);
  274 +
  275 + /**
  276 + * @link https://op.jinritemai.com/docs/api-docs/61/1589
  277 + * @param array $params
  278 + * @return ResultSet
  279 + */
  280 + public function kolMaterialsProductsDetails(array $params);
  281 +
  282 + /**
  283 + * @link https://op.jinritemai.com/docs/api-docs/61/1588
  284 + * @param array $params
  285 + * @return ResultSet
  286 + */
  287 + public function getProductShareMaterial(array $params);
  288 +
  289 + /**
  290 + * @link https://op.jinritemai.com/docs/api-docs/61/1626
  291 + * @param array $params
  292 + * @return mixed
  293 + */
  294 + public function getProductSkus(array $params);
  295 +
  296 + /**
  297 + * @link https://op.jinritemai.com/docs/api-docs/61/1726
  298 + * @param array $params
  299 + * @return mixed
  300 + */
  301 + public function shareCommandParse(array $params);
  302 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage;
  4 +
  5 +use Illuminate\Support\Arr;
  6 +
  7 +class Authorize extends Passage
  8 +{
  9 + /**
  10 + * @param string $code
  11 + * @param string $grantType {authorization_self, authorization_code}
  12 + * @param bool $sandbox
  13 + * @return ResultSet
  14 + */
  15 + public function token(string $code, string $grantType = 'authorization_code', bool $sandbox = false)
  16 + {
  17 + $params = ['code' => $code, 'grant_type' => $grantType];
  18 + if ($sandbox) {
  19 + if ($grantType === 'authorization_self') {
  20 + if ($code == '4463798') {
  21 + Arr::set($params, 'test_shop', 1);
  22 + } else {
  23 + Arr::set($params, 'shop_id', $code);
  24 + }
  25 + }
  26 + }
  27 + $this->builder->service('token.create');
  28 + $this->builder
  29 + ->method('GET')
  30 + ->path('/token/create')
  31 + ->service('token.create')
  32 + ->params($params);
  33 + }
  34 +
  35 + /**
  36 + * @param string $refreshToken
  37 + * @param string $grantType
  38 + * @return ResultSet
  39 + */
  40 + public function refresh(string $refreshToken, string $grantType = 'refresh_token')
  41 + {
  42 + $this->builder
  43 + ->method('POST')
  44 + ->service('token.refresh')
  45 + ->params(['refresh_token' => $refreshToken, 'grant_type' => $grantType]);
  46 + }
  47 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage\Order;
  4 +
  5 +use Lackoxygen\TiktokShop\Passage\Passage;
  6 +
  7 +class Order extends Passage implements OrderInterface
  8 +{
  9 + /**
  10 + * @inheritDoc
  11 + */
  12 + public function searchList(array $params)
  13 + {
  14 + $this->builder->method('POST')->service('order.searchList')->path('/order/searchList')->params($params);
  15 + }
  16 +
  17 + /**
  18 + * @inheritDoc
  19 + */
  20 + public function orderDetail(array $params)
  21 + {
  22 + $this->builder->method('POST')->service('order.orderDetail')->path('/order/orderDetail')->params($params);
  23 + }
  24 +
  25 + /**
  26 + * @inheritDoc
  27 + */
  28 + public function batchDecrypt(array $params)
  29 + {
  30 + $this->builder->method('POST')->service('order.batchDecrypt')->path('/order/batchDecrypt')->params($params);
  31 + }
  32 +
  33 + /**
  34 + * @inheritDoc
  35 + */
  36 + public function addOrderRemark(array $params)
  37 + {
  38 + $this->builder->method('POST')->service('order.addOrderRemark')->path('/order/addOrderRemark')->params($params);
  39 + }
  40 +
  41 + /**
  42 + * @inheritDoc
  43 + */
  44 + public function updatePostAmount(array $params)
  45 + {
  46 + $this->builder->method('POST')
  47 + ->service('order.updatePostAmount')
  48 + ->path('/order/updatePostAmount')
  49 + ->params($params);
  50 + }
  51 +
  52 + /**
  53 + * @inheritDoc
  54 + */
  55 + public function addressAppliedSwitch(array $params)
  56 + {
  57 + $this->builder->method('POST')
  58 + ->service('order.AddressAppliedSwitch')
  59 + ->path('/order/AddressAppliedSwitch')
  60 + ->params($params);
  61 + }
  62 +
  63 + /**
  64 + * @inheritDoc
  65 + */
  66 + public function updateOrderAmount(array $params)
  67 + {
  68 + $this->builder->method('POST')->service('order.updateOrderAmount')->path('')->params($params);
  69 + }
  70 +
  71 + public function addressConfirm(array $params)
  72 + {
  73 + $this->builder->method('POST')->service('order.addressConfirm')->params($params);
  74 + }
  75 +
  76 + /**
  77 + * @inheritDoc
  78 + */
  79 + public function addressModify(array $params)
  80 + {
  81 + $this->builder->method('POST')->service('order.addressModify')->params($params);
  82 + }
  83 +
  84 + /**
  85 + * @inheritDoc
  86 + */
  87 + public function addressSwitchConfig(array $params)
  88 + {
  89 + $this->builder->method('POST')->service('order.addresSwitchConfig')->params($params);
  90 + }
  91 +
  92 + /**
  93 + * @inheritDoc
  94 + */
  95 + public function invoiceList(array $params)
  96 + {
  97 + $this->builder->method('POST')->service('order.invoiceList')->params($params);
  98 + }
  99 +
  100 + /**
  101 + * @inheritDoc
  102 + */
  103 + public function batchEncrypt(array $params)
  104 + {
  105 + $this->builder->method('POST')->service('order.batchEncrypt')->params($params);
  106 + }
  107 +
  108 + /**
  109 + * @inheritDoc
  110 + */
  111 + public function batchSensitive(array $params)
  112 + {
  113 + $this->builder->method('POST')->service('order.batchSensitive')->params($params);
  114 + }
  115 +
  116 + public function invoiceUpload(array $params)
  117 + {
  118 + $this->builder->method('POST')->service('order.stockUp')->params($params);
  119 + }
  120 +
  121 + /**
  122 + * @inheritDoc
  123 + */
  124 + public function batchSearchIndex(array $params)
  125 + {
  126 + $this->builder->method('POST')->service('order.BatchSearchIndex')->params($params);
  127 + }
  128 +
  129 + /**
  130 + * @inheritDoc
  131 + */
  132 + public function antispamOrderSend(array $params)
  133 + {
  134 + $this->builder->method('POST')->service('antispam.orderSend')->params($params);
  135 + }
  136 +
  137 + /**
  138 + * @inheritDoc
  139 + */
  140 + public function antispamOrderQuery(array $params)
  141 + {
  142 + $this->builder->method('POST')->service('antispam.orderQuery')->params($params);
  143 + }
  144 +
  145 + /**
  146 + * @inheritDoc
  147 + */
  148 + public function getCrossBorderFulfillInfo(array $params)
  149 + {
  150 + $this->builder->method('POST')->service('order.getCrossBorderFulfillInfo')->params($params);
  151 + }
  152 +
  153 + /**
  154 + * @inheritDoc
  155 + */
  156 + public function getServiceList(array $params)
  157 + {
  158 + $this->builder->method('POST')->service('order.getServiceList')->params($params);
  159 + }
  160 +
  161 + /**
  162 + * @inheritDoc
  163 + */
  164 + public function addSerialNumber(array $params)
  165 + {
  166 + $this->builder->method('POST')->service('order.addSerialNumber')->params($params);
  167 + }
  168 +
  169 + /**
  170 + * @inheritDoc
  171 + */
  172 + public function replyService(array $params)
  173 + {
  174 + $this->builder->method('POST')->service('order.replyService')->params($params);
  175 + }
  176 +
  177 + /**
  178 + * @inheritDoc
  179 + */
  180 + public function serviceDetail(array $params)
  181 + {
  182 + $this->builder->method('POST')->service('order.serviceDetail')->params($params);
  183 + }
  184 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage\Order;
  4 +
  5 +use Lackoxygen\TiktokShop\Passage\ResultSet;
  6 +
  7 +/**
  8 + * @link https://op.jinritemai.com/docs/api-docs/15/1343
  9 + */
  10 +interface OrderInterface
  11 +{
  12 + /**
  13 + * @link https://op.jinritemai.com/docs/api-docs/15/1342
  14 + * @param array $params
  15 + * @return ResultSet
  16 + */
  17 + public function searchList(array $params);
  18 +
  19 + /**
  20 + * @link https://op.jinritemai.com/docs/api-docs/15/1343
  21 + * @param array $params
  22 + * @return ResultSet
  23 + */
  24 + public function orderDetail(array $params);
  25 +
  26 + /**
  27 + * @link https://op.jinritemai.com/docs/api-docs/15/982
  28 + * @param array $params
  29 + * @return ResultSet
  30 + */
  31 + public function batchDecrypt(array $params);
  32 +
  33 + /**
  34 + * @link https://op.jinritemai.com/docs/api-docs/15/568
  35 + * @param array $params
  36 + * @return ResultSet
  37 + */
  38 + public function addOrderRemark(array $params);
  39 +
  40 + /**
  41 + * @link https://op.jinritemai.com/docs/api-docs/15/264
  42 + * @param array $params
  43 + * @return ResultSet
  44 + */
  45 + public function updatePostAmount(array $params);
  46 +
  47 + /**
  48 + * @link https://op.jinritemai.com/docs/api-docs/15/500
  49 + * @param array $params
  50 + * @return ResultSet
  51 + */
  52 + public function addressAppliedSwitch(array $params);
  53 +
  54 + /**
  55 + * @link https://op.jinritemai.com/docs/api-docs/15/263
  56 + * @param array $params
  57 + * @return ResultSet
  58 + */
  59 + public function updateOrderAmount(array $params);
  60 +
  61 + /**
  62 + * @link https://op.jinritemai.com/docs/api-docs/15/505
  63 + * @param array $params
  64 + * @return ResultSet
  65 + */
  66 + public function addressConfirm(array $params);
  67 +
  68 + /**
  69 + * @link https://op.jinritemai.com/docs/api-docs/15/290
  70 + * @param array $params
  71 + * @return ResultSet
  72 + */
  73 + public function addressModify(array $params);
  74 +
  75 + /**
  76 + * @link https://op.jinritemai.com/docs/api-docs/15/501
  77 + * @param array $params
  78 + * @return ResultSet
  79 + */
  80 + public function addressSwitchConfig(array $params);
  81 +
  82 + /**
  83 + * @link https://op.jinritemai.com/docs/api-docs/15/660
  84 + * @param array $params
  85 + * @return ResultSet
  86 + */
  87 + public function invoiceList(array $params);
  88 +
  89 + /**
  90 + * @link https://op.jinritemai.com/docs/api-docs/15/487
  91 + * @param array $params
  92 + * @return ResultSet
  93 + */
  94 + public function batchEncrypt(array $params);
  95 +
  96 + /**
  97 + * @link https://op.jinritemai.com/docs/api-docs/15/508
  98 + * @param array $params
  99 + * @return ResultSet
  100 + */
  101 + public function batchSensitive(array $params);
  102 +
  103 + /**
  104 + * @link https://op.jinritemai.com/docs/api-docs/15/892
  105 + * @param array $params
  106 + * @return ResultSet
  107 + */
  108 + public function invoiceUpload(array $params);
  109 +
  110 + /**
  111 + * @link https://op.jinritemai.com/docs/api-docs/15/516
  112 + * @param array $params
  113 + * @return ResultSet
  114 + */
  115 + public function batchSearchIndex(array $params);
  116 +
  117 + /**
  118 + * @link https://op.jinritemai.com/docs/api-docs/15/649
  119 + * @param array $params
  120 + * @return ResultSet
  121 + */
  122 + public function antispamOrderSend(array $params);
  123 +
  124 + /**
  125 + * @link https://op.jinritemai.com/docs/api-docs/15/650
  126 + * @param array $params
  127 + * @return ResultSet
  128 + */
  129 + public function antispamOrderQuery(array $params);
  130 +
  131 + /**
  132 + * @link https://op.jinritemai.com/docs/api-docs/15/495
  133 + * @param array $params
  134 + * @return ResultSet
  135 + */
  136 + public function getCrossBorderFulfillInfo(array $params);
  137 +
  138 + /**
  139 + * @link https://op.jinritemai.com/docs/api-docs/15/266
  140 + * @param array $params
  141 + * @return ResultSet
  142 + */
  143 + public function getServiceList(array $params);
  144 +
  145 + /**
  146 + * @link https://op.jinritemai.com/docs/api-docs/15/1289
  147 + * @param array $params
  148 + * @return ResultSet
  149 + */
  150 + public function addSerialNumber(array $params);
  151 +
  152 + /**
  153 + * @link https://op.jinritemai.com/docs/api-docs/15/75
  154 + * @param array $params
  155 + * @return ResultSet
  156 + */
  157 + public function replyService(array $params);
  158 +
  159 + /**
  160 + * @link https://op.jinritemai.com/docs/api-docs/15/253
  161 + * @param array $params
  162 + * @return ResultSet
  163 + */
  164 + public function serviceDetail(array $params);
  165 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage;
  4 +
  5 +use Lackoxygen\TiktokShop\Attribute\Config;
  6 +use Lackoxygen\TiktokShop\Exception\ClientException;
  7 +use Lackoxygen\TiktokShop\Transmit\Builder;
  8 +
  9 +abstract class Passage
  10 +{
  11 + protected Config $config;
  12 +
  13 + protected Builder $builder;
  14 +
  15 + /**
  16 + * @param Config $config
  17 + * @param string $method
  18 + */
  19 + public function __construct(Config $config, string $method)
  20 + {
  21 + $this->config = $config;
  22 + $this->builder = Builder::create($config, get_class($this), $method);
  23 + }
  24 +
  25 + /**
  26 + * @return \Psr\Http\Message\ResponseInterface
  27 + * @throws ClientException
  28 + */
  29 + public function __invoke(): \Psr\Http\Message\ResponseInterface
  30 + {
  31 + return $this->builder->request();
  32 + }
  33 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage;
  4 +
  5 +use Lackoxygen\TiktokShop\Attribute\Config;
  6 +use Lackoxygen\TiktokShop\Exception\{ClientException, ExpiredException};
  7 +
  8 +class PassageProxy
  9 +{
  10 + protected string $passage;
  11 +
  12 + protected Config $config;
  13 +
  14 + protected function __construct(string $passage, Config $config)
  15 + {
  16 + $this->passage = $passage;
  17 +
  18 + $this->config = $config;
  19 + }
  20 +
  21 + public static function proxy(string $passage, Config $config): PassageProxy
  22 + {
  23 + return new self($passage, $config);
  24 + }
  25 +
  26 + /**
  27 + * @throws ClientException
  28 + * @throws ExpiredException
  29 + */
  30 + public function __call($name, $arguments): ResultSet
  31 + {
  32 + /**
  33 + * @var Passage $passage
  34 + */
  35 + $passage = new $this->passage($this->config, $name);
  36 +
  37 + $result = call_user_func_array([$passage, $name], $arguments);
  38 +
  39 + if (!is_null($result)) {
  40 + return new ResultSet($result);
  41 + }
  42 +
  43 + return new ResultSet($passage());
  44 + }
  45 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage\Product;
  4 +
  5 +use Lackoxygen\TiktokShop\Passage\Passage;
  6 +
  7 +class Product extends Passage implements ProductInterface
  8 +{
  9 + /**
  10 + * @inheritDoc
  11 + */
  12 + public function listV2(array $params)
  13 + {
  14 + $this->builder->method('POST')->service('product.listV2')->params($params);
  15 + }
  16 +
  17 + /**
  18 + * @inheritDoc
  19 + */
  20 + public function getCateProperty(array $params)
  21 + {
  22 + $this->builder->method('POST')->service('product.getCateProperty')->params($params);
  23 + }
  24 +
  25 + /**
  26 + * @inheritDoc
  27 + */
  28 + public function addV2(array $params)
  29 + {
  30 + $this->builder->method('POST')->service('product.addV2')->params($params);
  31 + }
  32 +
  33 + /**
  34 + * @inheritDoc
  35 + */
  36 + public function editV2(array $params)
  37 + {
  38 + $this->builder->method('POST')->service('product.editV2')->params($params);
  39 + }
  40 +
  41 + /**
  42 + * @inheritDoc
  43 + */
  44 + public function detail(array $params)
  45 + {
  46 + $this->builder->method('POST')->service('product.detail')->params($params);
  47 + }
  48 +
  49 + /**
  50 + * @inheritDoc
  51 + */
  52 + public function del(array $params)
  53 + {
  54 + $this->builder->method('POST')->service('product.del')->params($params);
  55 + }
  56 +
  57 + /**
  58 + * @inheritDoc
  59 + */
  60 + public function skuDetail(array $params)
  61 + {
  62 + $this->builder->method('POST')->service('sku.detail')->params($params);
  63 + }
  64 +
  65 + /**
  66 + * @inheritDoc
  67 + */
  68 + public function freightTemplateList(array $params)
  69 + {
  70 + $this->builder->method('POST')->service('freightTemplate.list')->params($params);
  71 + }
  72 +
  73 + /**
  74 + * @inheritDoc
  75 + */
  76 + public function brandList(array $params)
  77 + {
  78 + $this->builder->method('POST')->service('brand.list')->params($params);
  79 + }
  80 +
  81 + /**
  82 + * @inheritDoc
  83 + */
  84 + public function getCatePropertyV2(array $params)
  85 + {
  86 + $this->builder->method('POST')->service('product.getCatePropertyV2')->params($params);
  87 + }
  88 +
  89 + /**
  90 + * @inheritDoc
  91 + */
  92 + public function setOnline(array $params)
  93 + {
  94 + $this->builder->method('POST')->service('product.setOnline')->params($params);
  95 + }
  96 +
  97 + /**
  98 + * @inheritDoc
  99 + */
  100 + public function skuList(array $params)
  101 + {
  102 + $this->builder->method('POST')->service('sku.list')->params($params);
  103 + }
  104 +
  105 + /**
  106 + * @inheritDoc
  107 + */
  108 + public function skuSyncStockBatch(array $params)
  109 + {
  110 + $this->builder->method('POST')->service('sku.syncStockBatch')->params($params);
  111 + }
  112 +
  113 + /**
  114 + * @inheritDoc
  115 + */
  116 + public function setOffline(array $params)
  117 + {
  118 + $this->builder->method('POST')->service('product.setOffline')->params($params);
  119 + }
  120 +
  121 + /**
  122 + * @inheritDoc
  123 + */
  124 + public function qualityList(array $params)
  125 + {
  126 + $this->builder->method('POST')->service('product.qualityList')->params($params);
  127 + }
  128 +
  129 + /**
  130 + * @inheritDoc
  131 + */
  132 + public function editSkuPrice(array $params)
  133 + {
  134 + $this->builder->method('POST')->service('sku.editPrice')->params($params);
  135 + }
  136 +
  137 + /**
  138 + * @inheritDoc
  139 + */
  140 + public function qualityDetail(array $params)
  141 + {
  142 + $this->builder->method('POST')->service('product.qualityDetail')->params($params);
  143 + }
  144 +
  145 + /**
  146 + * @inheritDoc
  147 + */
  148 + public function editBuyerLimit(array $params)
  149 + {
  150 + $this->builder->method('POST')->service('product.editBuyerLimit')->params($params);
  151 + }
  152 +
  153 + /**
  154 + * @inheritDoc
  155 + */
  156 + public function qualityTask(array $params)
  157 + {
  158 + $this->builder->method('POST')->service('product.qualityTask')->params($params);
  159 + }
  160 +
  161 + /**
  162 + * @inheritDoc
  163 + */
  164 + public function getSpuKeyPropertyByCid(array $params)
  165 + {
  166 + $this->builder->method('POST')->service('spu.getKeyPropertyByCid')->params($params);
  167 + }
  168 +
  169 + /**
  170 + * @inheritDoc
  171 + */
  172 + public function editSkuCode(array $params)
  173 + {
  174 + $this->builder->method('POST')->service('sku.editCode')->params($params);
  175 + }
  176 +
  177 + /**
  178 + * @inheritDoc
  179 + */
  180 + public function getSpuInfoBySpuId(array $params)
  181 + {
  182 + $this->builder->method('POST')->service('spu.getSpuInfoBySpuId')->params($params);
  183 + }
  184 +
  185 + /**
  186 + * @inheritDoc
  187 + */
  188 + public function getSpuTpl(array $params)
  189 + {
  190 + $this->builder->method('POST')->service('spu.getSpuTpl')->params($params);
  191 + }
  192 +
  193 + /**
  194 + * @inheritDoc
  195 + */
  196 + public function addShopSpu(array $params)
  197 + {
  198 + $this->builder->method('POST')->service('spu.addShopSpu')->params($params);
  199 + }
  200 +
  201 + /**
  202 + * @inheritDoc
  203 + */
  204 + public function opptyProductApply(array $params)
  205 + {
  206 + $this->builder->method('POST')->service('opptyProduct.apply')->params($params);
  207 + }
  208 +
  209 + /**
  210 + * @inheritDoc
  211 + */
  212 + public function opptyProductClue(array $params)
  213 + {
  214 + $this->builder->method('POST')->service('opptyProduct.clue')->params($params);
  215 + }
  216 +
  217 + /**
  218 + * @inheritDoc
  219 + */
  220 + public function getOpptyProductApplyProgress(array $params)
  221 + {
  222 + $this->builder->method('POST')->service('opptyProduct.getApplyProgress')->params($params);
  223 + }
  224 +
  225 + /**
  226 + * @inheritDoc
  227 + */
  228 + public function allianceMaterialsProductCategory(array $params)
  229 + {
  230 + $this->builder->method('POST')->service('alliance.materialsProductCategory')->params($params);
  231 + }
  232 +
  233 + /**
  234 + * @inheritDoc
  235 + */
  236 + public function qualificationConfig(array $params)
  237 + {
  238 + $this->builder->method('POST')->service('product.qualificationConfig')->params($params);
  239 + }
  240 +
  241 + /**
  242 + * @inheritDoc
  243 + */
  244 + public function getBrandSug(array $params)
  245 + {
  246 + $this->builder->method('POST')->service('brand.getSug')->params($params);
  247 + }
  248 +
  249 + /**
  250 + * @inheritDoc
  251 + */
  252 + public function promiseDeliveryList(array $params)
  253 + {
  254 + $this->builder->method('POST')->service('promise.deliveryList')->params($params);
  255 + }
  256 +
  257 + /**
  258 + * @inheritDoc
  259 + */
  260 + public function brandConvert(array $params)
  261 + {
  262 + $this->builder->method('POST')->service('brand.convert')->params($params);
  263 + }
  264 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage\Product;
  4 +
  5 +use Lackoxygen\TiktokShop\Passage\ResultSet;
  6 +
  7 +interface ProductInterface
  8 +{
  9 + /**
  10 + * @link https://op.jinritemai.com/docs/api-docs/14/633
  11 + * @param array $params
  12 + * @return ResultSet
  13 + */
  14 + public function listV2(array $params);
  15 +
  16 + /**
  17 + * @link https://op.jinritemai.com/docs/api-docs/14/94
  18 + * @param array $params
  19 + * @return ResultSet
  20 + */
  21 + public function getCateProperty(array $params);
  22 +
  23 + /**
  24 + * @link https://op.jinritemai.com/docs/api-docs/14/249
  25 + * @param array $params
  26 + * @return ResultSet
  27 + */
  28 + public function addV2(array $params);
  29 +
  30 + /**
  31 + * @link https://op.jinritemai.com/docs/api-docs/14/250
  32 + * @param array $params
  33 + * @return ResultSet
  34 + */
  35 + public function editV2(array $params);
  36 +
  37 + /**
  38 + * @link https://op.jinritemai.com/docs/api-docs/14/56
  39 + * @param array $params
  40 + * @return ResultSet
  41 + */
  42 + public function detail(array $params);
  43 +
  44 + /**
  45 + * @link https://op.jinritemai.com/docs/api-docs/14/61
  46 + * @param array $params
  47 + * @return ResultSet
  48 + */
  49 + public function del(array $params);
  50 +
  51 + /**
  52 + * @link https://op.jinritemai.com/docs/api-docs/14/566
  53 + * @param array $params
  54 + * @return ResultSet
  55 + */
  56 + public function skuDetail(array $params);
  57 +
  58 + /**
  59 + * @link https://op.jinritemai.com/docs/api-docs/14/565
  60 + * @param array $params
  61 + * @return ResultSet
  62 + */
  63 + public function freightTemplateList(array $params);
  64 +
  65 + /**
  66 + * @link https://op.jinritemai.com/docs/api-docs/14/1267
  67 + * @param array $params
  68 + * @return ResultSet
  69 + */
  70 + public function brandList(array $params);
  71 +
  72 + /**
  73 + * @link https://op.jinritemai.com/docs/api-docs/14/1373
  74 + * @param array $params
  75 + * @return ResultSet
  76 + */
  77 + public function getCatePropertyV2(array $params);
  78 +
  79 + /**
  80 + * @link https://op.jinritemai.com/docs/api-docs/14/251
  81 + * @param array $params
  82 + * @return ResultSet
  83 + */
  84 + public function setOnline(array $params);
  85 +
  86 + /**
  87 + * @link https://op.jinritemai.com/docs/api-docs/14/82
  88 + * @param array $params
  89 + * @return ResultSet
  90 + */
  91 + public function skuList(array $params);
  92 +
  93 + /**
  94 + * @link https://op.jinritemai.com/docs/api-docs/14/298
  95 + * @param array $params
  96 + * @return ResultSet
  97 + */
  98 + public function skuSyncStockBatch(array $params);
  99 +
  100 + /**
  101 + * @link https://op.jinritemai.com/docs/api-docs/14/252
  102 + * @param array $params
  103 + * @return ResultSet
  104 + */
  105 + public function setOffline(array $params);
  106 +
  107 + /**
  108 + * @link https://op.jinritemai.com/docs/api-docs/14/938
  109 + * @param array $params
  110 + * @return ResultSet
  111 + */
  112 + public function qualityList(array $params);
  113 +
  114 + /**
  115 + * @link https://op.jinritemai.com/docs/api-docs/14/84
  116 + * @param array $params
  117 + * @return ResultSet
  118 + */
  119 + public function editSkuPrice(array $params);
  120 +
  121 + /**
  122 + * @link https://op.jinritemai.com/docs/api-docs/14/939
  123 + * @param array $params
  124 + * @return ResultSet
  125 + */
  126 + public function qualityDetail(array $params);
  127 +
  128 + /**
  129 + * @link https://op.jinritemai.com/docs/api-docs/14/262
  130 + * @param array $params
  131 + * @return ResultSet
  132 + */
  133 + public function editBuyerLimit(array $params);
  134 +
  135 + /**
  136 + * @link https://op.jinritemai.com/docs/api-docs/14/937
  137 + * @param array $params
  138 + * @return ResultSet
  139 + */
  140 + public function qualityTask(array $params);
  141 +
  142 + /**
  143 + * @link https://op.jinritemai.com/docs/api-docs/14/642
  144 + * @param array $params
  145 + * @return ResultSet
  146 + */
  147 + public function getSpuKeyPropertyByCid(array $params);
  148 +
  149 + /**
  150 + * @link https://op.jinritemai.com/docs/api-docs/14/86
  151 + * @param array $params
  152 + * @return ResultSet
  153 + */
  154 + public function editSkuCode(array $params);
  155 +
  156 + /**
  157 + * @link https://op.jinritemai.com/docs/api-docs/14/643
  158 + * @param array $params
  159 + * @return ResultSet
  160 + */
  161 + public function getSpuInfoBySpuId(array $params);
  162 +
  163 + /**
  164 + * @link https://op.jinritemai.com/docs/api-docs/14/644
  165 + * @param array $params
  166 + * @return ResultSet
  167 + */
  168 + public function getSpuTpl(array $params);
  169 +
  170 + /**
  171 + * @link https://op.jinritemai.com/docs/api-docs/14/645
  172 + * @param array $params
  173 + * @return ResultSet
  174 + */
  175 + public function addShopSpu(array $params);
  176 +
  177 +
  178 + /**
  179 + * @link https://op.jinritemai.com/docs/api-docs/14/738
  180 + * @param array $params
  181 + * @return ResultSet
  182 + */
  183 + public function opptyProductApply(array $params);
  184 +
  185 + /**
  186 + * @link https://op.jinritemai.com/docs/api-docs/14/739
  187 + * @param array $params
  188 + * @return ResultSet
  189 + */
  190 + public function opptyProductClue(array $params);
  191 +
  192 + /**
  193 + * @link https://op.jinritemai.com/docs/api-docs/14/740
  194 + * @param array $params
  195 + * @return ResultSet
  196 + */
  197 + public function getOpptyProductApplyProgress(array $params);
  198 +
  199 + /**
  200 + * @link https://op.jinritemai.com/docs/api-docs/14/637
  201 + * @param array $params
  202 + * @return ResultSet
  203 + */
  204 + public function allianceMaterialsProductCategory(array $params);
  205 +
  206 + /**
  207 + * @link https://op.jinritemai.com/docs/api-docs/14/1382
  208 + * @param array $params
  209 + * @return ResultSet
  210 + */
  211 + public function qualificationConfig(array $params);
  212 +
  213 + /**
  214 + * @link https://op.jinritemai.com/docs/api-docs/14/1436
  215 + * @param array $params
  216 + * @return ResultSet
  217 + */
  218 + public function getBrandSug(array $params);
  219 +
  220 + /**
  221 + * @link https://op.jinritemai.com/docs/api-docs/14/1529
  222 + * @param array $params
  223 + * @return ResultSet
  224 + */
  225 + public function promiseDeliveryList(array $params);
  226 +
  227 + /**
  228 + * @link https://op.jinritemai.com/docs/api-docs/14/1500
  229 + * @param array $params
  230 + * @return ResultSet
  231 + */
  232 + public function brandConvert(array $params);
  233 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage;
  4 +
  5 +use Lackoxygen\TiktokShop\Util\Json;
  6 +use GuzzleHttp\Psr7\Response;
  7 +use Illuminate\Support\Arr;
  8 +
  9 +class ResultSet
  10 +{
  11 + protected array $items = [];
  12 +
  13 + protected $result;
  14 +
  15 + public function __construct($result)
  16 + {
  17 + $this->result = $result;
  18 +
  19 + if ($this->isResponse()) {
  20 + $this->items = Json::unmarshal($result->getBody()->getContents());
  21 + } else {
  22 + $this->items = is_array($result) ? $result : [$result];
  23 + }
  24 + }
  25 +
  26 + protected function isResponse(): bool
  27 + {
  28 + return $this->result instanceof Response;
  29 + }
  30 +
  31 +
  32 + public function toArray(): array
  33 + {
  34 + return $this->items;
  35 + }
  36 +
  37 + public function isSuccess(): bool
  38 + {
  39 + $array = $this->toArray();
  40 +
  41 + if ($this->isResponse()) {
  42 + return 10000 === $array['code'];
  43 + }
  44 +
  45 + return true === Arr::first($array);
  46 + }
  47 +
  48 + public function getMessage(): string
  49 + {
  50 + $array = $this->toArray();
  51 +
  52 + return (string) $array['message'] ?? '';
  53 + }
  54 +
  55 + public function getData(): array
  56 + {
  57 + $array = $this->toArray();
  58 +
  59 + return (array) Arr::get($array, 'data', []);
  60 + }
  61 +
  62 + public function get(string $key, $default = '')
  63 + {
  64 + return Arr::get($this->getData(), $key, $default);
  65 + }
  66 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage\Shop;
  4 +
  5 +use Lackoxygen\TiktokShop\Passage\Passage;
  6 +
  7 +class Shop extends Passage implements ShopInterface
  8 +{
  9 + /**
  10 + * @inheritDoc
  11 + */
  12 + public function brandList(array $params)
  13 + {
  14 + $this->builder->service('POST')->params($params)->service('shop.brandList');
  15 + }
  16 +
  17 + /**
  18 + * @inheritDoc
  19 + */
  20 + public function searchMemberList(array $params)
  21 + {
  22 + $this->builder->service('POST')->params($params)->service('member.searchList');
  23 + }
  24 +
  25 + /**
  26 + * @inheritDoc
  27 + */
  28 + public function userLogin(array $params)
  29 + {
  30 + $this->builder->service('POST')->params($params)->service('antispam.userLogin');
  31 + }
  32 +
  33 + /**
  34 + * @inheritDoc
  35 + */
  36 + public function getShopCategory(array $params)
  37 + {
  38 + $this->builder->service('POST')->params($params)->service('shop.getShopCategory');
  39 + }
  40 +
  41 + /**
  42 + * @inheritDoc
  43 + */
  44 + public function addressUpdate(array $params)
  45 + {
  46 + $this->builder->service('POST')->params($params)->service('address.update');
  47 + }
  48 +
  49 + /**
  50 + * @inheritDoc
  51 + */
  52 + public function addressCreate(array $params)
  53 + {
  54 + $this->builder->service('POST')->params($params)->service('address.create');
  55 + }
  56 +
  57 + /**
  58 + * @inheritDoc
  59 + */
  60 + public function getShopShortLink(array $params)
  61 + {
  62 + $this->builder->service('POST')->params($params)->service('member.getShopShortLink');
  63 + }
  64 +
  65 + /**
  66 + * @inheritDoc
  67 + */
  68 + public function addressList(array $params)
  69 + {
  70 + $this->builder->service('POST')->params($params)->service('address.list');
  71 + }
  72 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage\Shop;
  4 +
  5 +use Lackoxygen\TiktokShop\Passage\ResultSet;
  6 +
  7 +interface ShopInterface
  8 +{
  9 + /**
  10 + * @link https://op.jinritemai.com/docs/api-docs/13/54
  11 + * @param array $params
  12 + * @return ResultSet
  13 + */
  14 + public function brandList(array $params);
  15 +
  16 + /**
  17 + * @link https://op.jinritemai.com/docs/api-docs/13/366
  18 + * @param array $params
  19 + * @return ResultSet
  20 + */
  21 + public function searchMemberList(array $params);
  22 +
  23 + /**
  24 + * @link https://op.jinritemai.com/docs/api-docs/13/635
  25 + * @param array $params
  26 + * @return ResultSet
  27 + */
  28 + public function userLogin(array $params);
  29 +
  30 + /**
  31 + * @link https://op.jinritemai.com/docs/api-docs/13/821
  32 + * @param array $params
  33 + * @return ResultSet
  34 + */
  35 + public function getShopCategory(array $params);
  36 +
  37 + /**
  38 + * @link https://op.jinritemai.com/docs/api-docs/13/1511
  39 + * @param array $params
  40 + * @return ResultSet
  41 + */
  42 + public function addressUpdate(array $params);
  43 +
  44 + /**
  45 + * @link https://op.jinritemai.com/docs/api-docs/13/1510
  46 + * @param array $params
  47 + * @return ResultSet
  48 + */
  49 + public function addressCreate(array $params);
  50 +
  51 + /**
  52 + * @link https://op.jinritemai.com/docs/api-docs/13/1455
  53 + * @param array $params
  54 + * @return ResultSet
  55 + */
  56 + public function getShopShortLink(array $params);
  57 +
  58 + /**
  59 + * @link https://op.jinritemai.com/docs/api-docs/13/1435
  60 + * @param array $params
  61 + * @return ResultSet
  62 + */
  63 + public function addressList(array $params);
  64 +
  65 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Passage;
  4 +
  5 +class Verify extends Passage
  6 +{
  7 + public function md5($sign, string $body): bool
  8 + {
  9 + $md5 = md5($this->config->getAppKey() .
  10 + $body .
  11 + $this->config->getAppSecret());
  12 + return $md5 === $sign;
  13 + }
  14 +
  15 + public function sha256($sign, string $body): bool
  16 + {
  17 + return true;
  18 + }
  19 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop;
  4 +
  5 +use Illuminate\Support\Arr;
  6 +use Lackoxygen\TiktokShop\Attribute\Config;
  7 +use Lackoxygen\TiktokShop\Passage\Alliance\Alliance;
  8 +use Lackoxygen\TiktokShop\Passage\Authorize;
  9 +use Lackoxygen\TiktokShop\Passage\Order\OrderInterface;
  10 +use Lackoxygen\TiktokShop\Passage\PassageProxy;
  11 +use Lackoxygen\TiktokShop\Passage\Product\ProductInterface;
  12 +use Lackoxygen\TiktokShop\Passage\Shop\ShopInterface;
  13 +use Lackoxygen\TiktokShop\Passage\Verify;
  14 +
  15 +/**
  16 + * @method OrderInterface order()
  17 + * @method ShopInterface shop()
  18 + * @method ProductInterface product()
  19 + * @method Authorize authorize()
  20 + * @method Verify verify()
  21 + * @method Alliance alliance()
  22 + */
  23 +class TiktokShop
  24 +{
  25 + /**
  26 + * @var Config
  27 + */
  28 + protected Config $config;
  29 +
  30 + /**
  31 + * @var array|string[]
  32 + */
  33 + protected static array $passages = [
  34 + 'order' => Passage\Order\Order::class, 'shop' => Passage\Shop\Shop::class,
  35 + 'product' => Passage\Product\Product::class, 'authorize' => Authorize::class, 'verify' => Verify::class,
  36 + 'alliance' => Alliance::class
  37 + ];
  38 +
  39 + /**
  40 + * @param $config
  41 + */
  42 + public function __construct($config = null)
  43 + {
  44 + if (!$config instanceof Config) {
  45 + $default = \config(TiktokShopProvider::$name);
  46 + if (!is_array($default)) {
  47 + return;
  48 + }
  49 + $config = static::newConfig($default);
  50 + }
  51 + $this->config = $config;
  52 + }
  53 +
  54 + /**
  55 + * @param array $options
  56 + *
  57 + * @return Config
  58 + */
  59 + public static function newConfig(array $options): Config
  60 + {
  61 + return new Config(Arr::get($options, 'app_key'), Arr::get($options, 'app_secret'),
  62 + Arr::get($options, 'base_uri'), (float) Arr::get($options, 'timeout'), Arr::get($options, 'enable_mock'));
  63 + }
  64 +
  65 + /**
  66 + * @param Config $config
  67 + *
  68 + * @return TiktokShop
  69 + */
  70 + public static function use(Config $config): TiktokShop
  71 + {
  72 + return new static($config);
  73 + }
  74 +
  75 + /**
  76 + * @param string $accessToken
  77 + *
  78 + * @return void
  79 + */
  80 + public function setAccessToken(string $accessToken): void
  81 + {
  82 + $this->config->setAccessToken($accessToken);
  83 + }
  84 +
  85 + /**
  86 + * @param $name
  87 + * @param array $arguments
  88 + *
  89 + * @return PassageProxy
  90 + */
  91 + public function __call($name, array $arguments = [])
  92 + {
  93 + $passage = static::$passages[$name];
  94 +
  95 + return PassageProxy::proxy($passage, $this->config);
  96 + }
  97 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop;
  4 +
  5 +use Illuminate\Support\ServiceProvider;
  6 +
  7 +class TiktokShopProvider extends ServiceProvider
  8 +{
  9 + /**
  10 + * @var string
  11 + */
  12 + public static string $name = 'tiktok.shop';
  13 +
  14 + /**
  15 + * @return void
  16 + */
  17 + public function boot()
  18 + {
  19 + $configPath = __DIR__.'/../publish/tiktok.php';
  20 + $this->publishes([
  21 + $configPath => config_path('tiktok.php')
  22 + ], 'lackoxygen-tiktok');
  23 + }
  24 +
  25 + /**
  26 + * @return string[]
  27 + */
  28 + public function provides(): array
  29 + {
  30 + return [static::$name, TiktokShop::class];
  31 + }
  32 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Transmit;
  4 +
  5 +use Lackoxygen\TiktokShop\Attribute\Config;
  6 +use Lackoxygen\TiktokShop\Attribute\Request;
  7 +use Lackoxygen\TiktokShop\Exception\ClientException;
  8 +use Lackoxygen\TiktokShop\Mock\Mock;
  9 +use GuzzleHttp\Exception\GuzzleException;
  10 +use Psr\Http\Message\ResponseInterface;
  11 +
  12 +class Builder
  13 +{
  14 + protected Request $request;
  15 +
  16 + protected Config $config;
  17 +
  18 + protected string $passage, $method;
  19 +
  20 + public function __construct(Config $config, string $passage, string $method)
  21 + {
  22 + $this->request = new Request;
  23 + $this->config = $config;
  24 + $this->request->setConfig($config);
  25 + $this->passage = $passage;
  26 + $this->method = $method;
  27 + }
  28 +
  29 + public static function create(Config $config, string $passage, string $method): Builder
  30 + {
  31 + return new static(...func_get_args());
  32 + }
  33 +
  34 + public function method(string $method): Builder
  35 + {
  36 + $this->request->setMethod($method);
  37 + return $this;
  38 + }
  39 +
  40 + public function params(array $params): Builder
  41 + {
  42 + $this->request->setParams($params);
  43 + return $this;
  44 + }
  45 +
  46 + public function v(string $v): Builder
  47 + {
  48 + $this->request->setV($v);
  49 + return $this;
  50 + }
  51 +
  52 + public function timestamp($timestamp): Builder
  53 + {
  54 + $this->request->setTimestamp($timestamp);
  55 + return $this;
  56 + }
  57 +
  58 + public function service(?string $service): Builder
  59 + {
  60 + $this->request->setService($service);
  61 + return $this;
  62 + }
  63 +
  64 + public function signature(bool $signature): Builder
  65 + {
  66 + $this->request->setSignature($signature);
  67 + return $this;
  68 + }
  69 +
  70 + public function path(string $path): Builder
  71 + {
  72 + $this->request->setPath($path);
  73 + return $this;
  74 + }
  75 +
  76 + /**
  77 + * @return Request
  78 + */
  79 + public function getRequest(): Request
  80 + {
  81 + return $this->request;
  82 + }
  83 +
  84 + /**
  85 + * @return ResponseInterface
  86 + * @throws ClientException
  87 + */
  88 + public function request(): ResponseInterface
  89 + {
  90 + $client = Client::create();
  91 + if ($this->config->isEnableMock()) {
  92 + $mock = new Mock($this->passage, $this->method);
  93 + return $mock->response();
  94 + }
  95 + try {
  96 + return $client->request($this->request);
  97 + } catch (GuzzleException $e) {
  98 + throw new ClientException($e);
  99 + }
  100 + }
  101 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Transmit;
  4 +
  5 +use Lackoxygen\TiktokShop\Attribute\Config;
  6 +use Lackoxygen\TiktokShop\Attribute\Request;
  7 +use Lackoxygen\TiktokShop\Exception\ClientException;
  8 +use Lackoxygen\TiktokShop\Exception\RetryException;
  9 +use Lackoxygen\TiktokShop\Util\Json;
  10 +use Lackoxygen\TiktokShop\Util\Signature;
  11 +use Lackoxygen\TiktokShop\Util\Sort;
  12 +use GuzzleHttp\Exception\ConnectException;
  13 +use GuzzleHttp\RequestOptions;
  14 +use Illuminate\Support\Str;
  15 +
  16 +class Client
  17 +{
  18 + public static function create(): Client
  19 + {
  20 + return new self;
  21 + }
  22 +
  23 + /**
  24 + * @param string $service
  25 + *
  26 + * @return string
  27 + */
  28 + protected function serviceToPath(string $service): string
  29 + {
  30 + return '/'.ltrim(Str::replace('.', '/', $service), '/');
  31 + }
  32 +
  33 + /**
  34 + * @param Request $request
  35 + *
  36 + * @return false|string
  37 + */
  38 + protected function signature(Request $request): ?string
  39 + {
  40 + $sig = new Signature;
  41 + $sig->setTimestamp($request->getTimestamp());
  42 + $sig->setMethod($request->getService());
  43 + $sig->setAppKey($request->getConfig()->getAppKey());
  44 + $sig->setAppSecret($request->getConfig()->getAppSecret());
  45 + $sig->setVersion($request->getV());
  46 + $params = $request->getParams();
  47 + Sort::ksort($params);
  48 + $sig->setParamJson(Json::marshal($params));
  49 +
  50 + return $sig->generate();
  51 + }
  52 +
  53 + /**
  54 + * @param Request $request
  55 + *
  56 + * @return array
  57 + */
  58 + protected function withSignatureQuery(Request $request): array
  59 + {
  60 + $params = $request->getParams();
  61 + Sort::ksort($params);
  62 +
  63 + return [
  64 + 'method' => $request->getService(), 'app_key' => $request->getConfig()->getAppKey(),
  65 + 'access_token' => $request->getConfig()->getAccessToken(), 'param_json' => Json::marshal($params),
  66 + 'timestamp' => $request->getTimestamp(), 'v' => $request->getV(), 'sign' => $this->signature($request),
  67 + 'sign_method' => 'hmac-sha256',
  68 + ];
  69 + }
  70 +
  71 + protected function withQuery(Request $request): array
  72 + {
  73 + return [
  74 + 'app_id' => $request->getConfig()->getAppKey(), 'app_secret' => $request->getConfig()->getAppSecret(),
  75 + ];
  76 + }
  77 +
  78 + public function guzzleHttp(Config $config): \GuzzleHttp\Client
  79 + {
  80 + return new \GuzzleHttp\Client([
  81 + 'base_uri' => $config->getBaseUri(), 'timeout' => $config->getTimeout(), 'verify' => false
  82 + ]);
  83 + }
  84 +
  85 +
  86 + /**
  87 + * @param Request $request
  88 + *
  89 + * @return \Psr\Http\Message\ResponseInterface
  90 + * @throws ClientException
  91 + * @throws RetryException
  92 + */
  93 + public function request(Request $request): \Psr\Http\Message\ResponseInterface
  94 + {
  95 + if ($request->isSignature()) {
  96 + $query = $this->withSignatureQuery($request);
  97 + } else {
  98 + $query = $this->withQuery($request);
  99 + }
  100 + $options = [
  101 + RequestOptions::HEADERS => [
  102 + 'Content-type' => 'application/json'
  103 + ]
  104 + ];
  105 + $options[RequestOptions::QUERY] = $query;
  106 + $options[RequestOptions::JSON] = $request->getParams();
  107 +
  108 + $retry = new Retry(function () use ($request, $options) {
  109 + return $this->guzzleHttp($request->getConfig())
  110 + ->request($request->getMethod(), $request->getPath() ? : $this->serviceToPath($request->getService()),
  111 + $options);
  112 + }, function ($e) {
  113 + return $e instanceof ConnectException;
  114 + });
  115 +
  116 + return $retry();
  117 + }
  118 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Transmit;
  4 +
  5 +use Lackoxygen\TiktokShop\Exception\ClientException;
  6 +use Lackoxygen\TiktokShop\Exception\RetryException;
  7 +
  8 +class Retry
  9 +{
  10 + protected \Closure $execute;
  11 +
  12 + protected \Closure $when;
  13 +
  14 + /**
  15 + * @param \Closure $execute
  16 + * @param \Closure $when
  17 + */
  18 + public function __construct(\Closure $execute, \Closure $when)
  19 + {
  20 + $this->execute = $execute;
  21 +
  22 + $this->when = $when;
  23 + }
  24 +
  25 + /**
  26 + * @param int $retries
  27 + * @param int $waitMilliseconds
  28 + *
  29 + * @return mixed|void
  30 + * @throws ClientException
  31 + * @throws RetryException
  32 + */
  33 + public function __invoke(int $retries = 3, int $waitMilliseconds = 500)
  34 + {
  35 + $callback = $this->execute;
  36 + $when = $this->when;
  37 + $attempts = 0;
  38 + do {
  39 + try {
  40 + return $callback($retries);
  41 + } catch (\Throwable $e) {
  42 + if (!$when($e)) {
  43 + throw new ClientException($e);
  44 + }
  45 + $waitMilliseconds && usleep($waitMilliseconds * 1000);
  46 + }
  47 + finally {
  48 + ++$attempts;
  49 + }
  50 + } while ($attempts < $retries);
  51 +
  52 + throw new RetryException(sprintf('maximum number of attempts(%d) reached', $attempts));
  53 + }
  54 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Util;
  4 +
  5 +class Json
  6 +{
  7 + public static function marshal(array $array)
  8 + {
  9 + return \json_encode($array, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
  10 + }
  11 +
  12 + public static function unmarshal(string $value, $associative = true)
  13 + {
  14 + return \json_decode($value, $associative);
  15 + }
  16 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Util;
  4 +
  5 +class Preg
  6 +{
  7 + public static function annotation(string $docs)
  8 + {
  9 + preg_match_all('/@.*?/U', $docs, $matches);
  10 +
  11 + return $matches[0] ?? [];
  12 + }
  13 +
  14 +
  15 + public static function mergeSpaces($string)
  16 + {
  17 + return preg_replace("/\s(?=\s)/", "\\1", $string);
  18 + }
  19 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Util;
  4 +
  5 +class Signature
  6 +{
  7 + private string $appKey;
  8 +
  9 + private string $appSecret;
  10 +
  11 + private string $method;
  12 +
  13 + private string $timestamp;
  14 +
  15 + private string $paramJson;
  16 +
  17 + private string $version;
  18 +
  19 + /**
  20 + * @param mixed $appKey
  21 + */
  22 + public function setAppKey(string $appKey): Signature
  23 + {
  24 + $this->appKey = $appKey;
  25 + return $this;
  26 + }
  27 +
  28 + /**
  29 + * @param mixed $method
  30 + */
  31 + public function setMethod($method): Signature
  32 + {
  33 + $this->method = $method;
  34 + return $this;
  35 + }
  36 +
  37 + /**
  38 + * @param mixed $timestamp
  39 + */
  40 + public function setTimestamp($timestamp): Signature
  41 + {
  42 + $this->timestamp = $timestamp;
  43 + return $this;
  44 + }
  45 +
  46 + /**
  47 + * @param mixed $appSecret
  48 + */
  49 + public function setAppSecret($appSecret): Signature
  50 + {
  51 + $this->appSecret = $appSecret;
  52 + return $this;
  53 + }
  54 +
  55 + /**
  56 + * @param mixed $paramJson
  57 + */
  58 + public function setParamJson($paramJson): Signature
  59 + {
  60 + $this->paramJson = $paramJson;
  61 + return $this;
  62 + }
  63 +
  64 + /**
  65 + * @param mixed $version
  66 + */
  67 + public function setVersion($version): Signature
  68 + {
  69 + $this->version = $version;
  70 + return $this;
  71 + }
  72 +
  73 + public function generate()
  74 + {
  75 + $paramPattern = 'app_key' . $this->appKey . 'method' .
  76 + $this->method . 'param_json' . $this->paramJson .
  77 + 'timestamp' . $this->timestamp . 'v' . $this->version;
  78 + $signPattern = $this->appSecret . $paramPattern . $this->appSecret;
  79 + return hash_hmac("sha256", $signPattern, $this->appSecret);
  80 + }
  81 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\TiktokShop\Util;
  4 +
  5 +class Sort
  6 +{
  7 + public static function kSort(array &$arr)
  8 + {
  9 + $kstring = true;
  10 + foreach ($arr as $k => &$v) {
  11 + if (!is_string($k)) {
  12 + $kstring = false;
  13 + }
  14 + if (is_array($v)) {
  15 + self::ksort($v);
  16 + }
  17 + }
  18 + if ($kstring) {
  19 + ksort($arr);
  20 + }
  21 + }
  22 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\Tests;
  4 +
  5 +use Lackoxygen\TiktokShop\Facade\TiktokShop;
  6 +use Lackoxygen\TiktokShop\Passage\ResultSet;
  7 +
  8 +class FetchTest extends \PHPUnit\Framework\TestCase
  9 +{
  10 + public function testRequest()
  11 + {
  12 + $obj = TiktokShop::alliance()->materialsProductsSearch([]);
  13 +
  14 + $this->assertInstanceOf($obj, ResultSet::class);
  15 + }
  16 +}