@@ -100,15 +100,14 @@ protected function doSend(MessageInterface $message): SentMessage
100
100
throw new UnsupportedMessageTypeException (__CLASS__ , SmsMessage::class, $ message );
101
101
}
102
102
103
- $ timestamp = time ();
104
103
$ data = [
105
104
'login ' => $ this ->login ,
106
- 'phone ' => $ this ->escapePhoneNumber ($ message ->getPhone ()),
107
- 'text ' => $ message ->getSubject (),
105
+ 'phone ' => $ phone = $ this ->escapePhoneNumber ($ message ->getPhone ()),
108
106
'sender ' => $ this ->from ,
109
- 'timestamp ' => $ timestamp ,
107
+ 'text ' => $ message ->getSubject (),
108
+ 'timestamp ' => time (),
110
109
];
111
- $ data ['signature ' ] = $ this ->generateSignature ($ data, $ timestamp );
110
+ $ data ['signature ' ] = $ this ->generateSignature ($ data );
112
111
113
112
$ endpoint = sprintf ('https://%s/external/get/send.php ' , $ this ->getEndpoint ());
114
113
$ response = $ this ->client ->request (
@@ -125,55 +124,33 @@ protected function doSend(MessageInterface $message): SentMessage
125
124
126
125
$ content = $ response ->toArray (false );
127
126
128
- // it happens if the host without www
129
- if (isset ($ content ['' ]['error ' ])) {
130
- throw new TransportException ('Unable to send the SMS: ' .$ this ->getErrorMsg ((int ) $ content ['' ]['error ' ]), $ response );
131
- }
132
-
133
- if (isset ($ content ['error ' ])) {
134
- throw new TransportException ('Unable to send the SMS: ' .$ this ->getErrorMsg ((int ) $ content ['error ' ]), $ response );
135
- }
127
+ if (0 !== (int ) $ content [$ phone ]['error ' ] ?? -1 ) {
128
+ $ errorCode = (int ) $ content ['error ' ] ?? $ content ['' ]['error ' ] ?? $ content [$ phone ]['error ' ] ?? -1 ;
129
+ if (-1 === $ errorCode ) {
130
+ throw new TransportException ('Unable to send the SMS. ' , $ response );
131
+ }
136
132
137
- $ phone = $ this ->escapePhoneNumber ($ message ->getPhone ());
138
- if (32 === (int ) $ content [$ phone ]['error ' ]) {
139
- throw new TransportException ('Unable to send the SMS: ' .$ this ->getErrorMsg ((int ) $ content [$ phone ]['error ' ]), $ response );
133
+ $ error = self ::ERROR_CODES [$ errorCode ] ?? self ::ERROR_CODES [999 ];
134
+ throw new TransportException ('Unable to send the SMS: ' .$ error , $ response );
140
135
}
141
136
142
- if (0 === (int ) $ content [$ phone ]['error ' ]) {
143
- $ sentMessage = new SentMessage ($ message , (string ) $ this );
144
- if (isset ($ content [$ phone ]['id_sms ' ])) {
145
- $ sentMessage ->setMessageId ($ content [$ phone ]['id_sms ' ]);
146
- }
147
-
148
- return $ sentMessage ;
137
+ $ sentMessage = new SentMessage ($ message , (string ) $ this );
138
+ if (isset ($ content [$ phone ]['id_sms ' ])) {
139
+ $ sentMessage ->setMessageId ($ content [$ phone ]['id_sms ' ]);
149
140
}
150
141
151
- throw new TransportException ( ' Unable to send the SMS. ' , $ response ) ;
142
+ return $ sentMessage ;
152
143
}
153
144
154
- private function generateSignature (array $ data, int $ timestamp ): string
145
+ private function generateSignature (array $ data ): string
155
146
{
156
- $ params = [
157
- 'timestamp ' => $ timestamp ,
158
- 'login ' => $ this ->login ,
159
- 'phone ' => $ data ['phone ' ],
160
- 'sender ' => $ this ->from ,
161
- 'text ' => $ data ['text ' ],
162
- ];
163
-
164
- ksort ($ params );
165
- reset ($ params );
147
+ ksort ($ data );
166
148
167
- return md5 (implode ('' , $ params ).$ this ->password );
149
+ return md5 (implode ('' , array_values ( $ data ) ).$ this ->password );
168
150
}
169
151
170
152
private function escapePhoneNumber (string $ phoneNumber ): string
171
153
{
172
154
return str_replace ('+ ' , '00 ' , $ phoneNumber );
173
155
}
174
-
175
- private function getErrorMsg (int $ errorCode ): string
176
- {
177
- return self ::ERROR_CODES [$ errorCode ] ?? self ::ERROR_CODES [999 ];
178
- }
179
156
}
0 commit comments