1
|
|
|
<?php |
2
|
|
|
namespace Sender\Otp; |
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 OTP |
12
|
|
|
* |
13
|
|
|
* @package Sender\OtpSend |
14
|
|
|
* @author VenkatS <[email protected]> |
15
|
|
|
* @link https://github.com/tesark/msg91-php |
16
|
|
|
* @license MIT |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
class OtpSend extends OtpBuildClass |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* This function for send OTP |
23
|
|
|
* |
24
|
|
|
* @param array $dataArray |
25
|
|
|
* @param array $data |
26
|
|
|
* |
27
|
|
|
* @throws ParameterException missing parameters or return empty |
28
|
|
|
* @return string Msg91 Json response |
29
|
|
|
*/ |
30
|
15 |
|
public function sendOtp($dataArray, $data) |
31
|
|
|
{ |
32
|
15 |
|
$this->inputData = $dataArray; |
33
|
15 |
|
$this->sendData = $data; |
34
|
15 |
|
if ($this->hasInputData() && $this->hasSendData()) { |
35
|
15 |
|
if ($this->checkAuthKey() && $this->checkMobile()) { |
36
|
15 |
|
$data = $this->sendData; |
37
|
|
|
//add sender on the Array |
38
|
15 |
|
$data = $this->addSender($this->inputData, $data); |
39
|
|
|
//add otp_expiry on the array |
40
|
12 |
|
$data = $this->addOtpExpiry($this->inputData, $data); |
41
|
|
|
//add otp_length on the array |
42
|
9 |
|
$data = $this->addOtpLength($this->inputData, $data); |
43
|
5 |
|
$checkOtp = $this->isKeyExists('otp', $this->inputData); |
44
|
5 |
|
$checkMsg = $this->isKeyExists('message', $this->inputData); |
45
|
5 |
|
if ($checkOtp && $checkMsg) { |
46
|
|
|
//add message on array |
47
|
3 |
|
$data = $this->addMessage($this->inputData, $data); |
48
|
|
|
//add otp on the array |
49
|
2 |
|
$data = $this->addOtp($this->inputData, $data); |
50
|
|
|
} |
51
|
2 |
|
if (($checkOtp && !$checkMsg) || (!$checkOtp && $checkMsg)) { |
52
|
2 |
|
throw ParameterException::missinglogic("When using otp or message, unable to use seperately"); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
$uri = "sendotp.php"; |
56
|
|
|
$delivery = new Deliver(); |
57
|
|
|
$response = $delivery->sendOtpGet($uri, $data); |
58
|
|
|
return $response; |
59
|
|
|
} else { |
60
|
|
|
$message = "Parameters not found"; |
61
|
|
|
throw ParameterException::missinglogic($message); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|