laravel批量短信通知发送



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

我正在使用第三方服务发送短信。您的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旨在被称为服务器到服务器,而不是在浏览器中。

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

在我的例子中,我使用Laravel Trait和guzzlehttp://guzzlePackage来发送批量短信。我所做的步骤类似于低于

i( 我安装了guzzlehttp://guzzlePackage。相关文档为https://laravel.com/docs/8.x/http-client.

ii(我创建了拉拉威尔特质类。在trait类中,我编写了一个发送SMS的方法。我使用CURL调用第三方SMS API。

iii(在控制器中,我导入Trait类,并从那里调用SMS发送特性方法。

我希望这些步骤能有所帮助。

最新更新