-
Notifications
You must be signed in to change notification settings - Fork 2
/
debug.speedy.php
136 lines (118 loc) · 4.42 KB
/
debug.speedy.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/* Enable for Debugging Purposes only */
ini_set('display_errors', 1) ;
ini_set('display_startup_errors', 1) ;
error_reporting(E_ALL) ;
require_once( $_SERVER['DOCUMENT_ROOT'] . '/access.inc.php' ) ;
require_once( $_SERVER['DOCUMENT_ROOT'] . '/config.inc.php' ) ;
require_once( $_SERVER['DOCUMENT_ROOT'] . '/feedback.php' ) ;
/* Determine parcel sender */
if ( isset ($_GET['p'] ) && !empty ($_GET['p'] ) ) {
$parcel_id = htmlspecialchars($_GET['p']) ;
if (preg_match(PATTERN_SPEEDY, $parcel_id)) {
echo '<h2>Доставка<span class="optional">та се изпълнява</span> чрез <span class="speedy">Спиди</span>. Хронология<span class="optional"> на събитията</span>:</h2></div>' ;
printSpeedy($parcel_id) ;
} else {
/* Replace echo statement with something else if you want to modify */
/* page behavior for people who land on page without a tracking no. */
echo '<h2>Необходимо е да подадете заявка с номер на товарителница</h2>' ;
die() ;
}
}
function printSpeedy($parcel_id) {
/* Make API request */
$reqURL = SPEEDY_API_BASE . SPEEDY_API_CMD_TRACK . '?userName=' . SPEEDY_USER . '&password=' . SPEEDY_PASS . '&language=' . $language_id . '&parcels=' . $parcel_id ;
$curl = curl_init() ;
curl_setopt_array($curl, array(
CURLOPT_URL => $reqURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 1,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
)) ;
$response = curl_exec($curl) ;
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE) ;
if ( $status != 200 )
{
die("Error: call to URL $reqURL failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)) ;
}
curl_close($curl) ;
echo "<h2>Raw output</h2>\n" ;
echo "<pre>\n" ;
var_dump ($response) ;
echo "</pre>\n" ;
echo "<hr><br>\n" ;
/* Interpret request output */
$data = json_decode($response, true) ;
$operations = $data['parcels']['0']['operations'] ;
echo "<h2>JSON Decode</h2>\n" ;
echo "<pre>\n" ;
var_dump ($operations) ;
echo "</pre>\n" ;
echo "<hr><br>\n" ;
/* Print data */
for($i=0; $i < count($operations); $i++) {
$opdate = $operations[$i]['dateTime'] ;
$opdate = strtotime($opdate) ;
$opdate = date('d.m.Y H:i', $opdate) ;
$opcode = $operations[$i]['operationCode'] ;
$opstatus = $operations[$i]['description'] ;
/* Checking for DPD Predict */
if (175 === $opcode)
{
$predict = $operations[$i]['comment'] ;
}
/*
echo '<div class="monospaced">' ;
echo '<span class="timestamp">' . $opdate . '</span>' ;
echo '<span class="monoblocked-inline">' . $opstatus . '</span>' ;
echo '</div>' ;
*/
}
/* Check if there is office location data */
$reqURL = SPEEDY_API_BASE . SPEEDY_API_CMD_RCV_OFFICE . '?userName=' . SPEEDY_USER . '&password=' . SPEEDY_PASS . '&language=' . $language_id . '&shipmentIds=' . $parcel_id ;
$curl = curl_init() ;
curl_setopt_array($curl, array(
CURLOPT_URL => $reqURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 1,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
)) ;
$response = curl_exec($curl) ;
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE) ;
if ( $status != 200 )
{
die("Error: call to URL $reqURL failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)) ;
}
curl_close($curl) ;
$data = json_decode($response, true) ;
echo "<h2>Speedy Receive Office Data</h2>\n" ;
echo "<pre>\n" ;
var_dump ($data) ;
echo "</pre>\n" ;
echo "<hr><br>\n" ;
$collect = $data['shipments']['0']['recipient']['pickupOfficeId'] ;
echo "<h2>Office ID output</h2>\n" ;
echo "<pre>\n" ;
var_dump ($collect) ;
echo "</pre>\n" ;
echo "<hr><br>\n" ;
/*
if (-14 === $opcode) { // Package has been delivered
echo '<h3 class="h3delivered">Пратката е доставена</h3>' . "\n" ;
feedbackRequestGoogle() ;
} elseif ($collect) { // Package has been sent to office and is not yet delivered
echo '<h3 class="h3map">Локация и работно време:</h3>' ;
echo '<div class="map">' ;
echo '<iframe class="ifmap" src="https://services.speedy.bg/officesmap?lang=bg&id=' . $collect . '">' ;
echo '</div>' ;
}
*/
}