1
|
|
|
<?php |
2
|
|
|
namespace Sender\Sms; |
3
|
|
|
|
4
|
|
|
use Sender\Deliver; |
5
|
|
|
use Sender\Validation; |
6
|
|
|
use Sender\MobileNumber; |
7
|
|
|
use Sender\Config\Config as ConfigClass; |
8
|
|
|
use Sender\ExceptionClass\ParameterException; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This Class for Send Normal SMS |
12
|
|
|
* |
13
|
|
|
* @package Msg91 SMS&OTP package |
14
|
|
|
* @author VenkatS <[email protected]> |
15
|
|
|
* @link https://github.com/tesark/msg91-php |
16
|
|
|
* @license MIT |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
class SmsNormal extends SmsBuildClass |
20
|
|
|
{ |
21
|
|
|
protected $inputData; |
22
|
|
|
protected $sendSmsData; |
23
|
|
|
/** |
24
|
|
|
* This function Category to send SMS |
25
|
|
|
* @param int|string $mobileNumber |
26
|
|
|
* @param array $data |
27
|
|
|
* @param int $category |
28
|
|
|
* @param string $authKey |
29
|
|
|
* |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
80 |
|
public function smsCategory($data, $category, $authKey) |
33
|
|
|
{ |
34
|
80 |
|
$transAuthKey = null; |
35
|
80 |
|
$promoAuthKey = null; |
36
|
80 |
|
$checkAuth = Validation::isAuthKey($authKey); |
37
|
80 |
|
if (!$checkAuth) { |
38
|
|
|
// Get Envirionment variable and config file values |
39
|
|
|
$config = new ConfigClass(); |
40
|
|
|
$container = $config->getDefaults(); |
41
|
|
|
$commonValue = $container['common']; |
42
|
|
|
$transAuthKey = $commonValue['transAuthKey']; |
43
|
|
|
$promoAuthKey = $commonValue['promoAuthKey']; |
44
|
|
|
} |
45
|
80 |
|
if ($category === 1) { |
46
|
|
|
//transactional SMS content Route 4 |
47
|
|
|
$sendData = array( |
48
|
40 |
|
'authkey' => $checkAuth ? $authKey : $transAuthKey, |
49
|
40 |
|
'route' => 4, |
50
|
|
|
); |
51
|
|
|
} else { |
52
|
|
|
//Promotional SMS content Route 1 |
53
|
40 |
|
$sendData = array( |
54
|
40 |
|
'authkey' => $checkAuth ? $authKey : $promoAuthKey, |
55
|
|
|
'route' => 4, |
56
|
|
|
); |
57
|
80 |
|
} |
58
|
|
|
$output = $this->sendSms($data, $sendData); |
59
|
|
|
return $output; |
60
|
|
|
} |
61
|
|
|
/** |
62
|
|
|
* This function for call All possible parameter added to send array |
63
|
|
|
* @param string|int $mobileNumber |
64
|
|
|
* @param array $data |
65
|
|
|
* @param array $sendData |
66
|
|
|
* |
67
|
|
|
* @throws ParameterException missing parameters or type error |
68
|
|
|
* @return string |
69
|
80 |
|
*/ |
70
|
|
|
public function sendSms($data, $sendData) |
71
|
80 |
|
{ |
72
|
80 |
|
$this->inputData = $data; |
73
|
|
|
$this->sendSmsData = $sendData; |
74
|
80 |
|
//this condition are check and parameters are added to buildSmsData array |
75
|
80 |
|
if ($this->hasMobileNumber() && $this->hasData() && $this->hasSendData()) { |
76
|
80 |
|
$buildSmsData = $sendData; |
77
|
|
|
$buildSmsData = $this->addAllParameters($buildSmsData); |
78
|
|
|
$response = $this->send($data, $buildSmsData); |
79
|
|
|
return $response; |
80
|
|
|
} else { |
81
|
|
|
$message = "parameters Missing"; |
82
|
|
|
throw ParameterException::missinglogic($message); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
/** |
86
|
|
|
* This function Used for Added available Parameter on Array |
87
|
|
|
* @param array $buildSmsData |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
80 |
|
*/ |
91
|
|
|
public function addAllParameters($buildSmsData) |
92
|
80 |
|
{ |
93
|
80 |
|
$buildSmsData = $this->addMobile($buildSmsData, 1); |
94
|
62 |
|
$buildSmsData = $this->addMessage($buildSmsData, 1); // no 1 for using GET method |
95
|
48 |
|
$buildSmsData = $this->addSender($buildSmsData, 1); |
96
|
44 |
|
$buildSmsData = $this->addCountry($buildSmsData, 1); |
97
|
40 |
|
$buildSmsData = $this->addFlash($buildSmsData, 1); |
98
|
38 |
|
$buildSmsData = $this->addUnicode($buildSmsData, 1); |
99
|
18 |
|
$buildSmsData = $this->addSchtime($buildSmsData, 1); |
100
|
10 |
|
$buildSmsData = $this->addAfterMinutes($buildSmsData, 1); |
101
|
4 |
|
$buildSmsData = $this->addResponse($buildSmsData, 1); |
102
|
|
|
$buildSmsData = $this->addCampaign($buildSmsData, 1); |
103
|
|
|
return $buildSmsData; |
104
|
|
|
} |
105
|
|
|
/** |
106
|
|
|
* This function use SMS data to Deliver Class |
107
|
|
|
* @param array $data |
108
|
|
|
* @param array $buildSmsData |
109
|
|
|
* |
110
|
|
|
* @throws ParameterException missing parameters or type error |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function send($data, $buildSmsData) |
114
|
|
|
{ |
115
|
|
|
$inputDataLen = Validation::getSize($data); |
116
|
|
|
$buildDataLen = Validation::getSize($buildSmsData); |
117
|
|
|
if ($inputDataLen+2 == $buildDataLen) { |
118
|
|
|
$uri = "sendhttp.php"; |
119
|
|
|
$delivery = new Deliver(); |
120
|
|
|
$response = $delivery->sendOtpGet($uri, $buildSmsData); |
121
|
|
|
return $response; |
122
|
|
|
} else { |
123
|
|
|
throw ParameterException::missinglogic("Check Input parameters, something wrong"); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|