1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tzsk\Sms\Drivers; |
4
|
|
|
|
5
|
|
|
use Tzsk\Sms\Abstracts\Driver; |
6
|
|
|
use SMSGatewayMe\Client\ApiClient; |
7
|
|
|
use SMSGatewayMe\Client\Configuration; |
8
|
|
|
use SMSGatewayMe\Client\Api\MessageApi; |
9
|
|
|
use SMSGatewayMe\Client\Model\SendMessageRequest; |
10
|
|
|
|
11
|
|
|
class SmsGatewayMe extends Driver |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* SMSGatewayMe Settings. |
15
|
|
|
* |
16
|
|
|
* @var object |
17
|
|
|
*/ |
18
|
|
|
protected $settings; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* SMSGatewayMe Client. |
22
|
|
|
* |
23
|
|
|
* @var SMSGatewayMe\Client\Api\MessageApi |
24
|
|
|
*/ |
25
|
|
|
protected $client; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Construct the class with the relevant settings. |
29
|
|
|
* |
30
|
|
|
* SendSmsInterface constructor. |
31
|
|
|
* @param $settings object |
32
|
|
|
*/ |
33
|
|
|
public function __construct($settings) |
34
|
|
|
{ |
35
|
|
|
$this->settings = (object) $settings; |
36
|
|
|
|
37
|
|
|
$config = Configuration::getDefaultConfiguration(); |
38
|
|
|
$config->setApiKey('Authorization', $this->settings->apiToken); |
39
|
|
|
$apiClient = new ApiClient($config); |
40
|
|
|
$this->client = new MessageApi($apiClient); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Send text message and return response. |
45
|
|
|
* |
46
|
|
|
* @return object |
47
|
|
|
*/ |
48
|
|
|
public function send() |
49
|
|
|
{ |
50
|
|
|
$response = collect(); |
51
|
|
|
foreach ($this->recipients as $recipient) { |
52
|
|
|
$response->put( |
53
|
|
|
$recipient, |
54
|
|
|
$this->client->sendMessages($this->payload($recipient)) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return (count($this->recipients) == 1) ? $response->first() : $response; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $recipient |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
protected function payload($recipient) |
66
|
|
|
{ |
67
|
|
|
return new SendMessageRequest([ |
68
|
|
|
'phoneNumber' => $recipient, |
69
|
|
|
'message' => $this->body, |
70
|
|
|
'deviceId' => $this->settings->from |
71
|
|
|
]); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..