<?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 );
$usernumber =  $obj->{'usernumber'} ;
$usernumber = '+919163898176';

require_once 'Twilio/autoload.php';
use Twilio\TwiML\MessagingResponse;
$response = new MessagingResponse();
$body = $_REQUEST['Body'];


$fromnumber = "+447723365161";
$account_sid = "ACdfcacc9f322707d47cabc84276f86a84";
$auth_token = "23cb0b5d43067f760c9b5a9991c01150";

$r = mt_rand(1000, 9999);
$otp = $r;
$sms = $lang_resources->YOUR_OTP_NUMBER.": ".$otp;
$sms = 'your otp is'.": ".$otp;
/*$client = new Client($account_sid, $auth_token);
$message = $client->messages->create(
    "whatsapp:+918013247774", // To
    [
        "from" => "whatsapp:+14155238886",
        "contentSid" => "HXb5b62575e6e4ff6129ad7c8efe1f983e",
        "contentVariables" => json_encode([
            "1" => "22 July 2026",
            "2" => "3:15pm",
        ]),
    ]
);
print $message->body;*/
/*$to= $usernumber;
$from= "whatsapp:".$fromnumber;
//$body = "Hi".$customername;
$body = $sms ;
$to = urlencode($to);
$from = urlencode($from);
$body = urlencode($body);
$bodymsg = str_replace("%5Cn","%0A",$body);
//$body123 = $body;
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.twilio.com/2010-04-01/Accounts/ACdfcacc9f322707d47cabc84276f86a84/Messages.json',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => 'To='.$to.'&From='.$from.'&MessagingServiceSid=MG0308adf27c931ebaaf62169e74c56fc9&Body='.$bodymsg,
  CURLOPT_HTTPHEADER => array(
    'Authorization: Basic QUNkZmNhY2M5ZjMyMjcwN2Q0N2NhYmM4NDI3NmY4NmE4NDoyM2NiMGI1ZDQzMDY3Zjc2MGM5YjVhOTk5MWMwMTE1MA==',
    'Content-Type: application/x-www-form-urlencoded'
  ),
));
$msgresponse = curl_exec($curl);
curl_close($curl);


$result = json_decode($msgresponse);
print_r($result);*/

$response['sms'] = $sms;
$response['code'] = $otp;
$response['error'] = false;


echo json_encode($response);		

?>