-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresult.php
74 lines (61 loc) · 1.73 KB
/
result.php
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
<?php
session_start();
?>
<?php
if(isset($_POST['button1'])){
//input from the form
$otp_code=filter_input(INPUT_POST,'otp');
print_r($_SESSION);
$phone_number=$_SESSION["phonenumber"];
echo $phone_number;
//API URL
require 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
$auth_id = getenv('AUTH_ID');
$secret_id=getenv('SECRET_ID');
$url = "https://api.tiniyo.com/v1/Account/".$auth_id."/VerificationsCheck";
//create a new cURL resource
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_VERBOSE, true);
//setup request to send json via POST
$data=array("code"=> $otp_code, "dst"=> $phone_number);
$payload = json_encode($data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$auth_id:$secret_id");
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
//attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload))
);
//return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute the POST request
$returns = curl_exec($ch);
// check the HTTP Status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
switch ($httpCode) {
case 200:
$resp = json_decode($returns);
if ($resp->status) {
echo "Status: ".$resp->status." Message:".$resp->message."\n";
if ( $resp->status == "success" ) {
echo "OTP VERIFIED\n";
}
} else {
echo "OTP Verification Failed\n";
}
break;
default:
echo 'Http Error: ' . $httpCode . ' : ' . curl_error($ch);
break;
}
//close cURL resource
curl_close($ch);
exit();
}
?>