waapi/waapi-php-sdk

官方的 EAZE WhatsApp PHP SDK

v1.0.1 2023-09-06 16:01 UTC

This package is auto-updated.

Last update: 2024-09-23 13:58:02 UTC


README

Latest Version on Packagist Total Downloads

简介

PHP 包,可以轻松与 waapi.app 交互。

安装

Composer

composer require waapi/waapi-php-sdk

使用方法

初始设置

use WaAPI\WaAPISdk\WaAPISdk;

$apiToken = 'xxxxxxxxxxxxxxxxxxxxxx';
$sdk = new WaAPISdk($apiToken);

检查 WhatsApp API 是否可用

$isAvailable = $sdk->isApiAvailable();

创建一个新的实例

$instance = $sdk->createInstance();
$instanceId = $instance->id;

获取现有的实例

$instanceId = 10; //you need to know your instance id at this point
$instance = $sdk->getInstance($instanceId);

更新现有的实例

$instanceId = 10; //you need to know your instance id at this point

//if a subscribed event occurs, this url will be requested with the event data
//can also be null if you do not want to receive webhooks
$webhookUrl = '';
$subscribedEvents = ['', '']; //can also be null or an empty array

$sdk->updateInstance($instanceId, $webhookUrl, $subscribedEvents);

//if you have an instance object, you can also use the following method
$instance = $sdk->getInstance($instanceId);
$instance->update($webhookUrl, $subscribedEvents);

删除现有的实例

$instanceId = 10; //you need to know your instance id at this point
$sdk->deleteInstance($instanceId);

//if you have an instance object, you can also use the following method to delete this instance
$instance = $sdk->getInstance($instanceId);
$instance->delete();

获取 QR 码

创建新实例后,您需要将 WhatsApp 手机号码与该实例连接。以下代码可以接收当前的 QR 码。

$instanceId = 10; //you need to know your instance id at this point
$response = $sdk->getInstanceClientQrCode($instanceId);

//if you have an instance object, you can also use the following method to delete this instance
$instance = $sdk->getInstance($instanceId);
$response = $instance->clientQrCode();

// The QR code as a base64 image string (data:image/png;base64,…).
// Set this string in the src attribute of a <img src=““> html tag.
$qrCode = $response->qrCode;

获取实例状态

实例始终具有状态。

$instanceId = 10; //you need to know your instance id at this point
$response = $sdk->getInstanceClientStatus($instanceId);

//if you have an instance object, you can also use the following method to delete this instance
$instance = $sdk->getInstance($instanceId);
$response = $instance->clientStatus();

$instanceStatus = $response->instanceStatus;

获取现有实例的信息

$instanceId = 10; //you need to know your instance id at this point
$response = $sdk->getInstanceClientInfo($instanceId);

//if you have an instance object, you can also use the following method to delete this instance
$instance = $sdk->getInstance($instanceId);
$response = $instance->clientInfo();

//your public name of your WhatsApp profile (your name)
$displayName = $response->displayName;

//the connected WhatsApp phone number (your phone number)
$phoneNumber = $response->formattedNumber;

//profile image url of the connected WhatsApp phone number (your profile picture)
$profileUrl = $response->profilePicUrl;

//a unique identifier for your WhatsApp account / profile / phone number
$whatsAppId = $response->contactId;

许可

MIT 许可证 (MIT)。请参阅 许可文件 获取更多信息。