1 | <?php |
||
12 | abstract class AbstractNetgsmMessage |
||
13 | { |
||
14 | private const SUCCESS_CODES = [ |
||
15 | '00', '01', '02', |
||
16 | ]; |
||
17 | |||
18 | protected $sendMethods = ['xml', 'get']; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $sendMethod; |
||
24 | |||
25 | /** |
||
26 | * @var string[] |
||
27 | */ |
||
28 | protected $recipients = []; |
||
29 | |||
30 | /** |
||
31 | * @var null |
||
32 | */ |
||
33 | protected $header = null; |
||
34 | |||
35 | /** |
||
36 | * @var Carbon |
||
37 | */ |
||
38 | protected $startDate; |
||
39 | |||
40 | /** |
||
41 | * @var Carbon |
||
42 | */ |
||
43 | protected $endDate; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $code; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $jobId; |
||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $defaults = []; |
||
59 | /** |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $credentials = []; |
||
63 | /** |
||
64 | * @var ClientInterface |
||
65 | */ |
||
66 | protected $client; |
||
67 | /** |
||
68 | * @var string endpoint url |
||
69 | */ |
||
70 | protected $url; |
||
71 | /** |
||
72 | * @var string message |
||
73 | */ |
||
74 | protected $message; |
||
75 | |||
76 | /** |
||
77 | * authorized data parameter |
||
78 | * |
||
79 | * @see https://www.netgsm.com.tr/dokuman/#http-get-sms-g%C3%B6nderme |
||
80 | * @see https://www.netgsm.com.tr/dokuman/#xml-post-sms-g%C3%B6nderme |
||
81 | * |
||
82 | * @var bool |
||
83 | */ |
||
84 | protected $authorizedData = false; |
||
85 | |||
86 | /** |
||
87 | * @var ResponseInterface |
||
88 | */ |
||
89 | protected $response; |
||
90 | |||
91 | /** |
||
92 | * @var array |
||
93 | */ |
||
94 | protected $fields = []; |
||
95 | |||
96 | /** |
||
97 | * @var array |
||
98 | */ |
||
99 | protected $errorCodes; |
||
100 | |||
101 | /** |
||
102 | * @param string $message |
||
103 | * @param array $defaults |
||
104 | * @return static |
||
105 | */ |
||
106 | public static function create(string $message = null, array $defaults = []) |
||
110 | |||
111 | /** |
||
112 | * AbstractNetgsmMessage constructor. |
||
113 | * @param array $defaults |
||
114 | * @param string $message |
||
115 | */ |
||
116 | public function __construct(string $message = null, array $defaults = []) |
||
121 | |||
122 | /** |
||
123 | * @return array |
||
124 | */ |
||
125 | abstract protected function mappers(): array; |
||
126 | |||
127 | abstract protected function createXmlPost(): string; |
||
128 | |||
129 | /** |
||
130 | * @param string|array|$recipients |
||
131 | * @return $this |
||
132 | */ |
||
133 | public function setRecipients($recipients) |
||
143 | |||
144 | /** |
||
145 | * @return string[] |
||
146 | */ |
||
147 | public function getRecipients(): array |
||
151 | |||
152 | /** |
||
153 | * @param null $header |
||
154 | * @return AbstractNetgsmMessage |
||
155 | */ |
||
156 | public function setHeader($header): self |
||
162 | |||
163 | /** |
||
164 | * @return string |
||
165 | */ |
||
166 | public function getHeader(): string |
||
170 | |||
171 | /** |
||
172 | * @param string $message |
||
173 | * @return AbstractNetgsmMessage |
||
174 | */ |
||
175 | public function setMessage(string $message): self |
||
181 | |||
182 | /** |
||
183 | * @return string |
||
184 | */ |
||
185 | public function getMessage(): string |
||
189 | |||
190 | /** |
||
191 | * @return string |
||
192 | */ |
||
193 | public function getSendMethod(): string |
||
197 | |||
198 | /** |
||
199 | * @param string $sendMethod |
||
200 | * @return $this |
||
201 | * @throws Exception |
||
202 | */ |
||
203 | public function setSendMethod(string $sendMethod): self |
||
212 | |||
213 | /** |
||
214 | * @return bool |
||
215 | */ |
||
216 | public function isAuthorizedData(): bool |
||
220 | |||
221 | /** |
||
222 | * |
||
223 | * @param bool $authorizedData |
||
224 | * @return AbstractNetgsmMessage |
||
225 | */ |
||
226 | public function setAuthorizedData(bool $authorizedData): AbstractNetgsmMessage |
||
231 | |||
232 | /** |
||
233 | * @return string |
||
234 | */ |
||
235 | public function getUrl(): string |
||
239 | |||
240 | /** |
||
241 | * @throws IncorrectPhoneNumberFormatException |
||
242 | */ |
||
243 | protected function validateRecipients(): void |
||
254 | |||
255 | /** |
||
256 | * @return string |
||
257 | */ |
||
258 | public function body(): array |
||
262 | |||
263 | /** |
||
264 | * @param mixed $client |
||
265 | * @return AbstractNetgsmMessage |
||
266 | */ |
||
267 | public function setClient(ClientInterface $client): self |
||
273 | |||
274 | /** |
||
275 | * @param array $defaults |
||
276 | * @return AbstractNetgsmMessage |
||
277 | */ |
||
278 | public function setDefaults(array $defaults): self |
||
284 | |||
285 | /** |
||
286 | * @param array $credentials |
||
287 | * @return AbstractNetgsmMessage |
||
288 | */ |
||
289 | public function setCredentials(array $credentials): self |
||
295 | |||
296 | /** |
||
297 | * @param Carbon $startDate |
||
298 | * @return AbstractNetgsmMessage |
||
299 | */ |
||
300 | public function setStartDate(Carbon $startDate): self |
||
305 | |||
306 | /** |
||
307 | * @param Carbon $endDate |
||
308 | * @return AbstractNetgsmMessage |
||
309 | */ |
||
310 | public function setEndDate(Carbon $endDate): self |
||
315 | |||
316 | /** |
||
317 | * @return string |
||
318 | */ |
||
319 | protected function getResponseContent(): string |
||
323 | |||
324 | /** |
||
325 | * @return mixed |
||
326 | */ |
||
327 | public function getJobId(): string |
||
331 | |||
332 | /** |
||
333 | * @return $this |
||
334 | * @throws CouldNotSendNotification |
||
335 | */ |
||
336 | public function parseResponse(): self |
||
354 | |||
355 | /** |
||
356 | * @return $this |
||
357 | * @throws CouldNotSendNotification |
||
358 | * @throws IncorrectPhoneNumberFormatException |
||
359 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
360 | */ |
||
361 | protected function sendViaGet(): self |
||
362 | { |
||
363 | $query = http_build_query($this->body()); |
||
364 | |||
365 | $this->response = $this->client->request('GET', $this->getUrl().'?'.$query); |
||
366 | |||
367 | return $this->parseResponse(); |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * @return $this |
||
372 | * @throws CouldNotSendNotification |
||
373 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
374 | */ |
||
375 | protected function sendViaXml(): self |
||
388 | |||
389 | /** |
||
390 | * @return $this |
||
391 | * @throws CouldNotSendNotification |
||
392 | * @throws IncorrectPhoneNumberFormatException |
||
393 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
394 | */ |
||
395 | public function send() |
||
402 | } |
||
403 |