codebuglab / letsbot-php
Lets Bot API的PHP库
v1
2023-08-06 19:11 UTC
Requires
- guzzlehttp/guzzle: ^7.0
README
此包可以提供您使用Let's Bot API所需的一切,根据Let's Bot API 文档
如果您正在使用Laravel,则应使用Composer安装它
composer require codebuglab/letsbot-php
安装后,您应发布配置文件以设置集成值
php artisan vendor:publish --tag=letsbot-config
配置文件位于 config/letsbot.php
return [
'api_key'=>env('LETS_BOT_API_KEY','test'),
'ssl_verify'=>true,
];
api_key
设置从仪表板生成的API密钥
ssl_verify
如果您在项目中使用该包进行开发,并且需要禁用SSL CERT PEM,则必须将其更改为 false
以跳过错误
如果您正在使用PHP本地或PHP OOP并且需要使用我们的包呢?
没问题,这很简单,只需设置您的集成数据即可
在此包中,我们提供了别名 LetsBot\Api\LetsBot::class
,您不需要做任何事情...
您只需在对象中使用 use LetsBot;
类即可
我们提供了一个嵌套在 LetsBot
类中的辅助函数 lb
示例:
require 'vendor/autoload.php';
$lb = (new \LetsBot\Api\LetsBot);
$lb::$api_key = 'test'; // set api key
$lb::$ssl_verify = false; // set ssl optional | true or false . default is true
// $lb = new LetsBot\Api\LetsBot;
$result = $lb->ChatList()->send();
echo json_encode($result);
用法
在此包中,我们提供了别名 LetsBot\Api\LetsBot::class
,您不需要做任何事情...
您只需在对象中使用 use LetsBot;
类即可
我们提供了一个嵌套在 LetsBot
类中的辅助函数 lb
示例:
return LetsBot::sessionStatus()->send();
// OR
return lb()->sessionStatus()->send();
以下是一系列可用的方法
消息
发送文本消息
LetsBot::message()->phone($phone)->body('Hi')->send();
- 或者
LetsBot::message()->send(['phone'=>$phone,'body'=>'Hi']);
发送贴纸消息
LetsBot::sticker()->send(['phone'=>$phone,'url'=>$url]);
- 或者
LetsBot::sticker()->phone($phone)->url($url)->send();
发送反应消息
LetsBot::react()->phone($phone)->reaction('❤️')->messageId('BAE5A8F8F8E0278E')->send();
- 或者
LetsBot::react()->send(['phone'=>$phone,'reaction'=>'❤️','messageId'=>'BAE5A8F8F8E0278E']);
发送回复消息
LetsBot::reply()->phone($phone)->body('replay msg')->messageId('BAE5A8F8F8E0278E')->send();
- 或者
LetsBot::reply()->send([
'phone'=>$phone,
'body'=>'replay msg',
'messageId'=>'BAE5A8F8F8E0278E'
]);
提到某人
LetsBot::mentions()->phone($phone)->mention($phone2)->send();
- 或者
LetsBot::mentions()->send(['phone'=>$phone2,'mention'=>$phone]);
发送消失消息
LetsBot::disappearing()->phone($phone)->duration(60)->body('This is a disappearing message')->send();
- 或者
LetsBot::disappearing()->send([
'phone'=>$phone,
'duration'=>60, //(Optional)Message disappear after duration time in seconds. Default (7 days)
'body'=>'This is a disappearing message that will disappear after X duration',
]);
发送目录消息
LetsBot::shareCatalog()->phone($phone)->catalog($phone2)
->title('This is title of catalog')
->description('This is description of catalog')
->body('This is body of catalog')->send();
- 或者
LetsBot::shareCatalog()->send([
'phone'=>$phone,
'catalog'=>$phone2,
'title'=>'This is title of catalog',
'description'=>'This is description of catalog',
'body'=>'This is body of catalog',
]);