elbrahms/wa-gateway 问题修复 & 功能扩展

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

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

elbrahms/wa-gateway

最新稳定版本:v1.0.1

Composer 安装命令:

composer require elbrahms/wa-gateway

包简介

Laravel package for WhatsApp messaging via the Whatsms gateway API

README 文档

README

Latest Version on Packagist PHP Version Require License

Laravel package for sending WhatsApp messages through the Whatsms gateway API.
Supports text, media, polls, stickers, buttons, lists, locations, vCards, and device/user management.

Requirements

  • PHP ≥ 8.1
  • Laravel 11 or 12
  • A running Whatsms gateway instance

Installation

composer require elbrahms/wa-gateway

The service provider and facade are registered automatically via Laravel's package discovery.

Publish the config file:

php artisan vendor:publish --tag=wa-gateway-config

Configuration

Add these variables to your .env:

WA_GATEWAY_URL=https://whatsms.fite-ne.com
WA_GATEWAY_API_KEY=your_api_key_here
WA_GATEWAY_SENDER=22799749554
WA_GATEWAY_TIMEOUT=30
WA_GATEWAY_VERIFY_SSL=true

Usage

Via the Facade

use Elbrahms\WaGateway\Facades\WaGateway;

// Send a text message
WaGateway::sendMessage('22799123456', 'Hello from Laravel!');

// Send an image
WaGateway::sendMedia('22799123456', 'image', 'https://example.com/photo.jpg', 'Check this out!');

// Send a document
WaGateway::sendMedia('22799123456', 'document', 'https://example.com/report.pdf');

// Send a poll
WaGateway::sendPoll('22799123456', 'Favourite color?', ['Red', 'Blue', 'Green']);

// Send a sticker
WaGateway::sendSticker('22799123456', 'https://example.com/sticker.webp');

// Send a location
WaGateway::sendLocation('22799123456', '13.5137', '2.1098');

// Send a vCard
WaGateway::sendVcard('22799123456', 'Ibrahim Sidi', '22799000000');

// Check if a number is on WhatsApp
$result = WaGateway::checkNumber('22799123456');
// $result['msg']['exists'] === true

Button Message

WaGateway::sendButton(
    number: '22799123456',
    message: 'How can we help?',
    buttons: [
        ['type' => 'reply',  'displayText' => 'Support'],
        ['type' => 'url',    'displayText' => 'Website', 'url' => 'https://fite-ne.com'],
        ['type' => 'call',   'displayText' => 'Call us', 'phoneNumber' => '22799749554'],
        ['type' => 'copy',   'displayText' => 'Copy code', 'copyCode' => 'PROMO2025'],
    ],
    footer: 'Powered by WaGateway'
);

List Message

WaGateway::sendList(
    number: '22799123456',
    message: 'Choose a department',
    title: 'Our Departments',
    buttonText: 'View list',
    list: ['Sales', 'Support', 'Billing', 'Technical'],
    footer: 'We reply within 24 h'
);

Device Management

// Generate QR code to connect a device
$qr = WaGateway::generateQr('22799749554');
// $qr['qrcode'] is a base64-encoded PNG — display or save it

// Create a new device
WaGateway::createDevice('22799000001', 'https://yourapp.com/webhook');

// Get device information
$info = WaGateway::deviceInfo('22799749554');

// Disconnect a device
WaGateway::disconnectDevice('22799749554');

User Management (admin only)

// Create a user
WaGateway::createUser(
    username: 'newuser',
    password: 'secret123',
    email: 'newuser@example.com',
    expire: 30,
    limitDevice: 5
);

// Get user info
$user = WaGateway::userInfo('newuser');

Dependency Injection

use Elbrahms\WaGateway\WaGateway;

class NotificationService
{
    public function __construct(protected WaGateway $wa) {}

    public function notify(string $phone, string $text): void
    {
        $this->wa->sendMessage($phone, $text);
    }
}

Override Sender Per Call

Every method accepts an optional $sender parameter:

WaGateway::sendMessage('22799123456', 'Hello!', sender: '22788868500');

Error Handling

All methods throw Elbrahms\WaGateway\Exceptions\WaGatewayException on failure:

use Elbrahms\WaGateway\Exceptions\WaGatewayException;

try {
    WaGateway::sendMessage('22799123456', 'Hello!');
} catch (WaGatewayException $e) {
    logger()->error('WaGateway error: ' . $e->getMessage(), $e->getErrors());
}

Webhook Payload

When your device receives a message the gateway will POST to your webhook URL:

{
  "device": "22799749554",
  "message": "Hello!",
  "from": "22799123456",
  "name": "Contact Name",
  "participant": null,
  "ppUrl": "https://...",
  "media": null
}

License

The MIT License (MIT). See LICENSE.md.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固