Skip to content

Instantly share code, notes, and snippets.

@basvandorst
Created June 29, 2012 08:22
Show Gist options
  • Save basvandorst/3016638 to your computer and use it in GitHub Desktop.
Save basvandorst/3016638 to your computer and use it in GitHub Desktop.
Example Zend Bol.com REST Controller
<?php
class BolController extends Zend_Controller_Action {
private function getSignature($date, $httpMethod, $url, $contentType, $queryParams) {
$signature = $httpMethod . "\n\n";
$signature .= $contentType . "\n";
$signature .= $date."\n";
$signature .= "x-openapi-date:" . $date . "\n";
$signature .= $url."\n";
$publicKey = "XX";
$privateKey = "YY";
return $publicKey . ':' . base64_encode(hash_hmac('SHA256', $signature, $privateKey, true));
}
public function indexAction() {
$contentType = "application/xml";
$today = gmdate('D, d F Y H:i:s \G\M\T');
$httpMethod = "GET";
$url = '/openapi/services/rest/catalog/v3/products/1001004006016448/';
$parameters = '';
$signature = $this->getSignature($today, $httpMethod, $url, $contentType, $parameters);
$headers = array(
"Content-type" => $contentType,
"X-OpenAPI-Authorization" => $signature,
"X-OpenAPI-Date" => $today
);
$rest = new Zend_Rest_Client("https://openapi.bol.com/");
$rest->setNoReset(true);
$http = $rest->getHttpClient();
$http->setHeaders($headers);
$rest->setHttpClient($http);
echo $rest->restGet($url);
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment