From 5ad1affef83a6cd74819088ac5cce02de9dd4879 Mon Sep 17 00:00:00 2001 From: Vitaly Baev Date: Mon, 21 Nov 2016 13:39:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D1=82=D0=BC=D0=B0=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20secretKey=20=D0=B4=D0=BB=D1=8F=20=D0=BC=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=D0=BC=D0=B5=D1=80=D0=BD=D1=8B=D1=85=20=D0=BC?= =?UTF-8?q?=D0=B0=D1=81=D1=81=D0=B8=D0=B2=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Vitaly Baev --- src/Client.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Client.php b/src/Client.php index 77975e0..66d0411 100644 --- a/src/Client.php +++ b/src/Client.php @@ -3,7 +3,7 @@ namespace Vitalybaev\YandexDelivery; /** - * + * Библиотека для выполнения запросов к API Яндекс.Доставки. */ class Client { @@ -65,7 +65,7 @@ function __construct($clientId, $senderId, $apiVersion = '1.0', $methodKeys = [] } /** - * @return + * @return string */ public function getSenderId() { @@ -84,7 +84,7 @@ public function setSenderId($senderId) } /** - * @return + * @return string */ public function getClientId() { @@ -108,6 +108,8 @@ public function setClientId($clientId) * @param string $method * @param string $parameters * @return array + * @throws Exception\InvalidJsonException + * @throws Exception\MethodKeysNotExistsException */ public function call($method, $parameters) { @@ -121,16 +123,8 @@ public function call($method, $parameters) 'sender_id' => $this->senderId, ]); - ksort($httpParameters); - - // Получаем secret_key - $secretKeyBase = ''; - foreach ($httpParameters as $value) { - $secretKeyBase .= $value; - } - $secretKeyBase .= $this->methodKeys[$method]; - - $httpParameters['secret_key'] = md5($secretKeyBase); + $secretKey = md5($this->getPostValues($httpParameters) . $this->methodKeys[$method]); + $httpParameters['secret_key'] = $secretKey; // Выполняем запрос $httpResponse = $this->httpClient->request('POST', "https://delivery.yandex.ru/api/$this->apiVersion/$method", [ @@ -146,4 +140,15 @@ public function call($method, $parameters) return $json; } + + private function getPostValues($data) + { + if (!is_array($data)) { + return $data; + } + ksort($data); + return join('', array_map(function($k) { + return $this->getPostValues($k); + }, $data)); + } }