-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.php
117 lines (94 loc) · 3.05 KB
/
app.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
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
<?php
require_once 'vendor/autoload.php';
if (!array_key_exists('eventId', $_GET)) {
$_GET['eventId'] = '9c32f00e-f025-41e5-88ce-bbcb2d9c7e24';
}
$eventId = filter_var(
$_GET['eventId'],
FILTER_VALIDATE_REGEXP,
['options' => ['regexp' => '/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$/i']]
);
if ($eventId === false) {
die("invalid eventId");
}
$response = [
'is_active' => -1,
'is_for_sale' => -1,
'quantity' => -1,
'is_for_booking' => -1,
];
$client = new GuzzleHttp\Client();
try {
$res = $client->request('GET',
"https://v-a-c-special.lastick.ru/api/widget/v1/schedule/$eventId/tickets",
[
'headers' => [
'authority' => 'v-a-c-special.lastick.ru',
'sec-ch-ua' => ' Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"',
'accept' => 'application/json, text/plain, */*',
'authorization' => ''
]
]
);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$log = sprintf(
"request failed - %s\nheaders: %s;\nresponse data: %s",
$e->getMessage(),
json_encode($e->getResponse()->getHeaders()),
$e->getResponse()->getBody()->getContents()
);
log1($log);
die(500);
}
$body = $res->getBody()->getContents();
$body = json_decode($body, true);
if (json_last_error() !== JSON_ERROR_NONE) {
log1("json decode error: " . json_last_error_msg());
die(500);
}
if (!array_key_exists('tickets', $body)) {
log1("response key 'tickets' missed");
die(500);
}
$tickets = $body['tickets'];
if (!is_array($tickets) || count($tickets) != 1) {
log1("invalid value in 'tickets': " . json_encode($tickets));
die(500);
}
$tickets = $tickets[0];
if (!array_key_exists('quantity', $tickets)) {
log1("response key 'tickets.quantity' missed");
die(500);
}
if (!array_key_exists('is_for_sale', $tickets)) {
log1("response key 'tickets.is_for_sale' missed");
die(500);
}
if (!array_key_exists('is_active', $tickets)) {
log1("response key 'tickets.is_active' missed");
die(500);
}
if (!array_key_exists('is_for_booking', $tickets)) {
log1("response key 'tickets.is_for_booking' missed");
die(500);
}
$response['quantity'] = (int)$tickets['quantity'];
$response['is_for_sale'] = (int)$tickets['is_for_sale'];
$response['is_active'] = (int)$tickets['is_active'];
$response['is_for_booking'] = (int)$tickets['is_for_booking'];
printResponse($response, $eventId);
//---
function printResponse(array $response, string $eventId) {
header('content-type: text/plain; version=0.0.4');
foreach ($response as $key => $val) {
echo "$key{eventId=\"$eventId\"} $val\n";
}
}
function log1(string $log) {
$log = sprintf(
"[%s] %s\n",
(new \DateTime)->format('c'),
$log
);
file_put_contents('ges.log', $log , FILE_APPEND);
}