Conditions | 6 |
Paths | 20 |
Total Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
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 | 'query' => [ |
||
39 | 'apikey' => $this->username, |
||
40 | 'sender' => $this->sender ?? config('laravel-sms.sender'), |
||
41 | 'destination' => implode(',', $this->recipients), |
||
42 | 'mssg' => $this->text, |
||
43 | 'dnd' => config('laravel-sms.mebo_sms.dnd'), |
||
44 | ], |
||
45 | ]); |
||
46 | |||
47 | $response = json_decode($request->getBody()->getContents(), true); |
||
48 | |||
49 | if (isset($response['status']) && $response['status'] == 'OK') { |
||
50 | return true; |
||
51 | } |
||
52 | |||
53 | $this->response = $response['error']; |
||
54 | |||
55 | return false; |
||
56 | } catch (ClientException $e) { |
||
57 | logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
||
58 | $this->httpError = $e; |
||
59 | |||
60 | return false; |
||
61 | } catch (\Exception $e) { |
||
62 | logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
||
63 | $this->httpError = $e; |
||
64 | |||
65 | return false; |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 |