-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-points.php
59 lines (52 loc) · 1.79 KB
/
update-points.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
<?php
$settings = [
'acsCompanyID' => '',
'acsCompanyPassword' => '',
'acsUserID' => '',
'acsUserPassword' => '',
'acsApiKey' => '',
];
$content = [
'ACSAlias' => 'ACS_Get_Stations_For_Plugin',
'ACSInputParameters' => [
'locale' => null,
'Company_ID' => $settings['acsCompanyID'],
'Company_Password' => $settings['acsCompanyPassword'],
'User_ID' => $settings['acsUserID'],
'User_Password' => $settings['acsUserPassword'],
],
];
$url = "https://webservices.acscourier.net/ACSRestServices/api/ACSAutoRest";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array(
'Accept: application/json',
'Content-Type: application/json',
'ACSApiKey: '.$settings['acsApiKey'],
)
);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($content));
$json_response = curl_exec($curl);
curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$response = json_decode($json_response, true);
$points = $response['ACSOutputResponce']['ACSTableOutput']['Table_Data1'] ?? [];
$points = array_values(array_filter($points, function ($item) {
return $item['type'] !== 'branch' || $item['Acs_Station_Branch_Destination'] == '1';
}));
$data = [
'code' => curl_getinfo($curl, CURLINFO_HTTP_CODE),
'meta' => $response['ACSOutputResponce']['ACSTableOutput']['Table_Data'] ?? [],
'points' => $points ?? [],
];
file_put_contents(
__DIR__.'/data.json',
json_encode([
'timestamp' => date('Y-m-d H:i'),
'meta' => $response['ACSOutputResponce']['ACSTableOutput']['Table_Data'] ?? [],
'points' => $points ?? [],
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
);