bundana/services 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bundana/services

Composer 安装命令:

composer require bundana/services

包简介

List of API services for development e.g. SMS, WhatsApp, email, etc.

README 文档

README

This package provides an easy-to-use interface for integrating the Mnotify SMS API into your PHP applications. The package allows you to send single and bulk SMS, check SMS balance, and register sender IDs with the Mnotify API.

Installation

To use this package, make sure you have the following environment variables set in your .env file:

MNOTIFY_API_KEY=your_api_key
MNOTIFY_SENDER_ID=your_sender_id
MNOTIFY_API_KEY_V2=your_api_key_v2
MNOTIFY_SENDER_ID_V2=your_sender_id_v2

Basic Usage

1. Sending a Single SMS

To send a single SMS, you can use the Mnotify::to() method to specify the recipient’s phone number, followed by the message() method to set the SMS content. Finally, call send() to dispatch the message.

use Bundana\Services\Messaging\Mnotify;

// Example of sending a single SMS
$response = Mnotify::to('1234567890') // recipient phone number
    ->message('Hello, this is a test message!') // message content
    ->send(); // send the message

// The $response will contain the success status and details of the send operation
echo $response;

2. Checking SMS Balance

To check your SMS balance, use the SMSBalance() method. This can be done for both API version 1 (default) and version 2.

use Bundana\Services\Messaging\Mnotify;

// Example of checking balance
$response = Mnotify::SMSBalance(); // by default, checks using version 1

// If you need to check balance using version 2
$response_v2 = Mnotify::SMSBalance('v2');

// The $response will contain the SMS balance or an error message
echo $response;

3. Sending Bulk SMS

To send bulk SMS to multiple recipients, use the sendBulk() method. This method takes an associative array where the keys are phone numbers and the values are the corresponding messages to send.

use Bundana\Services\Messaging\Mnotify;

// Example of sending bulk SMS
$contactsAndMessages = [
    '1234567890' => 'Message to recipient 1',
    '0987654321' => 'Message to recipient 2',
    '5555555555' => 'Message to recipient 3',
];

$response = Mnotify::sendBulk($contactsAndMessages); // sending using version 1 by default

// To send using version 2, pass the 'v2' as a second argument
$response_v2 = Mnotify::sendBulk($contactsAndMessages, 'v2');

// The $response will contain the success status and details of the send operation
print_r($response);

4. Registering a Sender ID

To register a sender ID with Mnotify, use the registerSenderID() method. This method takes two parameters: the sender ID and the purpose for registering the sender ID.

use Bundana\Services\Messaging\Mnotify;

// Example of registering a sender ID
$senderId = 'MySenderID';
$purpose = 'Transactional Messages';

$response = Mnotify::registerSenderID($senderId, $purpose);

// The $response will contain the success status and details of the registration
echo $response;

Additional Features

  • Set Custom API Keys: You can dynamically set API keys using the newKeys() method if you need to override the environment variables.

    Example:

    $customKeys = [
        'apiKey' => 'custom_api_key',
        'sender_id' => 'custom_sender_id',
    ];
    
    $response = Mnotify::to('1234567890')
        ->message('Hello, custom API keys!')
        ->newKeys($customKeys)
        ->send();
  • Scheduled SMS: To schedule SMS for future delivery, you can pass a schedule_date to the send() method.

    Example:

    $response = Mnotify::to('1234567890')
        ->message('This message will be sent later!')
        ->send(null, '2024-10-31 10:00:00');

Error Handling

Each method returns a JSON-encoded response. If an error occurs, the response will include an error message and a status of false.

Example error response:

{
    "success": false,
    "message": "Invalid recipient number."
}

API Versioning

By default, the package uses Mnotify API version 1 (v1). If you need to use API version 2, pass 'v2' as a parameter when sending messages or checking the balance.

License

This package is open-source and licensed under the MIT License.

This README.md file provides comprehensive documentation for using the Mnotify class, covering the key functionalities such as sending SMS, checking balance, bulk SMS, and registering sender IDs. You can further extend this document with additional details if required.

bundana/services 适用场景与选型建议

bundana/services 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 101 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 01 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 bundana/services 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bundana/services 我们能提供哪些服务?
定制开发 / 二次开发

基于 bundana/services 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 101
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-26