In order to access the service, you’ll need first to “sign” your URLs. In PHP, you don’t need any specific extension or file to do that. All you have to do is to copy and paste the following function into your code and call it where you want.
Name | Type | Summary |
---|---|---|
$urlDomain | string (required) | URL of the service (ex: http://uk.shoppingapis.kelkoo.com) |
$urlPath | string (required) | Path and query for the service (ex: /V3/productSearch?query=ipod) |
$partner | string (required) | Affiliate Id |
$key | string (required) | Affiliate secret key |
Please note that your query must be encoded if you use characters with accents. In PHP you can use urlencode()
.
function UrlSigner($urlDomain, $urlPath, $partner, $key){ settype($urlDomain, 'String'); settype($urlPath, 'String'); settype($partner, 'String'); settype($key, 'String'); $URL_sig = "hash"; $URL_ts = "timestamp"; $URL_partner = "aid"; $URLreturn = ""; $URLtmp = ""; $s = ""; // get the timestamp $time = time(); // replace " " by "+" $urlPath = str_replace(" ", "+", $urlPath); // format URL $URLtmp = $urlPath . "&" . $URL_partner . "=" . $partner . "&" . $URL_ts . "=" . $time; // URL needed to create the tokken $s = $urlPath . "&" . $URL_partner . "=" . $partner . "&" . $URL_ts . "=" . $time . $key; $tokken = ""; $tokken = base64_encode(pack('H*', md5($s))); $tokken = str_replace(array("+", "/", "="), array(".", "_", "-"), $tokken); $URLreturn = $urlDomain . $URLtmp . "&" . $URL_sig . "=" . $tokken; return $URLreturn; }
Simply call the function to generate the appropriate URL:
echo UrlSigner('http://uk.shoppingapis.kelkoo.com', '/V3/productSearch?query=ipod&sort=default_ranking&start=1&results=20&show_products=1&show_subcategories=1&show_refinements=1','123', 'PartnerKey');