定制 patelg10/green-api-laravel 二次开发

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

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

patelg10/green-api-laravel

最新稳定版本:v1.0.1

Composer 安装命令:

composer require patelg10/green-api-laravel

包简介

A clean Laravel wrapper for the Green API WhatsApp service.

README 文档

README

Latest Version on Packagist Total Downloads License

A professional, expressive Laravel wrapper for the Green API. This package provides a seamless way to integrate WhatsApp messaging into your Laravel applications using clean OOP principles, Facades, and an event-driven webhook system.

🚀 Features

  • Quick Setup – Automatic package discovery and configuration publishing.
  • Fluent API – Simple GreenApi facade for sending text and media.
  • Webhook Ready – Built-in endpoint and event dispatcher for incoming messages.
  • Developer Friendly – Full IDE auto-completion support via DocBlocks.
  • Clean Architecture – Follows Laravel best practices.

📦 Installation

Install the package via Composer:

composer require patelg10/green-api-laravel

Publish the configuration file:

php artisan vendor:publish --tag="greenapi-config"

⚙️ Configuration

Add your Green API credentials to your .env file. You can find these in your Green API console.

GREEN_API_ID_INSTANCE=your_id_instance_here
GREEN_API_TOKEN_INSTANCE=your_api_token_here
GREEN_API_HOST=https://api.green-api.com

🛠 Usage

Sending a Text Message

The package uses a Facade to make sending messages simple:

use YourName\GreenApi\Facades\GreenApi;

// Send message to a phone number (e.g., 1234567890@c.us)
GreenApi::sendMessage(
    '1234567890@c.us',
    'Hello! This is a test message from Laravel.'
);

Sending a File (via URL)

Send documents, images, or videos by providing a public URL:

use YourName\GreenApi\Facades\GreenApi;

GreenApi::sendFileByUrl(
    '1234567890@c.us',
    'https://example.com/invoice.pdf',
    'invoice.pdf',
    'Please find your invoice attached.'
);

🔔 Handling Webhooks (Incoming Messages)

This package automatically registers a POST route at:

/greenapi/webhook

This endpoint listens for events from Green API and dispatches a Laravel Event.

Step 1: Create a Listener

Generate a listener in your application:

php artisan make:listener HandleWhatsAppWebhook

Step 2: Register the Listener

In your App\Providers\EventServiceProvider.php:

use YourName\GreenApi\Events\WebhookReceived;
use App\Listeners\HandleWhatsAppWebhook;

protected $listen = [
    WebhookReceived::class => [
        HandleWhatsAppWebhook::class,
    ],
];

Step 3: Implement the Logic

In HandleWhatsAppWebhook.php:

namespace App\Listeners;

use YourName\GreenApi\Events\WebhookReceived;

class HandleWhatsAppWebhook
{
    public function handle(WebhookReceived $event)
    {
        $payload = $event->payload;

        // Check if the webhook is an incoming message
        if ($payload['typeWebhook'] === 'incomingMessageReceived') {
            $sender = $payload['senderData']['sender'];
            $message = $payload['messageData']['textMessageData']['textMessage'] ?? '';

            // Your business logic here (Save to DB, reply, etc.)
            \Log::info("New WhatsApp from {$sender}: {$message}");
        }
    }
}

🧪 Testing

If you are contributing to the package, you can run tests using:

composer test

🛡 Security

If you discover any security-related issues, please email, Instead of using the issue tracker.

patelg10@gmail.com

📄 License

This package is open-sourced software licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固