-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdump
More file actions
110 lines (103 loc) · 3.33 KB
/
dump
File metadata and controls
110 lines (103 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
session_start();
class SendOTP
{
private $baseUrl = "https://sendotp.msg91.com/api";
public function callGenerateAPI($request)
{
$data = array("countryCode" => $request['countryCode'], "mobileNumber" => $request['mobileNumber'], "getGeneratedOTP" => true);
$data_string = json_encode($data);
$ch = curl_init($this->baseUrl . '/generateOTP');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'application-Key: 154290AGqS2KTfWh592d4a02'
));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
public function saveOTP($OTP)
{
//save OTP to your session
$_SESSION["oneTimePassword"] = $OTP;
// OR save the OTP to your database
//connect db and save it to a table
return true;
}
public function generateOTP($request)
{
echo 'in fun';
var_dump($request);
//call generateOTP API
$response = $this->callGenerateAPI($request);
$response = json_decode($response, true);
if ($response["status"] == "error") {
//customize this as per your framework
echo $response["response"]["code"];
return;
}
//save the OTP on your server
if (isset($response["response"]["oneTimePassword"])) {
if ($this->saveOTP($response["response"]["oneTimePassword"])) {
echo "OTP SENT SUCCESSFULLY";
return;
} else {
echo "OTP NOT SAVED SUCCESSFULLY";
}
} else {
echo "OTP SENT SUCCESSFULLY";
}
}
public function verifyOTP($request)
{
//This is the sudo logic you have to customize it as needed.
//your verify logic here
if ($request["oneTimePassword"] == $_SESSION["oneTimePassword"]) {
echo "NUMBER VERIFIED SUCCESSFULLY";
return;
} else {
echo "OTP INVALID";
return;
}
// OR get the OTP from your db and check against the OTP from client
}
public function verifyBySendOtp($request)
{
$data = array("countryCode" => $request['countryCode'], "mobileNumber" => $request['mobileNumber'], "oneTimePassword" => $request['oneTimePassword']);
$data_string = json_encode($data);
$ch = curl_init($this->baseUrl . '/verifyOTP');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'application-Key: Put your Application key'
));
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, true);
if ($response["status"] == "error") {
//customize this as per your framework
echo $response["response"]["code"];
return;
} else {
echo "NUMBER VERIFIED SUCCESSFULLY";
}
}
}
$sendOTPObject = new SendOTP();
if (isset($_REQUEST['action']) && !empty($_REQUEST['action'])) {
var_dump($_REQUEST);
$funname = $_REQUEST['action'];
echo $sendOTPObject->$funname($_REQUEST);
} else {
echo "Error Wrong api";
}
?>