-
Notifications
You must be signed in to change notification settings - Fork 0
/
direct-link.php
55 lines (42 loc) · 1.71 KB
/
direct-link.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
<?php
require_once 'common.php';
global $carId, $typeId, $optionCode, $colorPreference;
$totalRetryCount = 5;
$remainingRetryCounts = $totalRetryCount;
$selectedColor = null;
$circulationsList = null;
while (!$circulationsList && $remainingRetryCounts >= 1) {
$circulationsList = getCirculations($carId);
notify('tried for ' . ($totalRetryCount - $remainingRetryCounts) . 'th time. result: ' . json_encode($circulationsList));
$remainingRetryCounts--;
}
if ($remainingRetryCounts === 0)
die(json_encode([
'ok' => false,
'error' => 'No response from Iranecar',
'checks' => $totalRetryCount
]));
$circulation = selectCirculationFromList($circulationsList, $typeId);
$color = findAdorableColor($circulation, $colorPreference);
$option = findAdorableOption($circulation, $optionCode);
$links = getLinks($circulation, $color, $option);
echo json_encode([
'links' => $links,
'selected-color' => $color,
], JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
notify(json_encode($links, JSON_PRETTY_PRINT));
function getLinks($circulation, $color, $option) {
$pId = $circulation->productId; // or maybe productGroup / carId
$cId = $circulation->id;
$cRow = $circulation->crcl_row;
$col = $color->id;
$colCode = $color->colorCode;
$formLink = "https://bahman.iranecar.com/registration?pId=$pId&cId=$cId&cRow=$cRow&col=$col&colCode=$colCode";
if ($option)
$formLink .= '&op=' . $option->id;
return [
'select-type' => "https://bahman.iranecar.com/product-group/$pId/circulations/ticket/no-ticket",
'select-color' => "https://bahman.iranecar.com/product-group/$pId/circulation/$cId/options/ticket/no-ticket",
'form' => $formLink
];
}