@@ -213,21 +213,21 @@ discard block |
||
213 | 213 | $path = 'sms/' . $path; |
214 | 214 | |
215 | 215 | // default params |
216 | - if (empty($this->config[ 'serverIp' ])) { |
|
216 | + if (empty($this->config['serverIp'])) { |
|
217 | 217 | throw new \InvalidArgumentException('RajaSMS: Server Ip Address is not set!'); |
218 | 218 | } |
219 | 219 | |
220 | - if (empty($this->config[ 'apiKey' ])) { |
|
220 | + if (empty($this->config['apiKey'])) { |
|
221 | 221 | throw new \InvalidArgumentException('RajaSMS: API Key is not set'); |
222 | 222 | } else { |
223 | - $params[ 'apikey' ] = $this->config[ 'apiKey' ]; |
|
223 | + $params['apikey'] = $this->config['apiKey']; |
|
224 | 224 | } |
225 | 225 | |
226 | - if ( ! empty($this->config[ 'callbackUrl' ]) and isset($params[ 'datapacket' ])) { |
|
227 | - $params[ 'callbackurl' ] = $this->config[ 'callbackUrl' ]; |
|
226 | + if (!empty($this->config['callbackUrl']) and isset($params['datapacket'])) { |
|
227 | + $params['callbackurl'] = $this->config['callbackUrl']; |
|
228 | 228 | } |
229 | 229 | |
230 | - $uri = (new Uri($this->config[ 'serverIp' ]))->withPath($path); |
|
230 | + $uri = (new Uri($this->config['serverIp']))->withPath($path); |
|
231 | 231 | |
232 | 232 | $request = new Curl\Request(); |
233 | 233 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | */ |
272 | 272 | public function send($msisdn, $message, $masking = false) |
273 | 273 | { |
274 | - $params[ 'datapacket' ] = []; |
|
274 | + $params['datapacket'] = []; |
|
275 | 275 | |
276 | 276 | if (is_array($msisdn)) { |
277 | 277 | $i = 1; |
@@ -279,9 +279,9 @@ discard block |
||
279 | 279 | if (false !== ($sendPackageData = $this->buildSendPackageData([ |
280 | 280 | 'msisdn' => $number, |
281 | 281 | 'message' => $message, |
282 | - 'sendingTime' => isset($this->config[ 'sendingTime' ]) ? $this->config[ 'sendingTime' ] : null, |
|
282 | + 'sendingTime' => isset($this->config['sendingTime']) ? $this->config['sendingTime'] : null, |
|
283 | 283 | ]))) { |
284 | - array_push($params[ 'datapacket' ], $sendPackageData); |
|
284 | + array_push($params['datapacket'], $sendPackageData); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | if ($i === 1000) { |
@@ -293,14 +293,14 @@ discard block |
||
293 | 293 | } elseif (false !== ($sendPackageData = $this->buildSendPackageData([ |
294 | 294 | 'msisdn' => $msisdn, |
295 | 295 | 'message' => $message, |
296 | - 'sendingTime' => isset($this->config[ 'sendingTime' ]) ? $this->config[ 'sendingTime' ] : null, |
|
296 | + 'sendingTime' => isset($this->config['sendingTime']) ? $this->config['sendingTime'] : null, |
|
297 | 297 | ]))) { |
298 | - array_push($params[ 'datapacket' ], $sendPackageData); |
|
298 | + array_push($params['datapacket'], $sendPackageData); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | $credit = $this->getCreditBalance($masking); |
302 | 302 | |
303 | - if (($credit->balance > 500) and (strtotime($credit->expired) > time()) and count($params[ 'datapacket' ]) > 0) { |
|
303 | + if (($credit->balance > 500) and (strtotime($credit->expired) > time()) and count($params['datapacket']) > 0) { |
|
304 | 304 | |
305 | 305 | if ($masking === true) { |
306 | 306 | $result = $this->request('api_sms_masking_send_json.php', $params, 'POST'); |
@@ -308,28 +308,28 @@ discard block |
||
308 | 308 | $result = $this->request('api_sms_reguler_send_json.php', $params, 'POST'); |
309 | 309 | } |
310 | 310 | |
311 | - if (isset($result[ 'sending_respon' ])) { |
|
312 | - if (isset($result[ 'sending_respon' ][ 0 ])) { |
|
313 | - if ($result[ 'sending_respon' ][ 0 ][ 'globalstatus' ] > 10) { |
|
314 | - $this->addError($result[ 'sending_respon' ][ 0 ][ 'globalstatus' ], |
|
315 | - $result[ 'sending_respon' ][ 0 ][ 'globalstatustext' ]); |
|
311 | + if (isset($result['sending_respon'])) { |
|
312 | + if (isset($result['sending_respon'][0])) { |
|
313 | + if ($result['sending_respon'][0]['globalstatus'] > 10) { |
|
314 | + $this->addError($result['sending_respon'][0]['globalstatus'], |
|
315 | + $result['sending_respon'][0]['globalstatustext']); |
|
316 | 316 | |
317 | 317 | return false; |
318 | 318 | } |
319 | 319 | } |
320 | 320 | |
321 | - if (isset($result[ 'sending_respon' ][ 0 ][ 'datapacket' ])) { |
|
321 | + if (isset($result['sending_respon'][0]['datapacket'])) { |
|
322 | 322 | $reports = new ArrayIterator(); |
323 | 323 | |
324 | - foreach ($result[ 'sending_respon' ][ 0 ][ 'datapacket' ] as $respon) { |
|
324 | + foreach ($result['sending_respon'][0]['datapacket'] as $respon) { |
|
325 | 325 | $reports = new SplArrayObject([ |
326 | - 'sendingId' => $respon[ 'sendingid' ], |
|
327 | - 'number' => $respon[ 'number' ], |
|
326 | + 'sendingId' => $respon['sendingid'], |
|
327 | + 'number' => $respon['number'], |
|
328 | 328 | 'sending' => new SplArrayObject([ |
329 | - 'status' => $respon[ 'sendingstatus' ], |
|
330 | - 'message' => $respon[ 'sendingstatustext' ], |
|
329 | + 'status' => $respon['sendingstatus'], |
|
330 | + 'message' => $respon['sendingstatustext'], |
|
331 | 331 | ]), |
332 | - 'price' => $respon[ 'price' ], |
|
332 | + 'price' => $respon['price'], |
|
333 | 333 | ]); |
334 | 334 | } |
335 | 335 | |
@@ -352,17 +352,17 @@ discard block |
||
352 | 352 | */ |
353 | 353 | protected function buildSendPackageData(array $data) |
354 | 354 | { |
355 | - if (preg_match('/^(62[1-9]{1}[0-9]{1,2})[0-9]{6,8}$/', $data[ 'msisdn' ]) == 1) { |
|
356 | - $data[ 'msisdn' ] = '0' . substr($data[ 'msisdn' ], 2); |
|
357 | - } elseif (preg_match('/^(\+62[1-9]{1}[0-9]{1,2})[0-9]{6,8}$/', $data[ 'msisdn' ]) == 1) { |
|
358 | - $data[ 'msisdn' ] = '0' . substr($data[ 'msisdn' ], 3); |
|
355 | + if (preg_match('/^(62[1-9]{1}[0-9]{1,2})[0-9]{6,8}$/', $data['msisdn']) == 1) { |
|
356 | + $data['msisdn'] = '0' . substr($data['msisdn'], 2); |
|
357 | + } elseif (preg_match('/^(\+62[1-9]{1}[0-9]{1,2})[0-9]{6,8}$/', $data['msisdn']) == 1) { |
|
358 | + $data['msisdn'] = '0' . substr($data['msisdn'], 3); |
|
359 | 359 | } |
360 | 360 | |
361 | - if (preg_match('/^(0[1-9]{1}[0-9]{1,2})[0-9]{6,8}$/', $data[ 'msisdn' ]) == 1) { |
|
361 | + if (preg_match('/^(0[1-9]{1}[0-9]{1,2})[0-9]{6,8}$/', $data['msisdn']) == 1) { |
|
362 | 362 | return [ |
363 | - 'number' => trim($data[ 'msisdn' ]), |
|
364 | - 'message' => urlencode(stripslashes(utf8_encode($data[ 'message' ]))), |
|
365 | - 'sendingdatetime' => isset($data[ 'sendingTime' ]) ? $data[ 'sendingTime' ] : null, |
|
363 | + 'number' => trim($data['msisdn']), |
|
364 | + 'message' => urlencode(stripslashes(utf8_encode($data['message']))), |
|
365 | + 'sendingdatetime' => isset($data['sendingTime']) ? $data['sendingTime'] : null, |
|
366 | 366 | ]; |
367 | 367 | } |
368 | 368 | |
@@ -388,18 +388,18 @@ discard block |
||
388 | 388 | $result = $this->request('api_sms_reguler_balance_json.php', [], 'POST'); |
389 | 389 | } |
390 | 390 | |
391 | - if (isset($result[ 'balance_respon' ])) { |
|
392 | - if (isset($result[ 'balance_respon' ][ 0 ][ 'globalstatus' ])) { |
|
393 | - if ($result[ 'balance_respon' ][ 0 ][ 'globalstatus' ] > 10) { |
|
394 | - $this->addError($result[ 'balance_respon' ][ 0 ][ 'globalstatus' ], |
|
395 | - $result[ 'balance_respon' ][ 0 ][ 'globalstatustext' ]); |
|
391 | + if (isset($result['balance_respon'])) { |
|
392 | + if (isset($result['balance_respon'][0]['globalstatus'])) { |
|
393 | + if ($result['balance_respon'][0]['globalstatus'] > 10) { |
|
394 | + $this->addError($result['balance_respon'][0]['globalstatus'], |
|
395 | + $result['balance_respon'][0]['globalstatustext']); |
|
396 | 396 | |
397 | 397 | return false; |
398 | 398 | } |
399 | 399 | |
400 | 400 | $credit = new SplArrayObject([ |
401 | - 'balance' => $result[ 'balance_respon' ][ 0 ][ 'Balance' ], |
|
402 | - 'expired' => $result[ 'balance_respon' ][ 0 ][ 'Expired' ], |
|
401 | + 'balance' => $result['balance_respon'][0]['Balance'], |
|
402 | + 'expired' => $result['balance_respon'][0]['Expired'], |
|
403 | 403 | ]); |
404 | 404 | |
405 | 405 | $result = $credit; |
@@ -422,16 +422,16 @@ discard block |
||
422 | 422 | { |
423 | 423 | $response = json_decode(file_get_contents('php://input'), true); |
424 | 424 | |
425 | - if ( ! empty($response)) { |
|
425 | + if (!empty($response)) { |
|
426 | 426 | $reports = new ArrayIterator(); |
427 | 427 | |
428 | - foreach ($response[ 'status_respon' ] as $respon) { |
|
428 | + foreach ($response['status_respon'] as $respon) { |
|
429 | 429 | $reports[] = new SplArrayObject([ |
430 | - 'sendingId' => $respon[ 'sendingid' ], |
|
431 | - 'number' => $respon[ 'number' ], |
|
430 | + 'sendingId' => $respon['sendingid'], |
|
431 | + 'number' => $respon['number'], |
|
432 | 432 | 'delivery' => new SplArrayObject([ |
433 | - 'status' => $respon[ 'deliverystatus' ], |
|
434 | - 'message' => $respon[ 'deliverystatustext' ], |
|
433 | + 'status' => $respon['deliverystatus'], |
|
434 | + 'message' => $respon['deliverystatustext'], |
|
435 | 435 | ]), |
436 | 436 | ]); |
437 | 437 | } |