Skip to content

Commit

Permalink
bugfix: fix method open.distribution.cps.kwaimoney.order.detail param…
Browse files Browse the repository at this point in the history
…s error
  • Loading branch information
G-YDG committed May 4, 2023
1 parent 79200e9 commit 8d1be94
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 70 deletions.
25 changes: 12 additions & 13 deletions src/Api/Distribution/Distribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}
}
2 changes: 1 addition & 1 deletion src/Api/Distribution/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function register(Container $pimple)
return new Distribution(isset($pimple['config']) ? $pimple['config']->toArray() : []);
};
}
}
}
2 changes: 1 addition & 1 deletion src/Api/User/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function register(Container $pimple)
return new User(isset($pimple['config']) ? $pimple['config']->toArray() : []);
};
}
}
}
8 changes: 5 additions & 3 deletions src/Api/User/User.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Ydg\KwaixiaodianSdk\Api\User;

use GuzzleHttp\Exception\GuzzleException;
Expand All @@ -8,12 +10,12 @@
class User extends KwaixiaodianApi
{
/**
* 获取用户公开信息
* @link https://open.kwaixiaodian.com/docs/api?apiName=open.user.info.get&categoryId=46&version=1
* 获取用户公开信息.
* @see https://open.kwaixiaodian.com/docs/api?apiName=open.user.info.get&categoryId=46&version=1
* @throws GuzzleException
*/
public function openUserInfoGet(): array
{
return $this->get('open.user.info.get');
}
}
}
6 changes: 3 additions & 3 deletions src/Kwaixiaodian.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
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
{
protected $providers = [
Api\Distribution\ServiceProvider::class,
Api\User\ServiceProvider::class,
];
}
}
59 changes: 23 additions & 36 deletions src/KwaixiaodianApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -76,64 +86,41 @@ 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
{
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 [
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
'Accept' => 'application/json;charset=UTF-8',
],
'verify' => false
'verify' => false,
];
}
}
}
7 changes: 1 addition & 6 deletions src/Oauth/Oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -44,4 +39,4 @@ public function refreshToken($refresh_token): array
]);
return Utils::jsonResponseToArray($response);
}
}
}
2 changes: 1 addition & 1 deletion src/Oauth/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function register(Container $pimple)
return new Oauth(isset($pimple['config']) ? $pimple['config']->toArray() : []);
};
}
}
}
4 changes: 2 additions & 2 deletions src/Support/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -23,4 +23,4 @@ public static function jsonResponseToArray(ResponseInterface $response): array
{
return json_decode($response->getBody()->getContents(), true);
}
}
}
2 changes: 1 addition & 1 deletion tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public function isSuccessResponse($response)
$this->assertArrayHasKey('result', $response);
$this->assertEquals(1, $response['result']);
}
}
}
6 changes: 5 additions & 1 deletion tests/Api/DistributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use Ydg\KwaixiaodianSdk\Kwaixiaodian;
use YdgTest\AbstractTest;

/**
* @internal
* @coversNothing
*/
class DistributionTest extends AbstractTest
{
public function testOpenDistributionCpsKwaimoneyPidList()
Expand Down Expand Up @@ -57,4 +61,4 @@ public function testOpenDistributionCpsKwaimoneyLinkCreate()
]);
$this->isSuccessResponse($response);
}
}
}
7 changes: 5 additions & 2 deletions tests/Api/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
use Ydg\KwaixiaodianSdk\Kwaixiaodian;
use YdgTest\AbstractTest;

/**
* @internal
* @coversNothing
*/
class UserTest extends AbstractTest
{
/**
* @return void
* @throws GuzzleException
*/
public function testInfoGet()
Expand All @@ -18,4 +21,4 @@ public function testInfoGet()
$response = $app->user->openUserInfoGet();
$this->isSuccessResponse($response);
}
}
}

0 comments on commit 8d1be94

Please sign in to comment.