|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Clickatell; |
|
4
|
|
|
|
|
5
|
|
|
use stdClass; |
|
6
|
|
|
use Clickatell\ClickatellException; |
|
7
|
|
|
use Clickatell\Rest; |
|
8
|
|
|
use NotificationChannels\Clickatell\Exceptions\CouldNotSendNotification; |
|
9
|
|
|
|
|
10
|
|
|
class ClickatellClient |
|
11
|
|
|
{ |
|
12
|
|
|
const SUCCESSFUL_SEND = 0; |
|
13
|
|
|
const AUTH_FAILED = 1; |
|
14
|
|
|
const INVALID_DEST_ADDRESS = 105; |
|
15
|
|
|
const INVALID_API_ID = 108; |
|
16
|
|
|
const CANNOT_ROUTE_MESSAGE = 114; |
|
17
|
|
|
const DEST_MOBILE_BLOCKED = 121; |
|
18
|
|
|
const DEST_MOBILE_OPTED_OUT = 122; |
|
19
|
|
|
const MAX_MT_EXCEEDED = 130; |
|
20
|
|
|
const NO_CREDIT_LEFT = 301; |
|
21
|
|
|
const INTERNAL_ERROR = 901; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var Rest |
|
25
|
|
|
*/ |
|
26
|
|
|
private $clickatell; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param Rest $clickatellRest |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(Rest $clickatellRest) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->clickatell = $clickatellRest; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param array $to String or Array of numbers |
|
38
|
|
|
* @param string $message |
|
39
|
|
|
*/ |
|
40
|
|
|
public function send(array $to, $message) |
|
41
|
|
|
{ |
|
42
|
|
|
$to = collect($to)->toArray(); |
|
43
|
|
|
|
|
44
|
|
|
$client = new \GuzzleHttp\Client(['base_uri' => 'https://platform.clickatell.com/messages/http/']); |
|
45
|
|
|
$query = sprintf( |
|
46
|
|
|
'send?apiKey=%s&to=%s&content=%s', |
|
47
|
|
|
config('services.clickatell.api_key'), |
|
48
|
|
|
reset($to), |
|
49
|
|
|
$message |
|
50
|
|
|
); |
|
51
|
|
|
$response = $client->request('GET', $query); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getFailedQueueCodes() |
|
58
|
|
|
{ |
|
59
|
|
|
return [ |
|
60
|
|
|
self::AUTH_FAILED, |
|
61
|
|
|
self::INVALID_DEST_ADDRESS, |
|
62
|
|
|
self::INVALID_API_ID, |
|
63
|
|
|
self::CANNOT_ROUTE_MESSAGE, |
|
64
|
|
|
self::DEST_MOBILE_BLOCKED, |
|
65
|
|
|
self::DEST_MOBILE_OPTED_OUT, |
|
66
|
|
|
self::MAX_MT_EXCEEDED, |
|
67
|
|
|
]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return array |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getRetryQueueCodes() |
|
74
|
|
|
{ |
|
75
|
|
|
return [ |
|
76
|
|
|
self::NO_CREDIT_LEFT, |
|
77
|
|
|
self::INTERNAL_ERROR, |
|
78
|
|
|
]; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.