定制 4jawalycom/sms-gateway-4jawaly 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

4jawalycom/sms-gateway-4jawaly

Composer 安装命令:

composer require 4jawalycom/sms-gateway-4jawaly

包简介

A Laravel SMS Gateway Package for Jawaly SMS Services

README 文档

README

A Laravel package for sending SMS messages through 4Jawaly SMS Gateway (4jawaly.com).

Requirements

  • PHP ^7.4|^8.0|^8.1|^8.2|^8.3
  • Laravel 7.x|8.x|9.x|10.x
  • Guzzle HTTP ^7.0

Installation

  1. Install the package via composer:
composer require 4jawalycom/sms-gateway-4jawaly
  1. Add the service provider to your config/app.php:
'providers' => [
    // ...
    Jawalycom\SMSGateway4Jawaly\SMSGatewayServiceProvider::class,
],

'aliases' => [
    // ...
    'SMSGateway' => Jawalycom\SMSGateway4Jawaly\Facades\SMSGateway::class,
],
  1. Publish the configuration file:
php artisan vendor:publish --provider="Jawalycom\SMSGateway4Jawaly\SMSGatewayServiceProvider"
  1. Add these variables to your .env file:
JAWALY_SMS_API_KEY=your_api_key
JAWALY_SMS_API_SECRET=your_api_secret
JAWALY_SMS_SENDER=your_sender_name

Usage

Method 1: Using the Facade

use Jawalycom\SMSGateway4Jawaly\Facades\SMSGateway;

// Important: All three parameters (number, message, sender) are required
// رقم الجوال ونص الرسالة واسم المرسل كلها متطلبات إلزامية

// Send SMS to a single number
$result = SMSGateway::send('966500000000', 'Your message here', 'SENDER_NAME');

// Send SMS to multiple numbers
$result = SMSGateway::send(
    ['966500000000', '966500000001'],
    'Your message here',
    'SENDER_NAME'
);

// Note: The sender name must be pre-approved by 4jawaly.com
// ملاحظة: يجب أن يكون اسم المرسل معتمداً مسبقاً من 4jawaly.com

// Check the result
if (!empty($result['success'])) {
    echo "Message sent successfully!";
    if (!empty($result['job_ids'])) {
        echo "Job IDs: " . implode(', ', $result['job_ids']);
    }
} else {
    echo "Failed to send message.";
    if (!empty($result['errors'])) {
        foreach ($result['errors'] as $error => $numbers) {
            echo "Error: $error - Numbers: " . implode(', ', $numbers);
        }
    }
}

Method 2: Using Direct Instantiation

use Jawalycom\SMSGateway4Jawaly\SMSGateway;

// Setup configuration array
$config = [
    'api_key' => env('JAWALY_SMS_API_KEY'),
    'api_secret' => env('JAWALY_SMS_API_SECRET'),
    'base_url' => 'https://api-sms.4jawaly.com/api/v1/',
    'default_sender' => env('JAWALY_SMS_SENDER'), // Must be pre-approved by 4jawaly.com
    'timeout' => 30,
    'verify_ssl' => true
];

// Create a new instance
$gateway = new SMSGateway($config);

// Send SMS (all parameters are required)
$result = $gateway->send('966500000000', 'Your message here', 'SENDER_NAME');

// Check the result
if (!empty($result['success'])) {
    echo "Message sent successfully!";
    if (!empty($result['job_ids'])) {
        echo "Job IDs: " . implode(', ', $result['job_ids']);
    }
} else {
    echo "Failed to send message.";
    if (!empty($result['errors'])) {
        foreach ($result['errors'] as $error => $numbers) {
            echo "Error: $error - Numbers: " . implode(', ', $numbers);
        }
    }
}

Getting Account Balance

// Using Facade
$balance = SMSGateway::getBalance();

// Using Direct Instantiation
$sms = new SMSGateway(config('jawaly-sms'));
$balance = $sms->getBalance();

// Get balance with custom options
$balance = SMSGateway::getBalance([
    'is_active' => 1,           // get active packages only
    'order_by' => 'id',         // package_points, current_points, expire_at or id
    'order_by_type' => 'desc',  // desc or asc
    'page' => 1,                // page number
    'page_size' => 10,          // items per page
    'return_collection' => 1    // get all collection
]);

Getting Sender Names

// Using Facade
$senders = SMSGateway::getSenderNames();

// Using Direct Instantiation
$sms = new SMSGateway(config('jawaly-sms'));
$senders = $sms->getSenderNames();

// Get sender names with custom options
$senders = SMSGateway::getSenderNames([
    'page_size' => 10,          // items per page
    'page' => 1,                // page number
    'status' => 1,              // 1 for active, 2 for inactive
    'sender_name' => '',        // search by sender name
    'is_ad' => '',             // 1 for ads, 2 for not ads
    'return_collection' => 1    // get all collection
]);

Response Format

Send SMS Response

[
    'success' => true,
    'job_id' => 'xxxxx',
    'data' => [
        // Full response from the API
    ]
]

Balance Response

{
    "collection": [
        {
            "id": xxx,
            "package_points": xxx,
            "current_points": xxx,
            "expire_at": "yyyy-mm-dd",
            // ... other package details
        }
    ],
    "pagination": {
        "total": xxx,
        "count": xxx,
        "per_page": xxx,
        "current_page": x,
        "total_pages": x
    }
}

Sender Names Response

{
    "collection": [
        {
            "id": xxx,
            "sender_name": "SENDER_NAME",
            "status": x,
            "note": "xxx",
            // ... other sender details
        }
    ],
    "pagination": {
        "total": xxx,
        "count": xxx,
        "per_page": xxx,
        "current_page": x,
        "total_pages": x
    }
}

Error Handling

The package throws exceptions for various error cases:

  • Invalid credentials
  • Empty message
  • Invalid sender name
  • Network errors
  • API errors

Example error handling:

try {
    $result = SMSGateway::send('966500000000', 'Your message', 'SENDER_NAME');
    // Message sent successfully
    echo "Message sent! Job ID: " . $result['job_id'];
} catch (\Exception $e) {
    // Handle the error
    echo "Error: " . $e->getMessage();
}

Features

  • Send SMS to single or multiple numbers
  • Support for Arabic and Unicode messages
  • Get account balance and package details
  • Retrieve approved sender names with filtering options
  • Pagination support for balance and sender names
  • Exception handling with meaningful error messages
  • Laravel integration with Facade support
  • Support for PHP 7.4 to 8.3
  • Support for Laravel 7.x to 10.x

Support

For support, please contact info@4jawaly.com

License

The MIT License (MIT). Please see License File for more information.

4jawalycom/sms-gateway-4jawaly 适用场景与选型建议

4jawalycom/sms-gateway-4jawaly 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.77k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 4jawalycom/sms-gateway-4jawaly 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-05