al-saloul/msegat

这是一个用于 Msegat 的 Laravel 扩展包。它的目标是简化复杂性

v1.0.2 2024-09-30 10:56 UTC

This package is auto-updated.

Last update: 2024-10-03 06:33:55 UTC


README

这是一个集成 Msegat 短信服务的 Laravel 扩展包。它通过为 Laravel 应用提供易于使用的包装,简化了通过 Msegat API 发送短信的过程。

功能

  • 使用 Msegat API 轻松发送短信。
  • 通过 .env 文件配置凭据(用户名、API 密钥、发送者名称)。
  • 专为 Laravel 应用设计。

要求

  • Laravel 8+ 或 9+ 或 10+ 或 11
  • PHP 7.4+ 或 PHP 8+

安装

要安装此包,请使用 Composer

composer require al-saloul/msegat

发布配置

要发布配置文件,请使用以下命令

php artisan vendor:publish --provider="Alsaloul\Msegat\MsegatServiceProvider"

这将创建一个名为 msegat.php 的配置文件,位于您的 config 文件夹中。

配置

将以下环境变量添加到您的 .env 文件中

MSEGAT_BASEURL="https://www.msegat.com"
MSEGAT_USERNAME=your_msegat_username
MSEGAT_API_KEY=your_msegat_api_key
MSEGAT_USER_SENDER=your_msegat_sender_name

或者,您可以直接编辑 config/msegat.php 文件来设置所需的配置。

用法

要发送短信,请使用 Msegat 门面

use Alsaloul\Msegat\Msegat;

$response = Msegat::sendMessage('966123456789', 'Hello, this is a test message!');

if ($response['code'] === '1') {  
    echo "Message sent successfully!";
} else {
    echo "Failed to send message.";
}

方法

Msegat::sendMessage($numbers, $message)

  • $numbers: 要发送消息的电话号码,以逗号分隔。(例如,96651xxxxxxx96652xxxxxxx
  • $message: 消息内容。

此方法将使用 Msegat API 向指定的号码发送消息。

Msegat::data($numbers, $message)

此方法生成发送短信所需的 JSON 负载。它由 sendMessage() 方法内部使用。

示例

发送单个消息

Msegat::sendMessage('9665xxxxxxxx', 'Hello from Msegat!');

发送多个消息

$numbers = '96651xxxxxxx,96652xxxxxxx';
$message = 'This is a broadcast message.';

$response = Msegat::sendMessage($numbers, $message);

处理错误

如果凭据或所需参数未设置,则将抛出异常

try {
    Msegat::sendMessage('966123456789', 'Testing error handling.');
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

状态码和消息

  • 1 - 成功

  • M0000 - 成功

  • M0001 - 变量缺失

  • M0002 - 无效的登录信息

  • M0022 - 超出允许的发送者数量

  • M0023 - 发送者名称处于激活状态或正在激活或被拒绝

  • M0024 - 发送者名称应为英文或数字

  • M0025 - 发送者名称长度无效

  • M0026 - 发送者名称已激活或未找到

  • M0027 - 激活码不正确

  • 1010 - 变量缺失

  • 1020 - 无效的登录信息

  • 1050 - MSG 正文为空

  • 1060 - 余额不足

  • 1061 - MSG 重复

  • 1064 - 自由 OTP,无效 MSG 内容您应使用 "Pin Code is: xxxx","Verification Code: xxxx" 或升级您的账户并激活您的发送者以发送任何内容

  • 1110 - 发送者名称缺失或不正确

  • 1120 - 手机号码不正确

  • 1140 - MSG 长度过长

  • M0029 - 无效的发送者名称 - 发送者名称应仅包含字母、数字,最大长度应为 11 个字符

  • M0030 - 发送者名称应以 AD 结尾

  • M0031 - 上传文件的最大允许大小为 5 MB

  • M0032 - 只允许 pdf、png、jpg 和 jpeg 文件!

  • M0033 - 发送者类型应为普通或白名单仅限

  • M0034 - 请使用 POST 方法

  • M0036 - 没有任何发送者

贡献

欢迎贡献!请按照以下步骤进行贡献

  1. 分支仓库。
  2. 创建一个新的分支(git checkout -b feature/new-feature)。
  3. 提交您的更改(git commit -am 'Add new feature')。
  4. 推送到分支(git push origin feature/new-feature)。
  5. 创建新的拉取请求。

支持

如果您有任何问题或问题,请自由在GitHub仓库上打开问题,或者通过电子邮件联系作者 eng.alsaloul.mohammed@gmail.com