| @@ 33-65 (lines=33) @@ | ||
| 30 | * @param null $text |
|
| 31 | * @return bool |
|
| 32 | */ |
|
| 33 | public function send($text = null): bool |
|
| 34 | { |
|
| 35 | if ($text) { |
|
| 36 | $this->setText($text); |
|
| 37 | } |
|
| 38 | ||
| 39 | try { |
|
| 40 | $response = $this->client->send($this->request, [ |
|
| 41 | 'form_params' => [ |
|
| 42 | 'recipients' => implode(',', $this->recipients), |
|
| 43 | 'sender_name' => $this->sender ?? config('laravel-sms.sender'), |
|
| 44 | 'email' => $this->username, |
|
| 45 | 'password' => $this->password, |
|
| 46 | 'message' => $this->text, |
|
| 47 | ], |
|
| 48 | ]); |
|
| 49 | ||
| 50 | $response = json_decode($response->getBody()->getContents(), true); |
|
| 51 | $this->response = $response['msg']; |
|
| 52 | ||
| 53 | return $response['status'] == '1' ? true : false; |
|
| 54 | } catch (ClientException $e) { |
|
| 55 | logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
|
| 56 | $this->httpError = $e; |
|
| 57 | ||
| 58 | return false; |
|
| 59 | } catch (\Exception $e) { |
|
| 60 | logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
|
| 61 | $this->httpError = $e; |
|
| 62 | ||
| 63 | return false; |
|
| 64 | } |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||
| @@ 31-68 (lines=38) @@ | ||
| 28 | * @param null $text |
|
| 29 | * @return bool |
|
| 30 | */ |
|
| 31 | public function send($text = null): bool |
|
| 32 | { |
|
| 33 | if ($text) { |
|
| 34 | $this->setText($text); |
|
| 35 | } |
|
| 36 | try { |
|
| 37 | $request = $this->client->send($this->request, [ |
|
| 38 | 'form_params' => [ |
|
| 39 | 'phone' => implode(',', $this->recipients), |
|
| 40 | 'app_key' => $this->username, |
|
| 41 | 'api_key' => $this->password, |
|
| 42 | 'message' => $this->text, |
|
| 43 | ], |
|
| 44 | ]); |
|
| 45 | ||
| 46 | $response = json_decode($request->getBody()->getContents(), true); |
|
| 47 | ||
| 48 | if ($response['status'] == 'SUCCESS') { |
|
| 49 | $this->response = 'The message was sent successfully'; |
|
| 50 | ||
| 51 | return true; |
|
| 52 | } |
|
| 53 | ||
| 54 | $this->response = $response['message']; |
|
| 55 | ||
| 56 | return false; |
|
| 57 | } catch (ClientException $e) { |
|
| 58 | logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
|
| 59 | $this->httpError = $e; |
|
| 60 | ||
| 61 | return false; |
|
| 62 | } catch (\Exception $e) { |
|
| 63 | logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
|
| 64 | $this->httpError = $e; |
|
| 65 | ||
| 66 | return false; |
|
| 67 | } |
|
| 68 | } |
|
| 69 | } |
|
| 70 | ||