|
1
|
|
|
<?php |
|
2
|
|
|
namespace ridvanbaluyos\sms\providers; |
|
3
|
|
|
|
|
4
|
|
|
use ridvanbaluyos\sms\SmsProviderServicesInterface as SmsProviderServicesInterface; |
|
5
|
|
|
use ridvanbaluyos\sms\Sms as Sms; |
|
6
|
|
|
use Noodlehaus\Config as Config; |
|
7
|
|
|
use Exception as Exception; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class PromoTexter |
|
11
|
|
|
* @package ridvanbaluyos\sms\providers |
|
12
|
|
|
*/ |
|
13
|
|
|
class PromoTexter extends Sms implements SmsProviderServicesInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $className; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* PromoTexter constructor. |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->className = substr(get_called_class(), strrpos(get_called_class(), '\\') + 1); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* This function sends the SMS. |
|
30
|
|
|
* |
|
31
|
|
|
* @param $phoneNumber |
|
32
|
|
|
* @param $message |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
|
|
public function send($phoneNumber, $message) |
|
36
|
|
|
{ |
|
37
|
|
|
try { |
|
38
|
|
|
$conf = Config::load(__DIR__ . '/../config/providers.json')[$this->className]; |
|
39
|
|
|
$query = [ |
|
40
|
|
|
'senderid' => $conf['senderid'], |
|
41
|
|
|
'clientid' => $conf['clientid'], |
|
42
|
|
|
'passkey' => $conf['passkey'] , |
|
43
|
|
|
'msisdn' => $phoneNumber, |
|
44
|
|
|
'message' => base64_encode($message), |
|
45
|
|
|
'dlr-call' => $conf['dlr-call'], |
|
46
|
|
|
'dlr-callback' => '', |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
$url = $conf['url'] . '?' . http_build_query($query); |
|
50
|
|
|
|
|
51
|
|
|
$ch = curl_init(); |
|
52
|
|
|
curl_setopt($ch,CURLOPT_URL,$url); |
|
53
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
54
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 240); |
|
55
|
|
|
$result = curl_exec($ch); |
|
56
|
|
|
curl_close($ch); |
|
57
|
|
|
$code = (intval($result) > 0) ? 202 : 403; |
|
58
|
|
|
|
|
59
|
|
|
return $this->response($code, $result, null, $this->className); |
|
60
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* This function checks the account balance. |
|
67
|
|
|
* |
|
68
|
|
|
*/ |
|
69
|
|
|
public function balance() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->response(404, [], $this->className . ' currently does not support this feature.', $this->className); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|