eagleminds/whatsapp-sender

通过API发送WhatsApp消息的基本包

dev-master 2024-05-17 15:53 UTC

This package is not auto-updated.

Last update: 2024-09-20 17:47:18 UTC


README

PHP WhatsApp消息发送器API库

使用WhatsApp-Sender发送WhatsApp消息(点击访问)。此库提供了一种简单高效的方式,通过PHP编程发送WhatsApp消息。它旨在与Laravel无缝集成,并可以通过Composer轻松集成到项目中。

功能

  • 发送消息:通过WhatsApp发送文本、图片、视频、文档和其他媒体。
  • Laravel集成:专为Laravel开发者构建,实现平滑集成。
  • Composer支持:使用Composer轻松安装和管理依赖项。

安装

您可以通过Composer安装此库。在您的终端中运行以下命令

composer require eagleminds/whatsapp-sender

用法

初始化库

首先,您需要使用您的凭证初始化WhatsApp消息发送器

use Eagleminds\WhatsappSender\WhatsAppSender;

发送消息

然后,您可以使用sendMessage方法向WhatsApp收件人发送消息

 public function sendMessage(Request $request)
    {
        // Get mobile number and message from request
        $mobileNumber = $request->input('mobile_number');
        $message = $request->input('message');

        // Send WhatsApp message
        try {
            $response = $this->whatsappSender->sendWhatsAppMessage($mobileNumber, $message);
            return response()->json(['success' => true, 'message' => 'WhatsApp message sent successfully', 'response' => $response]);
        } catch (\Exception $e) {
            return response()->json(['success' => false, 'message' => 'Failed to send WhatsApp message', 'error' => $e->getMessage()], 500);
        }
    }

发送媒体

要发送媒体(如图片、视频或文档),请使用sendMediaMessage方法

$mediaUrl = 'https://example.com/image.jpg';
$caption = 'Check out this image!';
$response = $sender->sendMediaMessage($recipient, $mediaUrl, $caption);

WhatsApp发送器平台文档

此存储库包含与Track New提供的WhatsApp发送器平台集成的文档。此平台允许您使用API编程方式发送WhatsApp消息。以下是注册、登录以及获取集成所需的必要密钥和模板ID的步骤。

注册和登录

要使用WhatsApp发送器平台,您需要在WhatsApp-Sender网站上注册。

注册步骤

  • 访问WhatsApp-Sender网站。
  • 单击“注册”或“注册”按钮。
  • 填写注册表单,包括电子邮件地址和密码等详细信息。
  • 提交表单以创建您的账户。

登录

  • 转到WhatsApp-Senderr网站。
  • 单击“登录”按钮。
  • 输入您的注册电子邮件地址和密码。
  • 单击“登录”以访问您的账户仪表板。

获取API密钥和模板ID

登录后,您需要获取集成WhatsApp发送器平台所需的必要API密钥(app_key)、认证密钥(auth_key)和模板ID。

获取API密钥(app_key)和认证密钥(auth_key)

  • 登录后,导航到您的账户设置或仪表板。
  • 查找类似“我的应用”的选项,然后点击应用“集成设置”。

app_key

  • 获取认证密钥(auth_key),点击Auth key菜单并显示Auth key。 auth_key
  • 记下这些密钥,因为它们将用于API认证。

获取模板ID

  • 在您的账户仪表板中,找到与消息模板或模板管理相关的部分。 template_create
  • 如有需要,请创建一个新的模板,或选择现有的模板。 template_id
  • 记下您想要用于发送消息的模板的模板ID。

示例

以下是一些示例,以帮助您开始。

发送文本消息

$response = $sender->sendMessage('whatsapp_number', 'Hello, World!');

发送图片

$mediaUrl = 'https://example.com/image.jpg';
$caption = 'Check out this image!';
$response = $sender->sendMediaMessage('whatsapp_number', $mediaUrl, $caption);

要求

  • PHP 7.0 或更高版本
  • Laravel 5.5 或更高版本(如果使用Laravel)

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件