public function SendOTP(Request $request)
{
$mobile = $request->input('mobile_no');
// Check if an OTP request has been made for this mobile number in the last 20 seconds
if (!Cache::has('otp_request_' . $mobile)) {
$pin = mt_rand(100000, 999999);
$message1 = "KSRTC - " . $pin . " is your OTP for application submission confirmation. Please enter it to proceed.";
$str = 'username=ksrtcfrontoffic&password=ksrtc123499&message=' . $message1 . "&numbers=" . $mobile . "&senderid=KSRTCMG";
$url = 'http://api.sms.tn.gov.in/fastclient/SMSclient.php?' . $str;
session(['otp' => $pin]);
$response = Http::get($url);
if ($response->ok()) {
// Set a rate limit for this mobile number for 20 seconds
Cache::put('otp_request_' . $mobile, true, 20);
return response()->json(['success' => true]);
}
}
return response()->json(['success' => false]);
}
WAIT, you allow the user to specify the mobile number to use? That totally breaks the point of OTP. I thought you had this app security checked?
If you just published your service credentials in this post, edit the question, and request a new password from the provider
put something like this in its own class
extract username, password and url into a service config which gets its values from ENV. Don't bake them into your code. At present If any of the values change you have to redeploy your code. Also, you dont want service credentials stored in your code repo.
catch exceptions thrown by the Http request
The error is that the connection timed out.
Either the url changed, or your credentials are not valid or the service is down
@Snapey and all : That credentials and details are dummy values ( for posting here). My Question is
this SMS service and form is working in localhost as shown
It's shown that error in Staging Server . What may be I am wrong ?
No it's a staging server. I can access server through my network but if server is away from internet it cannot access a resource like sms gateway. Hope you get me ?
@insight well obviously, the machine is going to need internet access if it wants to communicate with the outside world. I would have thought that obvious???