-
Notifications
You must be signed in to change notification settings - Fork 0
/
http-get-post.php
131 lines (116 loc) · 3.6 KB
/
http-get-post.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
<?php
// identifikace Business Application
define('BAID', 'demo');
// klientsky certifikat slouzici pro autentizaci
define('CERT', dirname(__FILE__) . '/demo.pem');
// certifikat autority RapidSSL, ktera vydala serverovy certifikat
define('CACERT', 'geotrust.crt');
// URL adresa HTTP GET/POST API (LinuxBox.cz SMS brana)
define('URL', 'https://www.ipsms.cz:8443/smsconnector/getpost/GP');
// poslat testovaci SMS - nejdrive zmente cilove cislo
define('SEND_SMS', false);
function smsgw($action = 'ping', $data = null) {
$postData = array(
'baID' => BAID,
'action' => $action
);
if (isset($data)) {
$postData = array_merge($postData, $data);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, URL);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CAINFO, CACERT);
curl_setopt($ch, CURLOPT_SSLCERT, CERT);
$response = curl_exec($ch);
if ($response === false) {
echo 'Connection error: ' . curl_error($ch) . "\n";
return null;
}
$output = array();
$arr = explode("\n", $response);
foreach ($arr as &$line) {
$line = trim($line);
if (!empty($line)) {
list($key, $value) = explode('=', $line, 2);
$output[$key] = $value;
}
}
curl_close($ch);
return $output;
}
echo "<h1>Demo application for HTTP GET/POST API</h1>\n";
echo "<p><a href=\"http://www.linuxbox.cz/ipsms\">http://www.linuxbox.cz/ipsms</a></p>\n";
// ping - vyzkouseni funkcnosti (spravne zadane parametry a aktivni ucet)
$result = smsgw('ping');
echo "<h2>ping</h2>\n";
echo "<pre>\n";
print_r($result);
echo "</pre>\n";
if ($result['code'] !== 'ISUC_000') {
echo "<strong>ERROR: " . $result['description'] . "</strong>\n";
exit();
}
if (SEND_SMS === true) {
// send - poslani SMS
$data = array(
// cilove cislo
'toNumber' => '+420123456789',
// text SMS
'text' => 'Server LinuxBox je určen společnostem libovolné velikosti s různorodými potřebami, kterým se dokáže snadno přizpůsobit. Jedná se o komplexní řešení s vysokou úrovní servisní podpory, která je jednou z klíčových filozofií společnosti LinuxBox.cz.',
// standardni SMS
'intruder' => false,
// s dorucenkou
'deliveryReport' => true,
// delsi SMS se rozdeli na vice casti
'multipart' => true
);
$result = smsgw('send', $data);
echo "<h2>send</h2>\n";
echo "<pre>\n";
print_r($result);
echo "</pre>\n";
if ($result['code'] !== 'ISUC_001') {
echo "<strong>ERROR: " . $result['description'] . "</strong>\n";
exit();
}
}
while (true) {
// receive - precteni dorucenky nebo prichozi SMS
$result = smsgw('receive');
if (empty($result)) {
break;
}
echo "<h2>receive</h2>\n";
echo "<pre>\n";
print_r($result);
echo "</pre>\n";
if ($result['selector'] === 'Response') {
// dorucenka
if ($result['code'] === 'ISUC_005') {
echo "<strong>Zprava byla dorucena - ID: " . $result['msgID'] . "</strong>\n";
}
} else if ($result['selector'] === 'TextSms') {
// prichozi zprava
echo "<strong>Prichozi SMS od " . $result['fromNumber'] .
", text zpravy: " . $result['text'] . "</strong>\n";
}
// confirm - potvrzeni, ze byla zprava systemem zpracovana
// a muze se pri pristim volani receive zobrazit dalsi zprava v poradi
$data = array(
'refMsgID' => $result['msgID'],
'refBaID' => $result['baID']
);
$result = smsgw('confirm', $data);
echo "<h2>confirm</h2>\n";
echo "<pre>\n";
print_r($result);
echo "</pre>\n";
if ($result['code'] !== 'ISUC_002') {
echo "<strong>ERROR: " . $result['description'] . "</strong>\n";
exit();
}
}