1 | <?php |
||
21 | 1 | class Sender extends BaseSender implements ISender |
|
22 | { |
||
23 | CONST URL = 'https://as.eurosms.com/sms/Sender'; |
||
24 | |||
25 | /** @var string */ |
||
26 | private $id; |
||
27 | |||
28 | /** @var string */ |
||
29 | private $key; |
||
30 | |||
31 | |||
32 | public function __construct(array $config = NULL) |
||
33 | { |
||
34 | 1 | if (is_array($config) && !empty($config)) |
|
35 | 1 | $this->config($config); |
|
36 | 1 | } |
|
37 | |||
38 | /** |
||
39 | * @param array $config |
||
40 | * @return self |
||
41 | */ |
||
42 | public function config($config) |
||
50 | |||
51 | /** |
||
52 | * @throws RM\SMSender\Exception |
||
53 | * @return bool|string ID of Message |
||
54 | */ |
||
55 | public function send(IMessage $message) |
||
56 | { |
||
57 | 1 | $this->check($message); |
|
58 | 1 | $this->onBeforeSend($message); |
|
59 | 1 | $res = $this->getHttpClient()->request('GET', self::URL . '?' . str_replace(urlencode($message->getTo()), $message->getTo(), http_build_query([ |
|
60 | 1 | 'action' => ($this->debug ? 'validate' : 'send') . '1SMSHTTP', |
|
61 | 1 | 'i' => $this->id, |
|
62 | 1 | 's' => $this->getSignature($message), |
|
63 | 1 | 'd' => 1, |
|
64 | 1 | 'sender' => $message->getFrom(), |
|
65 | 1 | 'number' => $message->getTo(), |
|
66 | 1 | 'msg' => $message->getText(), |
|
67 | ]))); |
||
68 | 1 | $response = $res->getBody(); |
|
69 | 1 | if ($this->isSuccess($response)) { |
|
70 | $this->onSuccess($message, $response); |
||
71 | } else { |
||
72 | 1 | $e = new GatewayException($response); |
|
73 | 1 | $this->onError($message, $response, $e); |
|
74 | 1 | throw $e; |
|
75 | } |
||
76 | return ($this->debug) |
||
77 | ? TRUE |
||
78 | : substr(Strings::trim((string)$response), 3); |
||
79 | } |
||
80 | |||
81 | public function getSignature(IMessage $message) : string |
||
85 | |||
86 | public function isSuccess(string $response) |
||
91 | |||
92 | /** |
||
93 | * @param string $id |
||
94 | * @param string $key |
||
95 | * @throws ConfigurationException |
||
96 | * @return bool |
||
97 | */ |
||
98 | private function checkConfig($id, $key) |
||
106 | |||
107 | /** |
||
108 | * @throws MissingParameterException |
||
109 | */ |
||
110 | private function check(IMessage $message) : bool |
||
120 | } |
||
121 |