I am creating signup page in react native.I wanted to generate random otp. And opt will send to user who is performing sign up process. For sending i am using msg91 gatway. But i am having error displayed above.. signupUser function in called over submit button click which will call php api to call msg91 gateway. i m new for react native as well msg91/ please draw me to the issue with my code and below is my code:
export const signUpUser = ({ name, password, mobile }) => {
return (dispatch) => {
console.log('signupaction');
//Multiple mobiles numbers separated by comma
mobileNumber = mobile;
console.log('signupaction'+mobile);
var url = "http://congenitalart.com/test/process.php";
return fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/text',
'Content-Type': 'application/text',
},
data: mobileNumber
})
.then(function(response) {
return response.text();
})
.then(function(data){
console.log(data); //this will just be text
var data_obj = JSON.parse(data);
return data_obj
})
.catch(function(error) {
console.log('There has been a problem with your fetch operation: ' + error.message);
throw error;
});
};
};
process.php
<?php
//session_start();
echo'test process';
//Your authentication key
$authKey = '190301AU2RL0SzSK5a460060';
//Multiple mobiles numbers separated by comma
$mobileNumber = $_POST["data"];
echo($mobileNumber);
//Sender ID,While using route4 sender id should be 6 characters long.
$senderId = "MSGIND";
//Your message to send, Add URL encoding here.
$rndno=rand(1000, 9999);
$message = urlencode("your OTP for registering with theatrebay.com is".$rndno);
//Define route
$route = "SendOTP";
//Prepare you post parameters
$postData = array(
'authkey' => $authKey,
'mobiles' => $mobileNumber,
'message' => $message,
'sender' => $senderId,
'route' => $route
);
//API URL
$url="https://control.msg91.com/api/sendhttp.php";
// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData
//,CURLOPT_FOLLOWLOCATION => true
));
//Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//get response
$output = curl_exec($ch);
//Print error if any
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
if(isset($_POST['submit']))
{
$_SESSION['date']=$_POST['date'];
$_SESSION['tickettype']=$_POST['tickettype'];
$_SESSION['ticketcount']=$_POST['ticketcount'];
$_SESSION['name']=$_POST['username'];
$_SESSION['email']=$_POST['emailid'];
$_SESSION['phone']=$_POST['mobileno'];
$_SESSION['password']=$_POST['password'];
$_SESSION['otp']=$rndno;
$_SESSION['isSold'] = $_POST['cod'];
$_SESSION['booking'] = "booking";
header( "Location: otp.php" );
}
}
}
return 0;
}
?>