| @@ 7-78 (lines=72) @@ | ||
| 4 | use GuzzleHttp\Client; |
|
| 5 | use Tzsk\Sms\Contract\MasterDriver; |
|
| 6 | ||
| 7 | class Linkmobility extends MasterDriver |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * Linkmobility Settings. |
|
| 11 | * |
|
| 12 | * @var object|null |
|
| 13 | */ |
|
| 14 | protected $settings = null; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * Http Client. |
|
| 18 | * |
|
| 19 | * @var Client|null |
|
| 20 | */ |
|
| 21 | protected $client = null; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * Construct the class with the relevant settings. |
|
| 25 | * |
|
| 26 | * SendSmsInterface constructor. |
|
| 27 | * @param array $settings |
|
| 28 | */ |
|
| 29 | public function __construct($settings) |
|
| 30 | { |
|
| 31 | $this->settings = (object) $settings; |
|
| 32 | $this->client = new Client(); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * Send text message and return response. |
|
| 37 | * |
|
| 38 | * @return mixed |
|
| 39 | */ |
|
| 40 | public function send() |
|
| 41 | { |
|
| 42 | $numbers = implode(",", $this->recipients); |
|
| 43 | ||
| 44 | $response = $this->client->request("POST", $this->settings->url, [ |
|
| 45 | "form_params" => [ |
|
| 46 | "USER" => $this->settings->username, |
|
| 47 | "PW" => $this->settings->password, |
|
| 48 | "RCV" => $numbers, |
|
| 49 | "SND" => urlencode($this->settings->sender), |
|
| 50 | "TXT" => $this->body, |
|
| 51 | ], |
|
| 52 | ]); |
|
| 53 | ||
| 54 | $data = $this->getResponseData($response); |
|
| 55 | ||
| 56 | return (object) array_merge($data, ["status" => true]); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * @param mixed $response |
|
| 61 | * |
|
| 62 | * @return mixed|object |
|
| 63 | */ |
|
| 64 | protected function getResponseData($response) |
|
| 65 | { |
|
| 66 | if ($response->getStatusCode() != 200) { |
|
| 67 | return (object) ["status" => false, "message" => "Request Error. " . $response->getReasonPhrase()]; |
|
| 68 | } |
|
| 69 | ||
| 70 | $data = json_decode((string) $response->getBody(), true); |
|
| 71 | ||
| 72 | if ($data["status"] != "success") { |
|
| 73 | return (object) ["status" => false, "message" => "Something went wrong.", "data" => $data]; |
|
| 74 | } |
|
| 75 | ||
| 76 | return $data; |
|
| 77 | } |
|
| 78 | } |
|
| 79 | ||
| @@ 7-79 (lines=73) @@ | ||
| 4 | use GuzzleHttp\Client; |
|
| 5 | use Tzsk\Sms\Contract\MasterDriver; |
|
| 6 | ||
| 7 | class Textlocal extends MasterDriver |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * Textlocal Settings. |
|
| 11 | * |
|
| 12 | * @var object|null |
|
| 13 | */ |
|
| 14 | protected $settings = null; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * Http Client. |
|
| 18 | * |
|
| 19 | * @var Client|null |
|
| 20 | */ |
|
| 21 | protected $client = null; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * Construct the class with the relevant settings. |
|
| 25 | * |
|
| 26 | * SendSmsInterface constructor. |
|
| 27 | * @param array $settings |
|
| 28 | */ |
|
| 29 | public function __construct($settings) |
|
| 30 | { |
|
| 31 | $this->settings = (object) $settings; |
|
| 32 | $this->client = new Client(); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * Send text message and return response. |
|
| 37 | * |
|
| 38 | * @return mixed |
|
| 39 | */ |
|
| 40 | public function send() |
|
| 41 | { |
|
| 42 | $numbers = implode(",", $this->recipients); |
|
| 43 | ||
| 44 | $response = $this->client->request("POST", $this->settings->url, [ |
|
| 45 | "form_params" => [ |
|
| 46 | "username" => $this->settings->username, |
|
| 47 | "hash" => $this->settings->hash, |
|
| 48 | "numbers" => $numbers, |
|
| 49 | "sender" => urlencode($this->settings->sender), |
|
| 50 | "message" => $this->body, |
|
| 51 | ], |
|
| 52 | ]); |
|
| 53 | ||
| 54 | $data = $this->getResponseData($response); |
|
| 55 | ||
| 56 | return (object) array_merge($data, ["status" => true]); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * Get the response data. |
|
| 61 | * |
|
| 62 | * @param object $response |
|
| 63 | * @return array|object |
|
| 64 | */ |
|
| 65 | protected function getResponseData($response) |
|
| 66 | { |
|
| 67 | if ($response->getStatusCode() != 200) { |
|
| 68 | return (object) ["status" => false, "message" => "Request Error. " . $response->getReasonPhrase()]; |
|
| 69 | } |
|
| 70 | ||
| 71 | $data = json_decode((string) $response->getBody(), true); |
|
| 72 | ||
| 73 | if ($data["status"] != "success") { |
|
| 74 | return (object) ["status" => false, "message" => "Something went wrong.", "data" => $data]; |
|
| 75 | } |
|
| 76 | ||
| 77 | return $data; |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||