From 8d1be94331f5c53d371144737b8f19bb92f97c3e Mon Sep 17 00:00:00 2001 From: ydg <1028180290@qq.com> Date: Thu, 4 May 2023 16:36:36 +0800 Subject: [PATCH] bugfix: fix method open.distribution.cps.kwaimoney.order.detail params error --- src/Api/Distribution/Distribution.php | 25 +++++----- src/Api/Distribution/ServiceProvider.php | 2 +- src/Api/User/ServiceProvider.php | 2 +- src/Api/User/User.php | 8 ++-- src/Kwaixiaodian.php | 6 +-- src/KwaixiaodianApi.php | 59 +++++++++--------------- src/Oauth/Oauth.php | 7 +-- src/Oauth/ServiceProvider.php | 2 +- src/Support/Utils.php | 4 +- tests/AbstractTest.php | 2 +- tests/Api/DistributionTest.php | 6 ++- tests/Api/UserTest.php | 7 ++- 12 files changed, 60 insertions(+), 70 deletions(-) diff --git a/src/Api/Distribution/Distribution.php b/src/Api/Distribution/Distribution.php index f9a1b2b..735b5b3 100644 --- a/src/Api/Distribution/Distribution.php +++ b/src/Api/Distribution/Distribution.php @@ -8,29 +8,28 @@ use Ydg\KwaixiaodianSdk\KwaixiaodianApi; /** - * @method openDistributionCpsKwaimoneyPidCreate(array $params) // 创建快赚客推广位 - * @method openDistributionCpsKwaimoneyPidUpdate(array $params) // 更新快赚客推广位 - * @method openDistributionCpsKwaimoneyPidList(array $params) // 查询快赚客推广位 - * @method openDistributionCpsKwaimoneyLinkCreate(array $params) // 创建快赚客推广链接 - * @method openDistributionCpsKwaimoneySelectionItemList(array $params) // 获取站外分销商品列表 - * @method openDistributionCpsKwaimoneySelectionItemDetail(array $params) // 获取站外分销商品详情 - * @method openDistributionCpsKwaimoneyOrderList(array $params) // 查询快赚客分销订单 - * @method openDistributionCpsKwaimoneyNewPromotionEffectDetail(array $params) // 查询快赚客拉新推广效果数据明细 + * @method openDistributionCpsKwaimoneyPidCreate(array $params) // 创建快赚客推广位 + * @method openDistributionCpsKwaimoneyPidUpdate(array $params) // 更新快赚客推广位 + * @method openDistributionCpsKwaimoneyPidList(array $params) // 查询快赚客推广位 + * @method openDistributionCpsKwaimoneyLinkCreate(array $params) // 创建快赚客推广链接 + * @method openDistributionCpsKwaimoneySelectionItemList(array $params) // 获取站外分销商品列表 + * @method openDistributionCpsKwaimoneySelectionItemDetail(array $params) // 获取站外分销商品详情 + * @method openDistributionCpsKwaimoneyOrderList(array $params) // 查询快赚客分销订单 + * @method openDistributionCpsKwaimoneyNewPromotionEffectDetail(array $params) // 查询快赚客拉新推广效果数据明细 */ class Distribution extends KwaixiaodianApi { /** - * 站外分销快赚客订单详情查询 - * @link https://open.kwaixiaodian.com/docs/api?apiName=open.distribution.cps.kwaimoney.order.detail&categoryId=46&version=1 + * 站外分销快赚客订单详情查询. + * @see https://open.kwaixiaodian.com/docs/api?apiName=open.distribution.cps.kwaimoney.order.detail&categoryId=46&version=1 * @param array|int|string $oid - * @return array * @throws GuzzleException */ public function openDistributionCpsKwaimoneyOrderDetail($oid): array { $oid = is_array($oid) ? $oid : [$oid]; return $this->get('open.distribution.cps.kwaimoney.order.detail', [ - 'oid' => implode(',', $oid), + 'oid' => $oid, ]); } -} \ No newline at end of file +} diff --git a/src/Api/Distribution/ServiceProvider.php b/src/Api/Distribution/ServiceProvider.php index b3e8ab6..d5ea7b4 100644 --- a/src/Api/Distribution/ServiceProvider.php +++ b/src/Api/Distribution/ServiceProvider.php @@ -21,4 +21,4 @@ public function register(Container $pimple) return new Distribution(isset($pimple['config']) ? $pimple['config']->toArray() : []); }; } -} \ No newline at end of file +} diff --git a/src/Api/User/ServiceProvider.php b/src/Api/User/ServiceProvider.php index 0684cac..f3da10d 100644 --- a/src/Api/User/ServiceProvider.php +++ b/src/Api/User/ServiceProvider.php @@ -21,4 +21,4 @@ public function register(Container $pimple) return new User(isset($pimple['config']) ? $pimple['config']->toArray() : []); }; } -} \ No newline at end of file +} diff --git a/src/Api/User/User.php b/src/Api/User/User.php index 478ff91..0938599 100644 --- a/src/Api/User/User.php +++ b/src/Api/User/User.php @@ -1,5 +1,7 @@ get('open.user.info.get'); } -} \ No newline at end of file +} diff --git a/src/Kwaixiaodian.php b/src/Kwaixiaodian.php index bca2766..4e59dff 100644 --- a/src/Kwaixiaodian.php +++ b/src/Kwaixiaodian.php @@ -7,8 +7,8 @@ use Ydg\FoudationSdk\ServiceContainer; /** - * @property Api\Distribution\Distribution $distribution - * @property Api\User\User $user + * @property Api\Distribution\Distribution $distribution + * @property Api\User\User $user */ class Kwaixiaodian extends ServiceContainer { @@ -16,4 +16,4 @@ class Kwaixiaodian extends ServiceContainer Api\Distribution\ServiceProvider::class, Api\User\ServiceProvider::class, ]; -} \ No newline at end of file +} diff --git a/src/KwaixiaodianApi.php b/src/KwaixiaodianApi.php index 8c734bd..d7f5c7c 100644 --- a/src/KwaixiaodianApi.php +++ b/src/KwaixiaodianApi.php @@ -16,22 +16,36 @@ class KwaixiaodianApi extends FoundationApi protected $baseUri = 'https://openapi.kwaixiaodian.com/'; /** - * @param string $baseUri + * @param mixed $name + * @param mixed $arguments + * @throws GuzzleException */ + public function __call($name, $arguments) + { + // 根据方法名转化为method + $method = strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '.$1', $name)); + + $methods = explode('.', $method); + $action = array_pop($methods); + + $requestMethod = in_array($action, ['list', 'detail']) ? 'GET' : 'POST'; + + return $this->request($method, $arguments[0] ?? [], $requestMethod); + } + public function setBaseUri(string $baseUri) { $this->baseUri = $baseUri; } - /** - * @return string - */ public function getBaseUri(): string { return $this->baseUri; } /** + * @param mixed $method + * @param mixed $param * @throws GuzzleException */ public function get($method, $param = []): array @@ -40,10 +54,6 @@ public function get($method, $param = []): array } /** - * @param string $method - * @param array $param - * @param string $request_method - * @return array * @throws GuzzleException */ public function request(string $method, array $param, string $request_method): array @@ -76,33 +86,26 @@ public function getConfig(): array return array_merge(['version' => 1, 'sign_method' => 'MD5'], $this->toArray()); } - /** - * @param array $params - * @param string $signSecret - * @return string - */ public function makeSign(array $params, string $signSecret): string { ksort($params); $paramsStr = ''; array_walk($params, function ($item, $key) use (&$paramsStr) { - if ('@' != substr((string)$item, 0, 1)) { + if (substr((string) $item, 0, 1) != '@') { $paramsStr .= sprintf('%s%s%s%s', $key, '=', $item, '&'); } }); return md5(sprintf('%s%s%s%s', $paramsStr, 'signSecret', '=', $signSecret)); } - /** - * @param string $method - * @return string - */ public function getUri(string $method): string { return $this->getBaseUri() . str_replace('.', '/', $method); } /** + * @param mixed $method + * @param mixed $param * @throws GuzzleException */ public function post($method, $param): array @@ -110,22 +113,6 @@ public function post($method, $param): array return $this->request($method, $param, 'POST'); } - /** - * @throws GuzzleException - */ - public function __call($name, $arguments) - { - // 根据方法名转化为method - $method = strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '.$1', $name)); - - $methods = explode('.', $method); - $action = array_pop($methods); - - $requestMethod = in_array($action, ['list', 'detail']) ? 'GET' : 'POST'; - - return $this->request($method, $arguments[0] ?? [], $requestMethod); - } - public function getHttpClientDefaultOptions(): array { return [ @@ -133,7 +120,7 @@ public function getHttpClientDefaultOptions(): array 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json;charset=UTF-8', ], - 'verify' => false + 'verify' => false, ]; } -} \ No newline at end of file +} diff --git a/src/Oauth/Oauth.php b/src/Oauth/Oauth.php index d737f79..c913150 100644 --- a/src/Oauth/Oauth.php +++ b/src/Oauth/Oauth.php @@ -11,9 +11,6 @@ class Oauth extends KwaixiaodianApi { /** - * @param $code - * @param string $grant_type - * @return array * @throws GuzzleException */ public function accessToken($code, string $grant_type = 'code'): array @@ -29,8 +26,6 @@ public function accessToken($code, string $grant_type = 'code'): array } /** - * @param $refresh_token - * @return array * @throws GuzzleException */ public function refreshToken($refresh_token): array @@ -44,4 +39,4 @@ public function refreshToken($refresh_token): array ]); return Utils::jsonResponseToArray($response); } -} \ No newline at end of file +} diff --git a/src/Oauth/ServiceProvider.php b/src/Oauth/ServiceProvider.php index 9434567..3004d10 100644 --- a/src/Oauth/ServiceProvider.php +++ b/src/Oauth/ServiceProvider.php @@ -21,4 +21,4 @@ public function register(Container $pimple) return new Oauth(isset($pimple['config']) ? $pimple['config']->toArray() : []); }; } -} \ No newline at end of file +} diff --git a/src/Support/Utils.php b/src/Support/Utils.php index 4d31565..d53ce82 100644 --- a/src/Support/Utils.php +++ b/src/Support/Utils.php @@ -10,7 +10,7 @@ class Utils { public static function getMsecTime(): string { - list($t1, $t2) = explode(' ', microtime()); + [$t1, $t2] = explode(' ', microtime()); return sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000); } @@ -23,4 +23,4 @@ public static function jsonResponseToArray(ResponseInterface $response): array { return json_decode($response->getBody()->getContents(), true); } -} \ No newline at end of file +} diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index b605e62..3654b09 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -23,4 +23,4 @@ public function isSuccessResponse($response) $this->assertArrayHasKey('result', $response); $this->assertEquals(1, $response['result']); } -} \ No newline at end of file +} diff --git a/tests/Api/DistributionTest.php b/tests/Api/DistributionTest.php index 4ea700b..9963e63 100644 --- a/tests/Api/DistributionTest.php +++ b/tests/Api/DistributionTest.php @@ -7,6 +7,10 @@ use Ydg\KwaixiaodianSdk\Kwaixiaodian; use YdgTest\AbstractTest; +/** + * @internal + * @coversNothing + */ class DistributionTest extends AbstractTest { public function testOpenDistributionCpsKwaimoneyPidList() @@ -57,4 +61,4 @@ public function testOpenDistributionCpsKwaimoneyLinkCreate() ]); $this->isSuccessResponse($response); } -} \ No newline at end of file +} diff --git a/tests/Api/UserTest.php b/tests/Api/UserTest.php index f1a05de..ef6cb3d 100644 --- a/tests/Api/UserTest.php +++ b/tests/Api/UserTest.php @@ -6,10 +6,13 @@ use Ydg\KwaixiaodianSdk\Kwaixiaodian; use YdgTest\AbstractTest; +/** + * @internal + * @coversNothing + */ class UserTest extends AbstractTest { /** - * @return void * @throws GuzzleException */ public function testInfoGet() @@ -18,4 +21,4 @@ public function testInfoGet() $response = $app->user->openUserInfoGet(); $this->isSuccessResponse($response); } -} \ No newline at end of file +}