<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
require_once '../lib/dbclass.php';

extract($_POST);
$data = $_REQUEST;

$to  = $_REQUEST['mobile'];
$otp = rand(1000, 9999);

$msg     = "Login OTP for validating your mobile number is $otp.C H Centre.";
$api_key = 'abe5be8596dad67f4a34a6296dee999d';
$from1   = '636863656e747265';

if (!$api_key) {
    return false;
}

$from     = 'CHCENT';
$contacts = $to;
$sms_text = urlencode($msg);
$api_url  = 'http://vasbay.com/webservice/smsSimpleApi.php?usersName=' .
    $from1 .
    '&key=' .
    $api_key .
    '&route=2&numbers=' .
    $contacts .
    '&senderId=' .
    $from .
    '&message=' .
    $sms_text;

//Submit to server
$response = file_get_contents($api_url);

$yummy = json_decode($response, true);



$status = $yummy['msg']['response']['count'];



if ($status > 0) {
    $data_detail['code']   = $otp;
    $data_detail['status'] = 0;
    $data_detail['mobile'] = $to;

    $iddtl = saveArray('ca_otp', $data_detail, 0);

    $message = 'True';
} else {
    $message = 'false';
}

$data2 = 0;
echo json_encode(['Status' => $message, 'data' => $data2]);

return;
?>	   

