1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace TarfinLabs\Netgsm; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use TarfinLabs\Netgsm\Exceptions\CouldNotSendNotification; |
8
|
|
|
|
9
|
|
|
class NetgsmOtpMessage extends AbstractNetgsmMessage |
10
|
|
|
{ |
11
|
|
|
protected $url = 'https://api.netgsm.com.tr/sms/send/otp'; |
12
|
|
|
|
13
|
|
|
protected $errorCodes = [ |
14
|
|
|
'20' => CouldNotSendNotification::MESSAGE_TOO_LONG, |
15
|
|
|
'30' => CouldNotSendNotification::CREDENTIALS_INCORRECT, |
16
|
|
|
'40' => CouldNotSendNotification::SENDER_INCORRECT, |
17
|
|
|
'50' => CouldNotSendNotification::RECEIVER_INCORRECT, |
18
|
|
|
'60' => CouldNotSendNotification::OTP_ACCOUNT_NOT_DEFINED, |
19
|
|
|
'70' => CouldNotSendNotification::PARAMETERS_INCORRECT, |
20
|
|
|
'80' => CouldNotSendNotification::QUERY_LIMIT_EXCEED, |
21
|
|
|
'100' => CouldNotSendNotification::SYSTEM_ERROR, |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
protected $fields = [ |
25
|
|
|
'usercode', |
26
|
|
|
'password', |
27
|
|
|
'msgheader', |
28
|
|
|
'msg', |
29
|
|
|
'no' |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
protected function createXmlPost(): string |
36
|
|
|
{ |
37
|
|
|
$xml = '<?xml version="1.0" encoding="UTF-8"?>'; |
38
|
|
|
$xml .= '<mainbody>'; |
39
|
|
|
$xml .= '<header>'; |
40
|
|
|
$xml .= '<usercode>'.$this->credentials['user_code'].'</usercode>'; |
41
|
|
|
$xml .= '<password>'.$this->credentials['secret'].'</password>'; |
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
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getUrl(): string |
61
|
|
|
{ |
62
|
|
|
return $this->url; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
protected function mappers(): array |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
'usercode' => $this->credentials['user_code'], |
72
|
|
|
'password' => $this->credentials['secret'], |
73
|
|
|
'msgheader' => $this->header ?? $this->defaults['header'], |
74
|
|
|
'msg' => $this->message, |
75
|
|
|
'no' => is_array($this->recipients) ? $this->recipients[0] : $this->recipients, |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|