From d2ad2368f0575cf6234a41d99706a9e41da728b8 Mon Sep 17 00:00:00 2001 From: Charles Shu Date: Mon, 11 Oct 2021 15:38:51 +0800 Subject: [PATCH 1/2] Update BaseRequest.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复无法多次更新access_token的问题 --- src/Api/BaseRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Api/BaseRequest.php b/src/Api/BaseRequest.php index 7986413..0195385 100644 --- a/src/Api/BaseRequest.php +++ b/src/Api/BaseRequest.php @@ -198,6 +198,7 @@ private function updateAccessToken(string $refreshToken): string $response = $this->httpGet('oauth2/refresh_token', $param, false); $response['data']['access_token_expired_at'] = time() + $response['data']['expires_in']; + $response['data']['refresh_token_expired_at'] = strtotime('+14 day'); Cache::set(self::OAUTH_CACHE_KEY.$this->shop_id, $response['data']); From f0f78eee03f64fdbfb8b77b2ee4cad740a17afd0 Mon Sep 17 00:00:00 2001 From: shubo83 Date: Mon, 11 Oct 2021 07:39:15 +0000 Subject: [PATCH 2/2] Fix styling --- .php-cs-fixer.cache | 2 +- src/Api/BaseRequest.php | 24 ++++++++++++------------ src/DouDian.php | 2 +- tests/TestCase.php | 12 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache index 0ee9a06..c41a700 100644 --- a/.php-cs-fixer.cache +++ b/.php-cs-fixer.cache @@ -1 +1 @@ -{"php":"8.0.10","version":"3.1.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true},"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"sort_algorithm":"alpha"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}}},"hashes":{"src\/DouDianFacade.php":299803777,"src\/DouDianServiceProvider.php":2138042692,"src\/Api\/Product.php":247336002,"src\/Api\/WareHouse.php":3583866547,"src\/Api\/Bats.php":1838554985,"src\/Api\/Recycle.php":3839630464,"src\/Api\/Member.php":311976673,"src\/Api\/BuyIn.php":1060733296,"src\/Api\/Yunc.php":4171296594,"src\/Api\/CrossBorder.php":403275624,"src\/Api\/Storage.php":1355493865,"src\/Api\/BaseRequest.php":1240334809,"src\/Api\/Shop.php":3329293900,"src\/Api\/Spu.php":774640965,"src\/Api\/Iop.php":3424136709,"src\/Api\/Order.php":3047532315,"src\/Api\/Alliance.php":3548439058,"src\/Api\/Coupons.php":2332003091,"src\/Api\/AntiSpam.php":3367862619,"src\/Api\/AfterSale.php":2731377559,"src\/Api\/Logistics.php":3453497654,"src\/Api\/OrderCode.php":1009326020,"src\/DouDian.php":2780031595,"tests\/TestCase.php":4001590423,"tests\/DouDianTest.php":3942821870}} \ No newline at end of file +{"php":"8.0.11","version":"3.2.1","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true},"class_definition":{"space_before_parenthesis":true},"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"sort_algorithm":"alpha"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}}},"hashes":{"src\/Api\/BuyIn.php":1060733296,"src\/Api\/BaseRequest.php":1504632681,"src\/Api\/Recycle.php":3839630464,"src\/Api\/OrderCode.php":1009326020,"src\/Api\/AfterSale.php":2731377559,"src\/Api\/Logistics.php":3453497654,"src\/Api\/Yunc.php":4171296594,"src\/Api\/CrossBorder.php":403275624,"src\/Api\/WareHouse.php":3583866547,"src\/Api\/Order.php":3047532315,"src\/Api\/Member.php":311976673,"src\/Api\/Product.php":247336002,"src\/Api\/Iop.php":3424136709,"src\/Api\/Coupons.php":2332003091,"src\/Api\/Storage.php":1355493865,"src\/Api\/AntiSpam.php":3367862619,"src\/Api\/Alliance.php":3548439058,"src\/Api\/Spu.php":774640965,"src\/Api\/Bats.php":1838554985,"src\/Api\/Shop.php":3329293900,"src\/DouDianServiceProvider.php":2138042692,"src\/DouDian.php":2780031595,"src\/DouDianFacade.php":299803777,"tests\/TestCase.php":4001590423,"tests\/DouDianTest.php":3942821870}} \ No newline at end of file diff --git a/src/Api/BaseRequest.php b/src/Api/BaseRequest.php index 0195385..8a3117c 100644 --- a/src/Api/BaseRequest.php +++ b/src/Api/BaseRequest.php @@ -30,11 +30,11 @@ public function __construct(array $config, $shop_id) { $this->config = $config; $this->shop_id = $shop_id; - if (!isset($config['app_key']) || !$config['app_key']) { + if (! isset($config['app_key']) || ! $config['app_key']) { throw new \InvalidArgumentException('配置有误, 请填写app_key'); } - if (!isset($config['app_secret']) || !$config['app_secret']) { + if (! isset($config['app_secret']) || ! $config['app_secret']) { throw new \InvalidArgumentException('配置有误, 请填写app_secret'); } $this->client = new Client(); @@ -103,10 +103,10 @@ protected function generateParams(string $url, array $params): array $url = str_replace('/', '.', $url); $accessToken = $this->getAccessToken(); $public = [ - 'app_key' => $this->config['app_key'], - 'timestamp' => date('Y-m-d H:i:s'), - 'v' => '2', - 'method' => $url, + 'app_key' => $this->config['app_key'], + 'timestamp' => date('Y-m-d H:i:s'), + 'v' => '2', + 'method' => $url, 'access_token' => $accessToken, ]; @@ -121,7 +121,7 @@ protected function generateParams(string $url, array $params): array $public, [ 'param_json' => $param_json, - 'sign' => $sign, + 'sign' => $sign, ] ); } @@ -137,7 +137,7 @@ protected function generateParams(string $url, array $params): array private function getAccessToken(): string { $oauthToken = Cache::get(self::OAUTH_CACHE_KEY.$this->shop_id, []); - if (!$oauthToken) { + if (! $oauthToken) { return $this->requestAccessToken(); } @@ -159,7 +159,7 @@ private function getAccessToken(): string private function requestAccessToken(): string { $param = [ - 'app_id' => $this->config['app_key'], + 'app_id' => $this->config['app_key'], 'app_secret' => $this->config['app_secret'], 'grant_type' => 'authorization_self', ]; @@ -190,9 +190,9 @@ private function requestAccessToken(): string private function updateAccessToken(string $refreshToken): string { $param = [ - 'app_id' => $this->config['app_key'], - 'app_secret' => $this->config['app_secret'], - 'grant_type' => 'refresh_token', + 'app_id' => $this->config['app_key'], + 'app_secret' => $this->config['app_secret'], + 'grant_type' => 'refresh_token', 'refresh_token' => $refreshToken, ]; diff --git a/src/DouDian.php b/src/DouDian.php index 85a6fb8..9bceff9 100644 --- a/src/DouDian.php +++ b/src/DouDian.php @@ -60,7 +60,7 @@ public function __construct(array $config = []) public function __get($class) { $class = '\\Abbotton\\DouDian\\Api\\'.Str::ucfirst($class); - if (!class_exists($class)) { + if (! class_exists($class)) { throw new Exception($class.', Not found', 404); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 4d6ff83..9b3895b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -18,13 +18,13 @@ public function setUp(): void Cache::shouldReceive('get') ->with(self::OAUTH_CACHE_KEY, Mockery::any()) ->andReturn([ - 'access_token' => 'foo', - 'access_token_expired_at' => time() + 86400, + 'access_token' => 'foo', + 'access_token_expired_at' => time() + 86400, 'refresh_token_expired_at' => strtotime('+14 day'), - 'refresh_token' => 'bar', - 'expires_in' => time() + 86400, - 'shop_id' => 123, - 'shop_name' => 'test shop', + 'refresh_token' => 'bar', + 'expires_in' => time() + 86400, + 'shop_id' => 123, + 'shop_name' => 'test shop', ]) ->getMock() ->shouldIgnoreMissing();