Created
June 29, 2012 08:22
-
-
Save basvandorst/3016638 to your computer and use it in GitHub Desktop.
Example Zend Bol.com REST Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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