<?php
function generateSignature($path, $payload, $secret, $expires) {
// Create the canonical string from expires and path
$canonical = "GET\n\n\n" . $expires . "\n" . $path . ($payload != null ? "\n" . $payload : "");
// for example GET 1452204987 /recoservice/1.0/recommendations/target/122711000061 containerCodes=a1wr-162ed67911cc
// Encrypt it with secret
$signatureBytes = hash_hmac("sha256", $canonical, $secret, true);
// Base64 encode the encrypted results and URL encode the base64
return urlencode(base64_encode($signatureBytes));
}
function generatecanonical($path, $payload, $secret, $expires) {
// Create the canonical string from expires and path
$canonical = "GET\n\n\n" . $expires . "\n" . $path . ($payload != null ? "\n" . $payload : "");
// for example GET 1452204987 /recoservice/1.0/recommendations/target/122711000061 containerCodes=a1wr-162ed67911cc
// Base64 encode the encrypted results and URL encode the base64
return $canonical;
}
$secret = "wbVx3n5/pgW0dTV/6nhW8QOVdr5HiWfZoXp1AcIJGfU="; //this is your secret API key that you can find in the Settings page
$a1accesskeyid = "507WRLEEPZSZFCKGFPKYOZJ"; //this is your public API key that you can find in the Settings page
$containerCodes = [
'a1wr-12ac7a9eb51a' //put your container codes here. No need for an array if you have only one container on that page
];
$targetId = "9780373622818"; //this is an example, $targetId should contain the variable you use on your page for your Product ID
$expires = time() + 900; //this makes API calls reusable for up to 15 min (900sec). You can make this longer or shorter, as you prefer (but not longer than 1h)
$pathToAgilOne = "/recoservice/1.0/recommendations/target/" . $targetId;
$payload = htmlentities('containerCodes=' . implode(',', $containerCodes));
$signature = generateSignature($pathToAgilOne, $payload, $secret, $expires);
$canonical = generatecanonical($pathToAgilOne, $payload, $secret, $expires);
?>
<!DOCTYPE html>
<html>
<head>
<title>A1 Electronics</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
}
</style>
</head>
<body style="padding: 0; margin: 0;">
<!-- Your page content -->
<div style="padding: 20px; border-bottom: 1px solid #ccc; background: #E6F1F7">
<div style="float: right;">
<a href="" style="text-decoration: none;">My Account | Wish List | Order Status | My Shopping Cart</a>
<div style="margin-top: 20px;">We take everything, except DISCOVER!</div>
</div>
<h1 style="padding: 0; margin: 0; color: #006699">A1 Electronics</h1>
<span>If we don't have what you're looking for, it doesn't exist</span>
</div>
<!-- The div in which we will place the AgilOne container (it's actually not necessary to encapsulate it in a div) -->
<div style="padding: 20px;">
<div style="margin-bottom: 30px; overflow: hidden; width: 800px;">
<?php foreach ($containerCodes as $containerCode) { ?>
<!-- note that this "for" loop isn't relevant for your website. You should put each div in the proper location for your website -->
<div id="<?= $containerCode ?>" style="margin-bottom: 20px;"></div> <!-- this is the div containing the actual container, and where it will show on the page -->
<?php } ?>
</div>
</div>
<!-- This part below is for the AgilOne Webtag. Don't re-implement it if you already have it on your page. -->
<script type='text/javascript'>
var _a1as = _a1as || [];
_a1as.push(["init","1234567"]);
_a1as.push(["track"]);
_a1as.push(["product_view", "<?= $targetId ?>"]);
</script>
<script type='text/javascript'>
(function() {
var a1s = document.createElement('script');
a1s.type = 'text/javascript';
a1s.async = true;
a1s.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'tr-1.agilone.com/tr-as.js';
var a1ss = document.getElementsByTagName('script')[0];
a1ss.parentNode.insertBefore(a1s, a1ss);
})();
</script>
<!-- End of the AgilOne Webtag script -->
<!-- This is the script for the AgilOne Web container -->
<script type='text/javascript'>
var _a1wr = {
target: '<?php echo $targetId ?>',
a1accesskeyid: '<?php echo $a1accesskeyid ?>',
expires: '<?php echo $expires ?>',
signature: '<?php echo $signature ?>',
containerCode: '<?php echo implode(',', $containerCodes) ?>',
apiHost: 'awrs.agilone.com',
apiPort: window.location.protocol === 'http:' ? '8080' : '8443',
_debug: true
};
</script>
<script src="//awrs.agilone.com/static/a1wr.min.js"></script>
<!-- End of AgilOne Web container script -->
<h1>signature is <?php echo $signature ?></h1>
<h2>
canonical is <?php echo $canonical ?>
</h2>
</body>
</html>
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).