|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Djunehor |
|
5
|
|
|
* Date: 1/22/2019 |
|
6
|
|
|
* Time: 9:36 AM. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Djunehor\Sms\Concrete; |
|
10
|
|
|
|
|
11
|
|
|
use GuzzleHttp\Exception\ClientException; |
|
12
|
|
|
use GuzzleHttp\Psr7\Request; |
|
13
|
|
|
|
|
14
|
|
|
class BulkSmsNigeria extends Sms |
|
15
|
|
|
{ |
|
16
|
|
|
private $baseUrl = 'https://www.bulksmsnigeria.com/api/v1/sms/'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class Constructor. |
|
20
|
|
|
* @param null $message |
|
21
|
|
|
*/ |
|
22
|
1 |
|
public function __construct($message = null) |
|
23
|
|
|
{ |
|
24
|
1 |
|
$this->username = config('laravel-sms.bulk_sms_nigeria.token'); |
|
25
|
|
|
|
|
26
|
1 |
|
if ($message) { |
|
27
|
|
|
$this->text($message); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
$this->client = self::getInstance(); |
|
31
|
1 |
|
$this->request = new Request('POST', $this->baseUrl.'create'); |
|
32
|
1 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param null $text |
|
36
|
|
|
* @return bool |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function send($text = null): bool |
|
39
|
|
|
{ |
|
40
|
1 |
|
if ($text) { |
|
41
|
|
|
$this->setText($text); |
|
42
|
|
|
} |
|
43
|
|
|
try { |
|
44
|
1 |
|
$response = $this->client->send($this->request, [ |
|
45
|
|
|
'form_params' => [ |
|
46
|
1 |
|
'api_token' => config('laravel-sms.bulk_sms_nigeria.token'), |
|
47
|
1 |
|
'to' => implode(',', $this->recipients), |
|
48
|
1 |
|
'from' => $this->sender ?? config('laravel-sms.sender'), |
|
49
|
1 |
|
'body' => $this->text, |
|
50
|
1 |
|
'dnd' => config('laravel-sms.bulk_sms_nigeria.dnd'), |
|
51
|
|
|
], |
|
52
|
|
|
]); |
|
53
|
|
|
|
|
54
|
1 |
|
$response = json_decode($response->getBody()->getContents(), true) ?? []; |
|
55
|
1 |
|
$this->response = array_key_exists('error', $response) ? $response['error']['message'] : $response['data']['message']; |
|
56
|
|
|
|
|
57
|
|
|
return $response['data']['status'] == 'success' ? true : false; |
|
58
|
1 |
|
} catch (ClientException $e) { |
|
59
|
|
|
logger()->error('HTTP Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
|
60
|
|
|
$this->httpError = $e; |
|
61
|
|
|
|
|
62
|
|
|
return false; |
|
63
|
1 |
|
} catch (\Exception $e) { |
|
64
|
1 |
|
logger()->error('SMS Exception in '.__CLASS__.': '.__METHOD__.'=>'.$e->getMessage()); |
|
65
|
1 |
|
$this->httpError = $e; |
|
66
|
|
|
|
|
67
|
1 |
|
return false; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|