Skip to content

Commit

Permalink
Generates a signature
Browse files Browse the repository at this point in the history
  • Loading branch information
KhristenkoYura authored Jun 24, 2016
1 parent 3dee1d2 commit d5a9199
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Odnoklassniki.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d5a9199

Please sign in to comment.