1
|
|
|
<?php |
2
|
|
|
namespace Sender\Traits; |
3
|
|
|
|
4
|
|
|
use Sender\Validation; |
5
|
|
|
use Sender\MobileNumber; |
6
|
|
|
use Sender\Sms\SmsDefineClass; |
7
|
|
|
use Sender\Sms\SmsBuildClass; |
8
|
|
|
use Sender\ExceptionClass\ParameterException; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This trait for SMS OTP FUNCTIONS |
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
|
|
|
trait SmsBuildTrait |
20
|
|
|
{ |
21
|
|
|
protected $inputData; |
22
|
|
|
/** |
23
|
|
|
* This function for Check String Type |
24
|
|
|
* @param int $category |
25
|
|
|
* @param string $key |
26
|
|
|
* @param array $buildSmsData |
27
|
|
|
* |
28
|
66 |
|
*/ |
29
|
|
|
public function buildStringData($category, $key, $value, $buildSmsData, $xmlDoc) |
30
|
66 |
|
{ |
31
|
66 |
|
$buildSmsData = $this->checkAuthCampaignData($category, $key, $value, $buildSmsData, $xmlDoc); |
32
|
66 |
|
$buildSmsData = $this->checkSenderData($category, $key, $value, $buildSmsData, $xmlDoc); |
33
|
62 |
|
$buildSmsData = $this->checkMessageData($category, $key, $value, $buildSmsData, $xmlDoc); |
34
|
62 |
|
$buildSmsData = $this->checkResponseData($category, $key, $value, $buildSmsData); |
35
|
|
|
return $buildSmsData; |
36
|
|
|
} |
37
|
|
|
/** |
38
|
|
|
* This function for Check String Type |
39
|
|
|
* @param int $category |
40
|
|
|
* @param string $key |
41
|
|
|
* @param array $buildSmsData |
42
|
|
|
* |
43
|
66 |
|
*/ |
44
|
|
|
public function checkSenderData($category, $key, $value, $buildSmsData, $xmlDoc) |
45
|
66 |
|
{ |
46
|
52 |
|
if ($key === 'sender') { |
47
|
|
|
$buildSmsData = $this->validLength($key, $value, $buildSmsData, 'sms', $category, $xmlDoc); |
|
|
|
|
48
|
66 |
|
} |
49
|
|
|
return $buildSmsData; |
50
|
|
|
} |
51
|
|
|
/** |
52
|
|
|
* This function for Check String Type |
53
|
|
|
* @param int $category |
54
|
|
|
* @param string $key |
55
|
|
|
* @param array $buildSmsData |
56
|
|
|
* |
57
|
66 |
|
*/ |
58
|
|
|
public function checkAuthCampaignData($category, $key, $value, $buildSmsData, $xmlDoc) |
59
|
66 |
|
{ |
60
|
|
|
if ($key === 'authkey' || $key === 'campaign') { |
61
|
|
|
$buildSmsData = $this->buildData($category, $key, $value, $buildSmsData, $xmlDoc); |
|
|
|
|
62
|
66 |
|
} |
63
|
|
|
return $buildSmsData; |
64
|
|
|
} |
65
|
|
|
/** |
66
|
|
|
* This function for Check String Type |
67
|
|
|
* @param int $category |
68
|
|
|
* @param string $key |
69
|
|
|
* @param array $buildSmsData |
70
|
|
|
* |
71
|
66 |
|
*/ |
72
|
|
|
public function checkMessageData($category, $key, $value, $buildSmsData, $xmlDoc) |
73
|
66 |
|
{ |
74
|
66 |
|
if ($key === 'message') { |
75
|
|
|
$buildSmsData = $this->messageCondition($category, $key, $buildSmsData, $value, $xmlDoc); |
76
|
62 |
|
} |
77
|
|
|
return $buildSmsData; |
78
|
|
|
} |
79
|
|
|
/** |
80
|
|
|
* Message condition Check |
81
|
|
|
* @param int $category |
82
|
|
|
* @param string $key |
83
|
|
|
* @param array $buildSmsData |
84
|
|
|
* @param int $value |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
66 |
|
*/ |
88
|
|
|
public function messageCondition($category, $key, $buildSmsData, $value, $xmlDoc) |
89
|
66 |
|
{ |
90
|
62 |
|
if (!$this->isKeyExists('unicode', $this->inputData)) { |
|
|
|
|
91
|
4 |
|
$buildSmsData = $this->checkMessageLength($key, $buildSmsData, 160, $value, $category, $xmlDoc); |
|
|
|
|
92
|
4 |
|
} elseif ($this->isKeyExists('unicode', $this->inputData)) { |
93
|
|
|
$buildSmsData = $this->checkMessageLength($key, $buildSmsData, 70, $value, $category, $xmlDoc); |
94
|
62 |
|
} |
95
|
|
|
return $buildSmsData; |
96
|
|
|
} |
97
|
|
|
/** |
98
|
|
|
* This function for Check String Type |
99
|
|
|
* @param int $category |
100
|
|
|
* @param string $key |
101
|
|
|
* @param array $buildSmsData |
102
|
|
|
* |
103
|
62 |
|
*/ |
104
|
|
|
public function checkResponseData($category, $key, $value, $buildSmsData) |
105
|
62 |
|
{ |
106
|
|
|
if ($key === 'response') { |
107
|
|
|
$value = $this->checkResponse($value); |
|
|
|
|
108
|
|
|
$buildSmsData = $this->buildData($category, $key, $value, $buildSmsData); |
109
|
62 |
|
} |
110
|
|
|
return $buildSmsData; |
111
|
|
|
} |
112
|
|
|
/** |
113
|
|
|
* This function check the content length |
114
|
|
|
* |
115
|
|
|
* |
116
|
|
|
*/ |
117
|
|
|
public function checkContent($lenOfBulkSms, $bulkSms, $root, $category, $xmlDoc) |
118
|
|
|
{ |
119
|
|
|
for ($j = 0; $j < $lenOfBulkSms; $j++) { |
120
|
|
|
$currentData = $bulkSms[$j]; |
121
|
|
|
if (array_key_exists('message', $currentData) && array_key_exists('mobile', $currentData)) { |
122
|
|
|
$this->inputData['message'] = $currentData['message']; |
123
|
|
|
$this->inputData['mobile'] = $currentData['mobile']; |
124
|
|
|
$smsTag = $this->createElement($xmlDoc, "SMS", $root); |
125
|
|
|
//check message length |
126
|
|
|
$smsTag = $this->buildMessage($category, 'message', $smsTag, $xmlDoc); |
|
|
|
|
127
|
|
|
//check mobile contents |
128
|
|
|
$this->addMobileNumber($xmlDoc, $smsTag); |
|
|
|
|
129
|
|
|
} else { |
130
|
|
|
$message = "parameters authkey or message missing"; |
131
|
|
|
throw ParameterException::missinglogic($message); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
/** |
136
|
|
|
* This function Create Element only |
137
|
|
|
* @param string $element |
138
|
|
|
* @param array $root |
139
|
|
|
* |
140
|
|
|
* @return array |
141
|
|
|
*/ |
142
|
|
|
public function createElement($xmlDoc, $element, $root = null) |
143
|
|
|
{ |
144
|
|
|
if (is_null($root)) { |
145
|
|
|
$root = $xmlDoc->appendChild($xmlDoc->createElement($element)); |
146
|
|
|
} else { |
147
|
|
|
$root = $root->appendChild($xmlDoc->createElement($element)); |
148
|
|
|
} |
149
|
|
|
return $root; |
150
|
|
|
} |
151
|
|
|
/** |
152
|
|
|
* This function for Check String Type |
153
|
|
|
* @param int $category |
154
|
|
|
* @param string $key |
155
|
72 |
|
* @param array $buildSmsData |
156
|
|
|
* |
157
|
72 |
|
*/ |
158
|
66 |
|
public function stringTypeCheckAndBuildData($category, $key, $value, $buildSmsData, $xmlDoc = null) |
159
|
62 |
|
{ |
160
|
|
|
if ($this->isString($value)) { |
|
|
|
|
161
|
22 |
|
$buildSmsData = $this->buildStringData($category, $key, $value, $buildSmsData, $xmlDoc); |
162
|
22 |
|
return $buildSmsData; |
163
|
|
|
} else { |
164
|
|
|
$message = "string values only accept"; |
165
|
|
|
throw ParameterException::invalidInput($key, "string", $value, $message); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
/** |
169
|
|
|
* This function used for Array inside present 0 or 1 |
170
|
|
|
* @param int $category |
171
|
|
|
* @param string $key |
172
|
6 |
|
* @param array $buildSmsData |
173
|
|
|
* |
174
|
6 |
|
*/ |
175
|
6 |
|
public function checkArrayValue($category, $key, $value, $buildSmsData, $xmlDoc) |
176
|
|
|
{ |
177
|
|
|
$value = $this->checkArray($value); |
|
|
|
|
178
|
|
|
if (!is_null($value)) { |
179
|
6 |
|
$buildSmsData = $this->buildData($category, $key, $value, $buildSmsData, $xmlDoc); |
180
|
6 |
|
return $buildSmsData; |
181
|
|
|
} else { |
182
|
|
|
$message = "Allowed only 0 or 1"; |
183
|
|
|
throw ParameterException::invalidInput($key, "int", $value, $message); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* This function for sms array Build with mobilenumbers |
189
|
|
|
* @param string $key |
190
|
|
|
* @param array $buildSmsData |
191
|
|
|
* @param int $category |
192
|
|
|
* |
193
|
80 |
|
* @throws ParameterException missing parameters or return empty |
194
|
|
|
* @return array |
195
|
80 |
|
*/ |
196
|
70 |
|
public function checkIntegerOrString($key, $value, $buildSmsData, $category) |
197
|
10 |
|
{ |
198
|
10 |
|
if ($this->isInterger($value)) { |
|
|
|
|
199
|
|
|
$buildSmsData = $this->buildData($category, $key, $value, $buildSmsData); |
200
|
|
|
} elseif ($this->isString($value)) { |
201
|
|
|
$buildSmsData = $this->buildMobile($key, $value, $buildSmsData, $category); |
202
|
|
|
} else { |
203
|
80 |
|
$message = "interger or string comma seperate values"; |
204
|
|
|
throw ParameterException::invalidInput($key, "string or integer", $value, $message); |
205
|
|
|
} |
206
|
|
|
return $buildSmsData; |
207
|
|
|
} |
208
|
|
|
/** |
209
|
|
|
* This function for sms array Build with mobilenumbers |
210
|
|
|
* @param array $buildSmsData |
211
|
|
|
* |
212
|
|
|
* |
213
|
|
|
* @return array |
214
|
|
|
*/ |
215
|
|
|
public function buildMobile($key, $value, $buildSmsData, $category) |
216
|
|
|
{ |
217
|
|
|
$result = $this->isValidNumber($value); |
|
|
|
|
218
|
|
|
if (!empty($result) && $result['value'] == true) { |
219
|
|
|
$buildSmsData = $this->buildData($category, $key, $value, $buildSmsData); |
220
|
|
|
return $buildSmsData; |
221
|
|
|
} else { |
222
|
|
|
$message = "this number not the correct:_".$result['mobile']; |
223
|
|
|
throw ParameterException::invalidInput("mobiles", "string", $value, $message); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|