From d5a9199b23f1d6e2ebb377f08f6b5424aaea75cd Mon Sep 17 00:00:00 2001 From: Yura Date: Fri, 24 Jun 2016 12:18:44 +0300 Subject: [PATCH] Generates a signature --- Odnoklassniki.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Odnoklassniki.php b/Odnoklassniki.php index e45fce6..fbb7bb9 100644 --- a/Odnoklassniki.php +++ b/Odnoklassniki.php @@ -47,14 +47,30 @@ protected function apiInternal($accessToken, $url, $method, array $params, array $params['access_token'] = $accessToken->getToken(); $params['application_key'] = $this->applicationKey; $params['method'] = str_replace('/', '.', str_replace('api/', '', $url)); - - $first = 'application_key=' . $this->applicationKey . 'method=' . $params['method']; - $second = md5($params['access_token'] . $this->clientSecret); - - $params['sig'] = md5($first . $second); + $params['sig'] = $this->sig($params, $params['access_token'], $this->clientSecret); return $this->sendRequest($method, $url, $params, $headers); } + + /** + * Generates a signature + * @param $vars array + * @param $accessToken string + * @param $secret string + * @return string + */ + protected function sig($vars, $accessToken, $secret) + { + ksort($vars); + $params = ''; + foreach ($vars as $key => $value) { + if (in_array($key, ['sig', 'access_token'])) { + continue; + } + $params .= "$key=$value"; + } + return md5($params . md5($accessToken . $secret)); + } /** * @inheritdoc