-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
executable file
·127 lines (96 loc) · 3.27 KB
/
api.php
File metadata and controls
executable file
·127 lines (96 loc) · 3.27 KB
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
<?php
class seven_API {
public $api_key;
public $error;
public $rid = 0;
public function __construct() {
}
public function set_credentials($api_key = '') {
$this->api_key = $api_key;
}
public function Submit($title = null, $message = null, $number = 0) {
$recipients = [];
foreach (is_array($number) ? $number : [$number] as $n) $recipients[] = $n;
$json_data = [
'from' => $title,
'json' => 1,
'text' => $message,
'to' => implode(',', $recipients),
];
$solve = $this->curl_use('sms', $json_data);
if (!$solve) {
$this->error = 'The API response could not be resolved.';
return false;
}
if ('100' !== $solve['success']) {
$this->error = 'Error: <' . $solve['success'] . '>';
return false;
}
$message = $solve->messages;
if (!$message || !isset($message['id'])) {
$this->error = print_r($solve, true);
return false;
}
$this->rid = $message->id;
return true;
}
private function curl_use($endpoint, $post_data = []) {
$ch = curl_init('https://gateway.seven.io/api/' . $endpoint);
$options = [
CURLOPT_HEADER => 0,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'SentWith: WISECP',
'X-Api-Key: ' . $this->api_key,
],
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 60,
];
if ($post_data) {
$options[CURLOPT_POST] = 1;
$options[CURLOPT_POSTFIELDS] = Utility::jencode($post_data);
}
curl_setopt_array($ch, $options);
$res = curl_exec($ch);
return '900' === $res ? false : Utility::jdecode($res, true);
}
public function Balance() {
error_log('wisecp.sms.balance'); // TODO: remove!
syslog(LOG_INFO, 'wisecp.sms.balance'); // TODO: remove!
$solve = $this->curl_use('balance');
if (!$solve) {
$this->error = 'The API response could not be resolved.';
return false;
}
return [
'balance' => $solve,
'currency' => 'EUR',
];
}
public function ReportLook($rid) {
$outcome = $this->curl_use('status?msg_id=' . $rid);
$lines = explode(PHP_EOL, $outcome);
if (count($lines) !== 2) {
$this->error = 'The API response could not be resolved.';
return false;
}
return reset($lines);
}
public function get_prices() {
$solve = $this->curl_use('pricing');
$rows = [];
if (isset($solve['countries'])) {
foreach ($solve['countries'] as $row) {
$network = reset($row['networks']);
if (!$network) continue;
$rows[] = [
'countryCode' => $row['countryCode'],
'prices' => [
'EUR' => $network['price'],
],
];
}
}
return $rows;
}
}