1. Go to this page and download the library: Download itwmw/go-cq-http-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
itwmw / go-cq-http-sdk example snippets
$api = new Itwmw\GoCqHttp\Api();
// 发送私聊消息
$api->message->sendMsg('测试消息', 'private', 995645888);
use Itwmw\GoCqHttp\Data\Post\BasePostMessage;
class MessageHandle
{
public function __invoke(BasePostMessage $message, \Closure $next)
{
// 处理消息
return $next($message);
}
}
$server->addHandler(MessageHandle::class);
use Itwmw\GoCqHttp\Data\Struct\Enum\PostMessageType;
use Itwmw\GoCqHttp\Data\Post\Message\PrivateMessage;
$server->addMessageListener(PostMessageType::PRIVATE, function (PrivateMessage $message, \Closure $next) {
// 处理消息
return $next($message);
});
use Itwmw\GoCqHttp\Data\Struct\Enum\PostNoticeType;
use Itwmw\GoCqHttp\Data\Post\Notice\GroupIncreaseNotice;
$server->addNoticeListener(PostNoticeType::GROUP_INCREASE, function (GroupIncreaseNotice $message, Closure $next) {
// 处理群成员增加
return $next($message);
});
use Itwmw\GoCqHttp\Data\Post\Message\PrivateMessage;
$server->addMessageListener(PostMessageType::PRIVATE, function (PrivateMessage $message, \Closure $next) {
if ('再见' === $message->message) {
return $message->response('bye~');
}
return $next($message);
});
$api->bot;
$api->friend;
$api->message;
$api->image;
$api->record;
$api->request;
$api->groupInfo;
$api->groupSetting;
$api->groupAction;
$api->groupFile;
$api->cq;
use Itwmw\GoCqHttp\Api;
use Itwmw\GoCqHttp\CqCode\Tts;
$api = new Api();
$tts = new Tts('你好');
$api->message->sendMsg($tts, user_id: 995645888);