承接 aghfatehi/laravel-whatsapp-api 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

aghfatehi/laravel-whatsapp-api

Composer 安装命令:

composer require aghfatehi/laravel-whatsapp-api

包简介

Meta WhatsApp Cloud API integration for Laravel 9-13. Supports all API services: messaging, media, templates, phone numbers, business profile, webhooks, QR codes, and conversations.

README 文档

README

Packagist Version Total Downloads PHP Version Laravel License Tests

Meta WhatsApp Cloud API integration for Laravel 9–13.
Supports all API services: messaging, media, templates, phone numbers, business profile, webhooks, QR codes, two-step verification, and conversations.

Installation

composer require aghfatehi/laravel-whatsapp-api
php artisan vendor:publish --tag=whatsapp-config

Configuration

Add to your .env:

WHATSAPP_API_TOKEN=
WHATSAPP_PHONE_NUMBER_ID=
WHATSAPP_WABA_ID=
WHATSAPP_APP_SECRET=
WHATSAPP_VERIFY_TOKEN=

Quick Start

use Aghfatehi\WhatsApp\Facades\WhatsApp;

// Send a text message
WhatsApp::messages()->sendText('966555555555', 'Hello!');

// Send a media message (image, document, audio, video)
WhatsApp::messages()->sendMedia('966555555555', 'image', 'https://example.com/photo.jpg', 'Caption');

// Send a template message
WhatsApp::messages()->sendTemplate('966555555555', 'hello_world', 'en');

// Send a location
WhatsApp::messages()->sendLocation('966555555555', 24.7136, 46.6753, 'Riyadh', 'Saudi Arabia');

// Send an interactive (button/list)
WhatsApp::messages()->sendInteractive('966555555555', [
    'type' => 'button',
    'body' => ['text' => 'Choose:'],
    'action' => [
        'buttons' => [
            ['type' => 'reply', 'reply' => ['id' => '1', 'title' => 'Yes']],
            ['type' => 'reply', 'reply' => ['id' => '2', 'title' => 'No']],
        ],
    ],
]);

// Send reaction
WhatsApp::messages()->sendReaction('966555555555', 'wamid.xxx', '👍');

// Mark message as read
WhatsApp::messages()->markAsRead('wamid.xxx');

All Services

Messages

WhatsApp::messages()->sendText($to, $body, $previewUrl);
WhatsApp::messages()->sendMedia($to, $type, $url, $caption, $filename);
WhatsApp::messages()->sendMediaById($to, $type, $mediaId, $caption, $filename);
WhatsApp::messages()->sendTemplate($to, $name, $lang, $components);
WhatsApp::messages()->sendInteractive($to, $data);
WhatsApp::messages()->sendLocation($to, $lat, $lng, $name, $address);
WhatsApp::messages()->sendContacts($to, $contacts);
WhatsApp::messages()->sendReaction($to, $messageId, $emoji);
WhatsApp::messages()->markAsRead($messageId);

Media

WhatsApp::media()->upload($filePath, $type);     // Upload to WhatsApp servers
WhatsApp::media()->getUrl($mediaId);               // Get download URL
WhatsApp::media()->download($mediaId);             // Download raw content
WhatsApp::media()->delete($mediaId);               // Delete from WhatsApp

Phone Numbers

WhatsApp::phoneNumbers()->list();                  // All phone numbers
WhatsApp::phoneNumbers()->get($phoneNumberId);      // Single number details
WhatsApp::phoneNumbers()->requestPin($phoneNumberId);
WhatsApp::phoneNumbers()->verifyPin($phoneNumberId, $pin);
WhatsApp::phoneNumbers()->deregister($phoneNumberId);

Business Profile

WhatsApp::businessProfile()->get($phoneNumberId);
WhatsApp::businessProfile()->update($phoneNumberId, $data);

Templates

WhatsApp::templates()->list($status, $limit);
WhatsApp::templates()->get($templateId);
WhatsApp::templates()->create($data);
WhatsApp::templates()->update($templateId, $data);
WhatsApp::templates()->delete($templateId);

QR Codes

WhatsApp::qrCodes()->create($prefilledMessage);
WhatsApp::qrCodes()->list();
WhatsApp::qrCodes()->get($qrCodeId);
WhatsApp::qrCodes()->update($qrCodeId, $data);
WhatsApp::qrCodes()->delete($qrCodeId);

Two-Step Verification

WhatsApp::twoStepVerification()->setPin($phoneNumberId, $pin);
WhatsApp::twoStepVerification()->deletePin($phoneNumberId);

Conversations

WhatsApp::conversations()->list($phoneNumberId, $filters);
WhatsApp::conversations()->getAnalytics($phoneNumberId, $dimensions);
WhatsApp::conversations()->getPricing($phoneNumberId);

Webhook

WhatsApp::webhook()->verifyToken($mode, $token, $challenge);
WhatsApp::webhook()->verifySignature($body, $signature);
WhatsApp::webhook()->parsePayload($payload);
WhatsApp::webhook()->handle($payload);

The package auto-registers these routes:

  • GET /api/whatsapp/webhook — webhook verification
  • POST /api/whatsapp/webhook — incoming messages + status updates

Multi-Connection

WhatsApp::connection('default')->messages()->sendText(...);
WhatsApp::connection('secondary')->messages()->sendText(...);

Define connections in config/whatsapp.php:

'connections' => [
    'default' => [
        'api_token' => env('WHATSAPP_API_TOKEN'),
        'phone_number_id' => env('WHATSAPP_PHONE_NUMBER_ID'),
        'waba_id' => env('WHATSAPP_WABA_ID'),
    ],
    'secondary' => [
        'api_token' => env('WHATSAPP_API_TOKEN_2'),
        'phone_number_id' => env('WHATSAPP_PHONE_NUMBER_ID_2'),
        'waba_id' => env('WHATSAPP_WABA_ID_2'),
    ],
],

Artisan Commands

php artisan whatsapp:setup              # Validate configuration
php artisan whatsapp:phone-numbers      # List connected phone numbers
php artisan whatsapp:register-webhook   # Register webhook URL

Database Support

The package is database-agnostic — it does not ship migrations.
You can store WhatsApp data in any database:

  • MySQL / MariaDB — default, no changes needed
  • PostgreSQL — no changes needed
  • SQLite — no changes needed
  • MongoDB — add mongodb/laravel-mongodb package

Testing

composer test
# or
vendor/bin/phpunit

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固