|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BongaTech SMS Client Library for PHP. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2017 |
|
6
|
|
|
* @author Vincent Mosoti <[email protected]> |
|
7
|
|
|
* @license https://github.com/VMosoti/bongatech-sms/blob/master/LICENSE |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace VMosoti\BongaTech; |
|
11
|
|
|
|
|
12
|
|
|
use VMosoti\BongaTech\Exceptions\BatchTypeNotSetException; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class SMS |
|
16
|
|
|
* @package VMosoti\BongaTech |
|
17
|
|
|
*/ |
|
18
|
|
|
class SMS |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Version number of the SMS API. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
const VERSION = '1.0'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* user ID registered in Bongatech. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $user_id; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* password for Bongatech. |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $password; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* token is generated by md5(password). |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $token; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* timestamp is the current datetime. |
|
50
|
|
|
* |
|
51
|
|
|
* @var string |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $timestamp; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* type of SMS to sent. |
|
57
|
|
|
* |
|
58
|
|
|
* @var int message |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $message_type; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* batch type of the SMS being sent. |
|
64
|
|
|
* |
|
65
|
|
|
* @var int batch |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $batch_type; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* the alphanumeric of the sender. |
|
71
|
|
|
* |
|
72
|
|
|
* @var string |
|
73
|
|
|
*/ |
|
74
|
|
|
protected $sender_id; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* the url on which delivery reports will be sent. |
|
78
|
|
|
* |
|
79
|
|
|
* @var string callback_url. |
|
80
|
|
|
*/ |
|
81
|
|
|
protected $callback_url; |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* recipient/recipients of the SMS being sent. |
|
86
|
|
|
* @var string/array. |
|
87
|
|
|
*/ |
|
88
|
|
|
protected $recipients; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* the message being sent (array of messages in case message is different for each user. |
|
92
|
|
|
* |
|
93
|
|
|
* @var string/array. |
|
94
|
|
|
*/ |
|
95
|
|
|
protected $message; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Bongatech end point |
|
99
|
|
|
* |
|
100
|
|
|
* @var string end point. |
|
101
|
|
|
*/ |
|
102
|
|
|
protected $endpoint = 'http://197.248.2.55/smsapi_test/submit.php'; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* SMS constructor. |
|
106
|
|
|
* @param string $user_id |
|
107
|
|
|
* @param string $password |
|
108
|
|
|
* @param string $sender_id |
|
109
|
|
|
* @param string $callback_url |
|
110
|
|
|
*/ |
|
111
|
|
|
public function __construct($user_id, $password, $sender_id, $callback_url) |
|
112
|
|
|
{ |
|
113
|
|
|
$this->user_id = $user_id; |
|
114
|
|
|
$this->password = $password; |
|
115
|
|
|
$this->sender_id = $sender_id; |
|
116
|
|
|
$this->callback_url = $callback_url; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* set the token |
|
121
|
|
|
*/ |
|
122
|
|
|
private function setToken() |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
|
|
125
|
|
|
$this->token = md5($this->password); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* set the timestamp |
|
130
|
|
|
*/ |
|
131
|
|
|
private function setTimestamp() |
|
|
|
|
|
|
132
|
|
|
{ |
|
133
|
|
|
|
|
134
|
|
|
$this->timestamp = date('YmdHis'); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* invoke if SMS being sent is of type subscribable. |
|
139
|
|
|
* |
|
140
|
|
|
* @return $this |
|
141
|
|
|
*/ |
|
142
|
|
|
public function subscribable() |
|
143
|
|
|
{ |
|
144
|
|
|
$this->message_type = MessageType::SUBSCIBABLE; |
|
145
|
|
|
|
|
146
|
|
|
return $this; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* invoke if SMS being sent is of type on demand. |
|
151
|
|
|
* |
|
152
|
|
|
* @return $this |
|
153
|
|
|
*/ |
|
154
|
|
|
public function onDemand() |
|
155
|
|
|
{ |
|
156
|
|
|
$this->message_type = MessageType::ON_DEMAND; |
|
157
|
|
|
|
|
158
|
|
|
return $this; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* invoke if SMS being sent is of type bulk SMS. This will be the common one. |
|
163
|
|
|
* @return $this |
|
164
|
|
|
*/ |
|
165
|
|
|
public function bulk() |
|
166
|
|
|
{ |
|
167
|
|
|
|
|
168
|
|
|
$this->message_type = MessageType::BULK; |
|
169
|
|
|
|
|
170
|
|
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* invoke if SMS is being sent to a single recipient. |
|
175
|
|
|
* |
|
176
|
|
|
* @return $this |
|
177
|
|
|
*/ |
|
178
|
|
|
public function noBatch() |
|
179
|
|
|
{ |
|
180
|
|
|
|
|
181
|
|
|
$this->batch_type = BatchType::NOT_BATCH; |
|
182
|
|
|
|
|
183
|
|
|
return $this; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* invoke if SMS is being sent to a different recipients. |
|
188
|
|
|
* |
|
189
|
|
|
* @return $this |
|
190
|
|
|
*/ |
|
191
|
|
|
public function sameMessage() |
|
192
|
|
|
{ |
|
193
|
|
|
|
|
194
|
|
|
$this->batch_type = BatchType::SAME_MESSAGE; |
|
195
|
|
|
|
|
196
|
|
|
return $this; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* invoke if each recipient will receive a different message. |
|
201
|
|
|
* |
|
202
|
|
|
* @return $this |
|
203
|
|
|
*/ |
|
204
|
|
|
public function differentMessages() |
|
205
|
|
|
{ |
|
206
|
|
|
|
|
207
|
|
|
$this->batch_type = BatchType::DIFFERENT_MESSAGE; |
|
208
|
|
|
|
|
209
|
|
|
return $this; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* |
|
214
|
|
|
*/ |
|
215
|
|
|
public function send() |
|
216
|
|
|
{ |
|
217
|
|
|
if ($this->batch_type == BatchType::NOT_BATCH) { |
|
|
|
|
|
|
218
|
|
|
|
|
219
|
|
|
} elseif ($this->batch_type == BatchType::SAME_MESSAGE) { |
|
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
} elseif ($this->batch_type == BatchType::DIFFERENT_MESSAGE) { |
|
|
|
|
|
|
222
|
|
|
|
|
223
|
|
|
} else { |
|
224
|
|
|
|
|
225
|
|
|
throw new BatchTypeNotSetException("Message Batch Type has not been set."); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* send a message to a single recipient. |
|
232
|
|
|
* |
|
233
|
|
|
* @param Request $request |
|
234
|
|
|
*/ |
|
235
|
|
|
private function sendForNoBatch(Request $request) |
|
|
|
|
|
|
236
|
|
|
{ |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* send same message to different recipients. |
|
241
|
|
|
* |
|
242
|
|
|
* @param Request $request |
|
243
|
|
|
*/ |
|
244
|
|
|
private function sendForSameMessage(Request $request) |
|
|
|
|
|
|
245
|
|
|
{ |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* send different message to different recipients |
|
250
|
|
|
* |
|
251
|
|
|
* @param Request $request |
|
252
|
|
|
*/ |
|
253
|
|
|
private function sendForDifferentMessages(Request $request) |
|
|
|
|
|
|
254
|
|
|
{ |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
|
|
258
|
|
|
} |
|
259
|
|
|
|