<?php
include 'connect.php';
header('Content-Type: application/json; charset=utf-8');
header("Access-Control-Allow-Origin: *");
$json = file_get_contents('php://input');
$obj = json_decode( $json );
$usernum =  $obj->{'usernumber'} ;
$countryCode =  $obj->{'countrycode'} ;

$usernumber = '+'.$countryCode.$usernum;

require_once 'Twilio/autoload.php';
use Twilio\Rest\Client;

$twilio_number = "+14793232115";//"+447723365161";
$account_sid = "AC3182fb6256eae9aa859c3f112ee29a1d";//"ACdfcacc9f322707d47cabc84276f86a84";
$auth_token = "d64c62578e977983f6f0be51a0596410";//"23cb0b5d43067f760c9b5a9991c01150";

$account_sid = $account_sid;
$auth_token = $auth_token;
//$usernumber = '+918013247774';
$usrcel = $usernumber;
$r = mt_rand(100000, 999999);
$otp = $r;
$sms = $lang_resources->YOUR_OTP_NUMBER." ".$otp;

$space = implode(' ', str_split($otp));
$sms = 'Your OTP is '. $space;

$safeSms = htmlspecialchars($sms, ENT_XML1 | ENT_QUOTES, 'UTF-8');

// Create XML content
$xmlContent = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say voice="woman">$safeSms</Say>
</Response>
XML;
// write code on xml file
file_put_contents('makevoice.xml', $xmlContent);

$client = new Client($account_sid, $auth_token);
$call = $client->calls->create(
    $usrcel, // To
    $twilio_number, // From
    ["url" => "https://plugins-development.ordering.co/tikram/makevoice.xml"]
);
//new twillo code
$response['sms'] = $sms;
$response['code'] = $otp;
$response['error'] = false;
echo json_encode($response);

?>
