-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorders.php
More file actions
65 lines (45 loc) · 1.41 KB
/
Copy pathorders.php
File metadata and controls
65 lines (45 loc) · 1.41 KB
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
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Cookie\SetCookie;
$baseUrl = 'http://localhost:8000';
function getOrder(string $baseUrl): string
{
$apiKey = readline('provide your API key: ');
$params = [
'key' => $apiKey
];
$client = new Client(['base_uri' => $baseUrl]);
$jar = new CookieJar();
$jar->setCookie(new SetCookie([
'Name' => 'PHPSESSID',
'Value' => session_id(),
'Domain' => 'localhost',
'Path' => '/',
'Expires' => time() + 3600,
]));
$tokenResponse = $client->post("/index.php?route=api/login", [
'form_params' => $params,
'cookies' => $jar,
]);
$tokenResponseBody = json_decode($tokenResponse->getBody()->getContents());
if (isset($tokenResponseBody->token)) {
$token = $tokenResponseBody->token;
} else {
return "Login error\n";
}
$orderId = readline("provide order id: ");
$response = $client->get("/index.php?route=api/order/info&token=$token&order_id=$orderId", [
'cookies' => $jar,
]);
$responseBody = json_decode($response->getBody()->getContents());
if (isset($responseBody->order)) {
return json_encode($responseBody->order, JSON_PRETTY_PRINT) . "\n";
} else {
return "Not available.";
}
}
session_start();
session_write_close();
echo getOrder($baseUrl);