作者 竞泽

feat:format all

<?php
return [
'app_key' => env('TIKTOK_APP_KEY', ''),
'app_secret' => env('TIKTOK_APP_SECRET', ''),
'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),
'base_uri' => env('TIKTOK_BASE_URI', 'https://openapi-sandbox.jinritemai.com'),
'timeout' => env('TIKTOK_TIMEOUT', 30),
];
... ...
... ... @@ -20,18 +20,19 @@ class Config
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;
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
* @param mixed $appKey
*/
public function setAppKey(string $appKey): void
{
... ... @@ -47,7 +48,7 @@ class Config
}
/**
* @param mixed $appSecret
* @param mixed $appSecret
*/
public function setAppSecret($appSecret): void
{
... ... @@ -63,7 +64,7 @@ class Config
}
/**
* @param bool $enableMock
* @param bool $enableMock
*/
public function setEnableMock(bool $enableMock): void
{
... ... @@ -80,7 +81,7 @@ class Config
/**
* @param string $baseUri
* @param string $baseUri
*/
public function setBaseUri(string $baseUri): void
{
... ... @@ -96,7 +97,7 @@ class Config
}
/**
* @param string $accessToken
* @param string $accessToken
*/
public function setAccessToken(string $accessToken): void
{
... ... @@ -112,7 +113,7 @@ class Config
}
/**
* @param float $timeout
* @param float $timeout
*/
public function setTimeout(float $timeout): void
{
... ...
... ... @@ -2,11 +2,11 @@
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 Lackoxygen\TiktokShop\Attribute\Config;
use Lackoxygen\TiktokShop\Attribute\Request;
use Lackoxygen\TiktokShop\Exception\ClientException;
use Lackoxygen\TiktokShop\Exception\MockException;
use Lackoxygen\TiktokShop\Util\Json;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response;
... ...
... ... @@ -13,12 +13,12 @@ abstract class Passage
protected Builder $builder;
/**
* @param Config $config
* @param string $method
* @param Config $config
* @param string $method
*/
public function __construct(Config $config, string $method)
{
$this->config = $config;
$this->config = $config;
$this->builder = Builder::create($config, get_class($this), $method);
}
... ...
... ... @@ -3,7 +3,7 @@
namespace Lackoxygen\TiktokShop\Passage;
use Lackoxygen\TiktokShop\Attribute\Config;
use Lackoxygen\TiktokShop\Exception\{ClientException, ExpiredException};
use Lackoxygen\TiktokShop\Exception\ClientException;
class PassageProxy
{
... ... @@ -25,7 +25,6 @@ class PassageProxy
/**
* @throws ClientException
* @throws ExpiredException
*/
public function __call($name, $arguments): ResultSet
{
... ...
... ... @@ -49,14 +49,14 @@ class ResultSet
{
$array = $this->toArray();
return (string) $array['message'] ?? '';
return (string)$array['message'] ?? '';
}
public function getData(): array
{
$array = $this->toArray();
return (array) Arr::get($array, 'data', []);
return (array)Arr::get($array, 'data', []);
}
public function get(string $key, $default = '')
... ...
... ... @@ -35,7 +35,7 @@ class SessionHeart
public function __destruct()
{
$watch = false;
$watch = false;
$serializes = [];
SessionMemory::each(function (SessionInterface $session) use (&$watch, &$serializes) {
$serializes[] = serialize($session);
... ...
... ... @@ -40,7 +40,7 @@ class SessionMemory
public static function persistence()
{
$key = static::$cachePrefix.'keepalive_table';
$key = static::$cachePrefix . 'keepalive_table';
try {
if (func_get_args()) {
static::cache()->set($key, func_get_arg(0));
... ...
... ... @@ -74,7 +74,7 @@ class Store
}
/**
* @param string $id
* @param string $id
*/
public function setId(string $id): void
{
... ... @@ -90,7 +90,7 @@ class Store
}
/**
* @param string $accessToken
* @param string $accessToken
*/
public function setAccessToken(string $accessToken): void
{
... ... @@ -106,7 +106,7 @@ class Store
}
/**
* @param string $refreshToken
* @param string $refreshToken
*/
public function setRefreshToken(string $refreshToken): void
{
... ... @@ -122,7 +122,7 @@ class Store
}
/**
* @param Carbon $createdAt
* @param Carbon $createdAt
*/
public function setCreatedAt(Carbon $createdAt): void
{
... ... @@ -138,7 +138,7 @@ class Store
}
/**
* @param Carbon $expiredAt
* @param Carbon $expiredAt
*/
public function setExpiredAt(Carbon $expiredAt): void
{
... ... @@ -154,7 +154,7 @@ class Store
}
/**
* @param int $expiresIn
* @param int $expiresIn
*/
public function setExpiresIn(int $expiresIn): void
{
... ... @@ -170,7 +170,7 @@ class Store
}
/**
* @param array $extras
* @param array $extras
*/
public function setExtras(array $extras): void
{
... ... @@ -186,7 +186,7 @@ class Store
}
/**
* @param int $refreshNum
* @param int $refreshNum
*/
public function setRefreshNum(int $refreshNum): void
{
... ...
... ... @@ -31,8 +31,8 @@ class TiktokShop
* @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,
'order' => Passage\Order\Order::class, 'shop' => Passage\Shop\Shop::class,
'product' => Passage\Product\Product::class, 'authorize' => Authorize::class, 'verify' => Verify::class,
'alliance' => Alliance::class
];
... ... @@ -52,18 +52,18 @@ class TiktokShop
}
/**
* @param array $options
* @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'));
Arr::get($options, 'base_uri'), (float)Arr::get($options, 'timeout'), Arr::get($options, 'enable_mock'));
}
/**
* @param Config $config
* @param Config $config
*
* @return TiktokShop
*/
... ... @@ -73,7 +73,7 @@ class TiktokShop
}
/**
* @param string $accessToken
* @param string $accessToken
*
* @return void
*/
... ... @@ -84,7 +84,7 @@ class TiktokShop
/**
* @param $name
* @param array $arguments
* @param array $arguments
*
* @return PassageProxy
*/
... ...
... ... @@ -22,7 +22,7 @@ class TiktokShopProvider extends ServiceProvider
public function boot()
{
if ($this->app->runningInConsole()) {
$configPath = __DIR__.'/../publish/tiktok.shop.php';
$configPath = __DIR__ . '/../publish/tiktok.shop.php';
$this->publishes([
$configPath => config_path('tiktok.shop.php')
], 'lackoxygen-tiktok-shop');
... ...
... ... @@ -21,17 +21,17 @@ class Client
}
/**
* @param string $service
* @param string $service
*
* @return string
*/
protected function serviceToPath(string $service): string
{
return '/'.ltrim(Str::replace('.', '/', $service), '/');
return '/' . ltrim(Str::replace('.', '/', $service), '/');
}
/**
* @param Request $request
* @param Request $request
*
* @return false|string
*/
... ... @@ -51,7 +51,7 @@ class Client
}
/**
* @param Request $request
* @param Request $request
*
* @return array
*/
... ... @@ -61,10 +61,10 @@ class Client
Sort::ksort($params);
return [
'method' => $request->getService(), 'app_key' => $request->getConfig()->getAppKey(),
'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',
'timestamp' => $request->getTimestamp(), 'v' => $request->getV(), 'sign' => $this->signature($request),
'sign_method' => 'hmac-sha256',
];
}
... ... @@ -84,7 +84,7 @@ class Client
/**
* @param Request $request
* @param Request $request
*
* @return \Psr\Http\Message\ResponseInterface
* @throws ClientException
... ... @@ -97,17 +97,17 @@ class Client
} else {
$query = $this->withQuery($request);
}
$options = [
$options = [
RequestOptions::HEADERS => [
'Content-type' => 'application/json'
]
];
$options[RequestOptions::QUERY] = $query;
$options[RequestOptions::JSON] = $request->getParams();
$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()),
->request($request->getMethod(), $request->getPath() ?: $this->serviceToPath($request->getService()),
$options);
}, function ($e) {
return $e instanceof ConnectException;
... ...
... ... @@ -12,8 +12,8 @@ class Retry
protected \Closure $when;
/**
* @param \Closure $execute
* @param \Closure $when
* @param \Closure $execute
* @param \Closure $when
*/
public function __construct(\Closure $execute, \Closure $when)
{
... ... @@ -23,8 +23,8 @@ class Retry
}
/**
* @param int $retries
* @param int $waitMilliseconds
* @param int $retries
* @param int $waitMilliseconds
*
* @return mixed|void
* @throws ClientException
... ... @@ -33,7 +33,7 @@ class Retry
public function __invoke(int $retries = 3, int $waitMilliseconds = 500)
{
$callback = $this->execute;
$when = $this->when;
$when = $this->when;
$attempts = 0;
do {
try {
... ... @@ -43,8 +43,7 @@ class Retry
throw new ClientException($e);
}
$waitMilliseconds && usleep($waitMilliseconds * 1000);
}
finally {
} finally {
++$attempts;
}
} while ($attempts < $retries);
... ...