0

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

4

1 回答 1

0

根据出站消息的 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
                         ] 
                       ]
                      );

于 2021-04-14T11:34:27.617 回答