1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Djunehor\Sms\Concrete; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
use GuzzleHttp\Exception\ClientException; |
7
|
|
|
use Illuminate\Support\Facades\Log; |
8
|
|
|
|
9
|
|
|
class InfoBip extends Sms |
10
|
|
|
{ |
11
|
|
|
private $baseUrl; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Constructor. |
15
|
|
|
* @param null $message |
16
|
|
|
*/ |
17
|
|
|
public function __construct($message = null) |
18
|
|
|
{ |
19
|
|
|
$this->username = config('laravel-sms.infobip.username'); |
20
|
|
|
$this->password = config('laravel-sms.infobip.password'); |
21
|
|
|
$this->baseUrl = config('laravel-sms.infobip.base_url'); |
22
|
|
|
if ($message) { |
23
|
|
|
$this->text($message); |
24
|
|
|
} |
25
|
|
|
$this->client = new Client([ |
26
|
|
|
'base_uri' => $this->baseUrl, |
27
|
|
|
'headers' => [ |
28
|
|
|
'Authorization' => 'Basic '.base64_encode("$this->username:$this->password"), |
29
|
|
|
'Content-Type' => 'application/json', |
30
|
|
|
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36 OPR/47.0.2631.39', |
31
|
|
|
], |
32
|
|
|
]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param null $text |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
public function send($text = null): bool |
40
|
|
|
{ |
41
|
|
|
if ($text) { |
42
|
|
|
$this->setText($text); |
43
|
|
|
} |
44
|
|
|
try { |
45
|
|
|
$request = $this->client->post('/sms/2/text/single', [ |
46
|
|
|
'form_params' => [ |
47
|
|
|
'from' => $this->sender ?? config('laravel-sms.sender'), |
48
|
|
|
'to' => implode(',', $this->recipients), |
49
|
|
|
'text' => $this->text, |
50
|
|
|
], |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
$response = json_decode($request->getBody()->getContents(), true); |
54
|
|
|
$this->response = $response; |
55
|
|
|
|
56
|
|
|
return $request->getStatusCode() == 200 ? true : false; |
57
|
|
|
} catch (ClientException $e) { |
58
|
|
|
Log::info('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
59
|
|
|
$this->httpError = $e; |
60
|
|
|
|
61
|
|
|
return false; |
62
|
|
|
} catch (\Exception $e) { |
63
|
|
|
Log::info('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
64
|
|
|
$this->httpError = $e; |
65
|
|
|
|
66
|
|
|
return false; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|