微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我如何将 OTP 发送到 Laravel 中的用户电话号码

如何解决我如何将 OTP 发送到 Laravel 中的用户电话号码

我有 gupshup 帐户。我想在 laravel 中创建 api,它将使用 gupshup 帐户将 otp 发送到电话。我是 laravel 的新手

解决方法

根据 Outbound Messages 的 GupShup API 文档,您需要使用您的 API 密钥和信息向他们的服务器发出发布请求。

Laravel 使用 Guzzle HTTP client 发出请求。您可以使用 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
                         ] 
                       ]
                      );

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。