msg91 / msg91-one-api
一个用于运行 MSG91 服务的 Laravel PHP 包
dev-main
2024-06-19 07:04 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is not auto-updated.
Last update: 2024-09-26 06:30:26 UTC
README
简介
msg91/msg91
是一个 Laravel PHP 包,提供了将 MSG91 服务集成到您的 Laravel 应用程序中的功能。
安装
您可以通过 Composer 安装此包。在您的 Laravel 项目目录中运行以下命令
composer require msg91/msg91
用法
OTP 验证
安装此包后,您可以在 Laravel 应用程序中使用它进行 OTP 验证,如下所示
use Msg91\Services\OTPService; // Import the OTPService class $otpService = new OTPService(); // Instantiate the OTPService class $authKey = 'your_auth_key'; $token = 'access-token'; // Replace with the actual access token to verify $response = $otpService->verifyToken($authKey, $token); // Handle the response // Example: if ($response['type'] === 'success') { echo 'OTP verification successful'; } else { echo 'OTP verification failed: ' . $response['message']; }
活动服务
您还可以使用此包通过 CampaignService 运行活动。以下是在 Laravel 应用程序中使用 CampaignService 的示例
use Msg91\Services\CampaignService; // Instantiate the CampaignService class $service = new CampaignService('your_auth_key'); // Define your campaign slug and input data : max 1000 including cc and bcc as individual entity $campaignSlug = 'your_campaign_slug'; $inputData = [ "data" => [ [ "to" => 'recipient1@example.com', "cc" => 'cc1@example.com', "bcc" => 'bcc1@example.com', "mobiles" => '919876543210', "name" => 'Recipient 1', "from_name" => 'Sender Name', "from_email" => 'sender@example.com', "variables" => [ "var1" => 'value1', "var2" => 'value2', ], ], [ "to" => 'recipient1@example.com', "cc" => 'cc1@example.com', "bcc" => 'bcc1@example.com', "mobiles" => '919876543210', "name" => 'Recipient 1', "from_name" => 'Sender Name', "from_email" => 'sender@example.com', "variables" => [ "var1" => 'value1', "var2" => 'value2', ], ], ... ]; // Run the campaign $response = $service->runCampaign($campaignSlug, $inputData); // Handle the response var_dump($response);
许可证
此包是开源软件,使用 MIT 许可证授权。