michalwolinski / wbiztool-php
访问WbizTool API的PHP客户端库
v1.1.1
2019-12-12 20:43 UTC
Requires
- php: ^7.4
- ext-json: *
- guzzlehttp/guzzle: ^7.0
- nesbot/carbon: ^2.0@dev
Requires (Dev)
- mockery/mockery: ^1.2
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-09-19 22:26:25 UTC
README
访问WbizTool API的PHP客户端库
通过Composer安装
在控制台中运行
composer require michalwolinski/wbiztool-php
以安装此库。
用法
首先,您需要初始化凭证和客户端对象。
加载库并设置凭证
$credentials = new Credentials(
[clientId], [apiKey], [whatsappClientId]
);
$client = new Client(new \GuzzleHttp\Client(), $credentials);
消息类型
您可以选择以下几种消息类型之一。
文本
文本消息作为参数
$type = new Text('message content');
图片URL
带有图片的文本消息
- 消息
- 图片URL
$type = ImageUrl('Testing text message', 'https://example.com/image.jpg');
文件URL
带有文件的文本消息
- 消息
- 文件URL
- 文件名
$type = FileUrl('Testing text message', 'https://example.com/Documents.zip', 'Documents.zip');
方法
发送消息
此方法直接发送消息。
参数
- SendMessage对象
- 接收者对象(电话号码作为参数)
- MessageType对象
$response = $client->push(
new SendMessage(),
new Receiver('123456789'),
$type
);
计划消息
此方法计划发送消息。
参数
- ScheduleMessage对象(Carbon对象,包含计划日期和时间,时区)
- 接收者对象(电话号码作为参数)
- MessageType对象
$response = $client->push(
new ScheduleMessage(Carbon::tomorrow(), 'UTC'),
new Receiver('123456789'),
$type
);
取消消息
此方法取消挂起消息。
参数
- CancelMessage对象(messageId)
$response = $client->push(
new CancelMessage(12345)
);
响应对象
每个方法都返回响应对象,该对象包含
- 状态(bool)
- 消息(string)
- 消息ID(int)
您可以使用getter或toArray()方法
["status"]=> bool(true)
["message"]=> string(9) "Cancelled"
["messageId"]=> int(123)
作者
- Michal Wolinski - Haxmedia
许可协议
本项目采用MIT许可证。