-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.php
86 lines (67 loc) · 3.09 KB
/
index.php
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
<?
$card = $_GET['card'];
$var = urlencode($card);
//min 3 chars
$method = "GET";
$url = "https://api.cardmarket.com/ws/v2.0/output.json/stock/articles/$var/1"; //example for search stock
$appToken = "CHANGE THIS";
$appSecret = "CHANGE THIS";
$accessToken = "CHANGE THIS";
$accessSecret = "CHANGE THIS";
$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) . "&";
$encodedParams = array();
foreach ($params as $key => $value) { if ("realm" != $key) { $encodedParams[rawurlencode($key)] = rawurlencode($value); } }
ksort($encodedParams);
$values = array();
foreach ($encodedParams as $key => $value) { $values[] = $key . "=" . $value; }
$paramsString = rawurlencode(implode("&", $values));
$baseString .= $paramsString;
$signatureKey = rawurlencode($appSecret) . "&" . rawurlencode($accessSecret);
$rawSignature = hash_hmac("sha1", $baseString, $signatureKey, true);
$oAuthSignature = base64_encode($rawSignature);
$params['oauth_signature'] = $oAuthSignature;
$header = "Authorization: OAuth ";
$headerParams = array();
foreach ($params as $key => $value) { $headerParams[] = $key . "=\"" . $value . "\""; }
$header .= implode(", ", $headerParams);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($ch);
curl_close($ch);
$decoded = json_decode($content, true);
//var_dump($decoded);
echo "Stock matching results for '$card':<br>";
foreach ($decoded as $key) {
for($i = 0; $i < sizeof($key); $i++) {
$name = $key[$i]['product']['enName'];
$rarity = $key[$i]['product']['rarity'];
$condition = $key[$i]['condition'];
if(empty($key[$i]['isFoil'])) { $foil = ""; } else { $foil = ", FOIL"; } ;
if(empty($key[$i]["isSigned"])) { $signed = ""; } else { $signed = ", SIGNED"; } ;
if(empty($key[$i]["isPlayset"])) { $playset = ""; } else { $playset = ", PLAYSET"; } ;
if(empty($key[$i]["isAltered"])) { $altered = ""; } else { $altered = ", ALTERED"; } ;
$price = $key[$i]['price'];
$quantity = $key[$i]['count'];
//$cardimage = $key[$i]['image'];
$expantion = $key[$i]["expansion"];
$language = $key[$i]["language"]['languageName'];
echo $quantity."x<b>$name</b> - $rarity [$language] - $condition @ ".$price."€$foil $signed $playset $altered<br>";
}
}