laravel - 如何将 OTP 发送到 Laravel 中的用户电话号码
问题描述
我有 gupshup 帐户。我想在 laravel 中创建 api,它将使用 gupshup 帐户将 otp 发送到手机。我是 laravel 的新手
解决方案
根据出站消息的 GupShup API 文档,您需要使用您的 API 密钥和信息向他们的服务器发出发布请求。
Laravel 使用 Guzzle HTTP 客户端发出请求。您可以使用HTTP
外观发出发布请求。下面是一个未经测试的示例:
use Illuminate\Support\Facades\Http; // To be added to the top of your file where you add the code below
// Put the following code in the function which sends out the OTP.
$response = Http::withHeaders([
"Content-Type" => "application/x-www-form-urlencoded",
"apikey": "{{Your API Key}}" // replace with your API key
])
->post('https://api.gupshup.io/sm/api/v1/msg',
[
"channel" => "whatsapp",
"source" => "1111111111", // your business number
"destination" => "9999999999", // clients number
"src.name" => "Your App" // Your App Name
"message" => [
"isHSM" => "false",
"type" => "text",
"text" => "{{Your OTP is XXXXX}}" // replace with text you want to send
]
]
);
推荐阅读
- node.js - 如何使用 dialogflow 实现 node.js 在谷歌操作上实现二元决策树?
- sql-server - 如何使用 SQL Server 存储过程获得这样的响应
- java - 为从字符串创建的查询添加限制和偏移量
- javascript - 给定指定时区的 Javascript 时区更改
- python - 类中的 python 函数与 java/c++ 中的函数有何不同?
- php - php在一个语句中通过未知索引获取数组的值
- javascript - fetch-mock:没有为 POST 定义回退响应
- java - Java方法引用选择窄类型
- spring - spring如何将请求参数的value属性的数据转换为字符串内容
- http - 如何在 nodejs 中创建 http 和 https 服务器?