Laravel 的 SMS 包 - 通过 sms.net.bd 的 SMS 网关简化 SMS 集成。在 Laravel 应用程序中轻松发送消息、检查余额、获取投递报告和管理 SMS。

1.0.4 2024-03-24 09:33 UTC

This package is auto-updated.

Last update: 2024-09-24 10:33:31 UTC


README

Packagist version mit Packagist Downloads

Laravel 的 SMS 包 - 通过 sms.net.bd 简化 SMS 集成。在 Laravel 应用程序中轻松发送消息、检查余额、获取投递报告和管理 SMS。

SMS Laravel 包提供了从 php 应用程序到 sms.net.bd REST API 的便捷访问。

今天注册 免费的 sms.net.bd 账户,并从我们先进的 SMS 平台获取您的 API 密钥。此外,您还可以享受免费额度来测试您的 API!

示例

查看其他代码 示例

功能

  • 通过 sms.net.bd sms 网关 发送 SMS 消息。
  • 安排 SMS 消息的将来投递。
  • 使用发送者 ID 向多个收件人发送 SMS。
  • 检索 SMS 投递报告。
  • 检查账户余额和余额有效性。

要求

  • Laravel 框架 7.x
  • PHP 7.2 或更高版本

安装

使用 Composer 安装此包

composer require sms_net_bd/sms

在 .env 文件中设置您的 SMS API 密钥

SMS_NET_BD_API_KEY=your-api-key

注意:请确保将占位符 your-api-key 替换为您的实际 API 密钥

用法

use sms_net_bd\SMS; // Import the SMS class

// Create an instance of the class
$sms = new SMS();

try {
    // Send Single SMS
    $response = $sms->sendSMS(
        "Hello, this is a test SMS!",
        "01701010101"
    );

    // Send Multiple Recipients SMS
    $response = $sms->sendSMS(
        "Hello, this is a test SMS!",
        "01701010101,+8801856666666,8801349494949,01500000000"
    );

    // Send SMS With Sender ID or Masking Name
    $response = $sms->sendSMS(
        "Hello, this is a test SMS!",
        "01701010101",
        "sms.net.bd"
    );

    // Schedule SMS for future delivery
    $response = $sms->sendScheduledSMS(
        "Scheduled SMS",
        "8801701010101",
        "2023-12-01 14:30:00" // Date format: YYYY-MM-DD HH:MM:SS
    );

    // Schedule SMS for future delivery with Sender ID
    $response = $sms->sendScheduledSMS(
        "Scheduled SMS with date",
        "8801701010101",
        "2023-12-01 14:30:00",
        "sms.net.bd"
    );

    // Get SMS delivery report
    $report = $sms->getReport($requestId);

    // Check account balance
    $balanceInfo = $sms->getBalance();

} catch (Exception $e) {
    // handle $e->getMessage();
}

注意:请确保将占位符值替换为您的电话号码和消息。

错误处理

该包提供了更好的错误处理。如果 API 响应有错误(错误 != 0),则抛出包含错误消息的异常。

try {
    $response = $sms->sendSMS('Invalid Recipient', '+invalid-number');
} catch (\Exception $e) {
    // Handle the exception, log the error, or display a user-friendly message.
    echo 'Error: ' . $e->getMessage();
}

许可

此软件包是开源软件,根据 MIT 许可证 许可。

贡献

欢迎贡献!您可以随意提交 问题打开一个拉取请求

支持

如果您有任何问题或反馈,请 打开一个问题打开一个拉取请求