laravel 群发短信通知发送

laravel bulk sms notification sending

你好,我是 laravel 的新手,我正在尝试从 api 发送短信通知。

我正在使用第 3 方服务发送短信,您的 php 代码集成文档较少。和 API URL

当我在 laravel 表单控制器中尝试时,表单提交短信通知将由此触发 但问题是我的 API 用户名和密码显示在浏览器 URL 中,检查网络选项卡也是个问题我不想向任何人显示我的 API 凭据

return redirect()->away("http://api.bulksmsgateway.in/sendmessage.php?user=....&password=.......&mobile=........&message=hello&sender=.......&type=3&template_id=123"); 

** php代码集成服务商文档**

<?php
error_reporting (E_ALL ^ E_NOTICE);
$username="XXXXXXX";
$password ="XXXXXXX";
$number=$_POST['number'];
$sender="abc";
$message=$_POST['message'];
$template_id='12345';
if($_POST['submitted']=='true')
{ 
$url="http://api.bulksmsgateway.in/sendmessage.php?user=".urlencode($username)."&password=".urlencode($password)."&mobile=".urlencode($number)."&sender=".urlencode($sender)."&message=".urlencode($message)."&type=".urlencode('3')."&template_id=".urlencode($template_id);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $curl_scraped_page = curl_exec($ch);
curl_close($ch); 
}

?>
<html>
<head>
</head>
<body>
<form action="" method="post" name="sms_gate" >
<br />
Number : <br />
<input type="text" name="number" />
<br /><br />
Message:<br/>
<textarea name="message" ></textarea>
<input type="hidden" name="submitted" value="true" />
<br />
<input type="submit" name="submit" value="send" />
</form>
</body>
</html>

** API URL 代码集成服务商文档提供此**

URL : http://api.bulksmsgateway.in/sendmessage.php?user=....&password=.......&mobile=........&message=hello&sender=.......&type=3&template_id=123

我的控制器

public function Store_Enrollment(Request $request)

    {

      $this->validate($request, [

  'student_name' => 'required|string|max:255',
  'student_phone_no' => 'required|string|max:10',
         
    ]);
 
   $input['student_name'] = ucfirst ($request['student_name']);
   $input['student_phone_no'] = $request->student_phone_no;
   $redirect = Student::create($input); 
 
  
return redirect()->away("http://api.bulksmsgateway.in/sendmessage.php?user=XXX&password=XXX&mobile=$redirect->student_phone_no&message=Dear  $redirect->student_name,  G&sender=ABC&type=3&template_id=112"); 

}

API这样的名字是为了被称为​​server-to-server,而不是在浏览器中。

您可以使用 Laravel HTTP client 从您的服务器调用此 API;这不会暴露 API 密钥或其他敏感数据。

就我而言,我使用 Laravel Trait 和 guzzlehttp/guzzle Package 来发送群发短信。 我执行的步骤如下所示

i) 我安装了 guzzlehttp/guzzle 包。相关文档是 https://laravel.com/docs/8.x/http-client.

ii) 我创建了 Laravel 特征 class。在 trait class 里面,我写了一个发送短信的方法。我用CURL调用第三方短信API.

iii) 在控制器中我导入了 Trait class 并从那里调用 SMS 发送 trait 方法。

希望这些步骤对您有所帮助。