1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| <!doctype html>
<html>
<head>
<title>Titre de la page</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<?php
$server_url = "https://sandbox.cardmarket.com/ws/v2.0/output.json/";
$method = "GET";
$url = $server_url."stock/shoppingcart-articles";
$appToken = "";
$appSecret = "";
$accessToken = "";
$accessSecret = "";
$nonce = uniqid();
$timestamp = time();
$signatureMethod = "HMAC-SHA1";
$version = "1.0";
$params = array(
'realm' => $url,
'oauth_consumer_key' => $appToken,
'oauth_token' => $accessToken,
'oauth_nonce' => $nonce,
'oauth_timestamp' => $timestamp,
'oauth_signature_method' => $signatureMethod,
'oauth_version' => $version,
);
$baseString = strtoupper($method) . "&";
$baseString .= rawurlencode($url) . "&";
/* Gather, encode, and sort the base string parameters */
$encodedParams = array();
foreach ($params as $key => $value)
{
if ("realm" != $key)
{
$encodedParams[rawurlencode($key)] = rawurlencode($value);
}
}
ksort($encodedParams);
/* Expand the base string by the encoded parameter=value pairs */
$values = array();
foreach ($encodedParams as $key => $value)
{
$values[] = $key . "=" . $value;
}
$paramsString = rawurlencode(implode("&", $values));
$baseString .= $paramsString;
/*
* Create the signingKey
*/
$signatureKey = rawurlencode($appSecret) . "&" . rawurlencode($accessSecret);
/**
* Create the OAuth signature
* Attention: Make sure to provide the binary data to the Base64 encoder
*
* @var $oAuthSignature string OAuth signature value
*/
$rawSignature = hash_hmac("sha1", $baseString, $signatureKey, true);
$oAuthSignature = base64_encode($rawSignature);
/*
* Include the OAuth signature parameter in the header parameters array
*/
$params['oauth_signature'] = $oAuthSignature;
/*
* Construct the header string
*/
$header = "Authorization: OAuth ";
$headerParams = array();
foreach ($params as $key => $value)
{
$headerParams[] = $key . "=\"" . $value . "\"";
}
$header .= implode(", ", $headerParams);
/*
* Get the cURL handler from the library function
*/
$curlHandle = curl_init();
/*
* Set the required cURL options to successfully fire a request to MKM's API
*/
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array($header));
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
/**
* Execute the request, retrieve information about the request and response, and close the connection
*
* @var $content string Response to the request
* @var $info array Array with information about the last request on the $curlHandle
*/
$content = curl_exec($curlHandle);
$info = curl_getinfo($curlHandle);
curl_close($curlHandle);
/*
* Convert the response string into an object
*
* If you have chosen XML as response format (which is standard) use simplexml_load_string
* If you have chosen JSON as response format use json_decode
*
* @var $decoded \SimpleXMLElement|\stdClass Converted Object (XML|JSON)
*/
$decoded = json_decode($content, true);
if(!empty($decoded->results))
{
foreach($decoded->results as $data)
{
echo "<u>" . $data->seller['name']."</u> : ". $data->buyer['name'];
echo "<br />";
}
}
else
{
echo 'Rien ici';
}
?>
</body>
</html> |
Partager