1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TarfinLabs\Netgsm\Sms; |
4
|
|
|
|
5
|
|
|
use TarfinLabs\Netgsm\NetgsmErrors; |
6
|
|
|
|
7
|
|
|
class NetgsmSmsMessage extends AbstractNetgsmMessage |
8
|
|
|
{ |
9
|
|
|
protected $url = 'sms/send'; |
10
|
|
|
|
11
|
|
|
protected $errorCodes = [ |
12
|
|
|
'20' => NetgsmErrors::MESSAGE_TOO_LONG, |
13
|
|
|
'30' => NetgsmErrors::CREDENTIALS_INCORRECT, |
14
|
|
|
'40' => NetgsmErrors::SENDER_INCORRECT, |
15
|
|
|
'70' => NetgsmErrors::PARAMETERS_INCORRECT, |
16
|
|
|
]; |
17
|
|
|
|
18
|
|
|
protected $fields = [ |
19
|
|
|
'gsmno', |
20
|
|
|
'message', |
21
|
|
|
'msgheader', |
22
|
|
|
'startdate', |
23
|
|
|
'stopdate', |
24
|
|
|
'dil', |
25
|
|
|
'izin', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* creates the xml request body for sms sending via xml post method. |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
protected function createXmlPost(): string |
33
|
|
|
{ |
34
|
|
|
$xml = '<?xml version="1.0" encoding="UTF-8"?>'; |
35
|
|
|
$xml .= '<mainbody>'; |
36
|
|
|
$xml .= '<header>'; |
37
|
|
|
$xml .= '<company dil="'.$this->defaults['language'].'">Netgsm</company>'; |
38
|
|
|
$xml .= '<usercode>'.$this->credentials['user_code'].'</usercode>'; |
39
|
|
|
$xml .= '<password>'.$this->credentials['secret'].'</password>'; |
40
|
|
|
$xml .= '<type>1:n</type>'; |
41
|
|
|
$xml .= '<filtre>'.(int) $this->isAuthorizedData().'</filtre>'; |
42
|
|
|
$xml .= '<msgheader>'.$this->getHeader().'</msgheader>'; |
43
|
|
|
$xml .= '</header>'; |
44
|
|
|
$xml .= '<body>'; |
45
|
|
|
$xml .= '<msg>'; |
46
|
|
|
$xml .= '<![CDATA['.$this->message.']]>'; |
47
|
|
|
$xml .= '</msg>'; |
48
|
|
|
foreach ($this->recipients as $recipient) { |
49
|
|
|
$xml .= '<no>'.$recipient.'</no>'; |
50
|
|
|
} |
51
|
|
|
$xml .= '</body>'; |
52
|
|
|
$xml .= '</mainbody>'; |
53
|
|
|
|
54
|
|
|
return $xml; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* maps the given parameters according to the required parameters of the sms message endpoint. |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
protected function mappers(): array |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
'gsmno' => implode(',', $this->recipients), |
66
|
|
|
'msgheader' => $this->header ?? $this->defaults['header'], |
67
|
|
|
'message' => $this->message, |
68
|
|
|
'startdate' => ! empty($this->startDate) ? $this->startDate->format('dmYHi') : null, |
69
|
|
|
'stopdate' => ! empty($this->endDate) ? $this->endDate->format('dmYHi') : null, |
70
|
|
|
'izin' => (int) $this->isAuthorizedData(), |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|