{"id":15068528,"url":"https://github.com/botuniverse/php-libonebot","last_synced_at":"2025-04-10T17:41:25.170Z","repository":{"id":38036851,"uuid":"402699879","full_name":"botuniverse/php-libonebot","owner":"botuniverse","description":"PHP 的 LibOneBot 库，助力 Onebot 多平台适配","archived":false,"fork":false,"pushed_at":"2025-03-10T07:44:59.000Z","size":618,"stargazers_count":16,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-20T08:47:39.295Z","etag":null,"topics":["libonebot","onebot","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/botuniverse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-03T08:28:54.000Z","updated_at":"2025-03-10T07:43:37.000Z","dependencies_parsed_at":"2024-10-13T04:40:54.886Z","dependency_job_id":"22487542-a5c5-45c8-9627-5b985e57b6d2","html_url":"https://github.com/botuniverse/php-libonebot","commit_stats":{"total_commits":280,"total_committers":6,"mean_commits":"46.666666666666664","dds":"0.43214285714285716","last_synced_commit":"22e4a71e653efda5305733b5ccb64e16bb17d9d6"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/botuniverse%2Fphp-libonebot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/botuniverse%2Fphp-libonebot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/botuniverse%2Fphp-libonebot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/botuniverse%2Fphp-libonebot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/botuniverse","download_url":"https://codeload.github.com/botuniverse/php-libonebot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248262185,"owners_count":21074258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libonebot","onebot","php"],"created_at":"2024-09-25T01:37:58.586Z","updated_at":"2025-04-10T17:41:25.153Z","avatar_url":"https://github.com/botuniverse.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--suppress HtmlDeprecatedAttribute --\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/botuniverse/php-libonebot/releases\"\u003e\n    \u003cimg alt=\"Version\" src=\"https://img.shields.io/github/v/release/botuniverse/php-libonebot?include_prereleases\u0026logo=github\u0026style=flat-square\" /\u003e\n  \u003c/a\u003e\n  \u003cimg alt=\"GitHub Workflow Status\" src=\"https://img.shields.io/github/workflow/status/botuniverse/php-libonebot/Test?logo=github\u0026style=flat-square\" /\u003e\n  \u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/botuniverse/php-libonebot?style=flat-square\u0026logo=open%20source%20initiative\u0026logoColor=white\" /\u003e\n  \u003cimg alt=\"Packagist PHP Version Support\" src=\"https://img.shields.io/packagist/php-v/onebot/libonebot?color=777bb3\u0026logo=php\u0026logoColor=white\u0026style=flat-square\" /\u003e\n\u003c/p\u003e\n\n# php-libonebot\n\nPHP 的 LibOneBot 库。LibOneBot 可以帮助 OneBot 实现者快速在新的聊天机器人平台实现 OneBot v12 接口标准。\n\n基于 LibOneBot 实现 OneBot 时，OneBot 实现者只需专注于编写与聊天机器人平台对接的逻辑，包括通过长轮询或 webhook 方式从机器人平台获得事件，并将其转换为 OneBot 事件，以及处理 OneBot\n动作请求，并将其转换为对机器人平台 API 的调用。\n\n此外，内部的通信方式有相应的抽象方法，你可以在 libob 的基础上开发或整合其他 Web 框架。\n\n**当前版本还在开发中，在发布正式版之前此库内的接口可能会发生较大变动。**\n\n开发进度见 [更新日志](/docs/update.md)。\n\n## 使用\n\n```shell\ncomposer require onebot/libonebot\n```\n\n## 尝试 Demo\n\n在 require 下载 libob 库后，新建文件 `demo.php` 和 `demo.json`，并在 `demo.php` 中写如下代码：\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nrequire_once 'vendor/autoload.php';\n\n$ob = new \\OneBot\\V12\\OneBot('repl', 'qq', 'REPL-1');\n$ob-\u003esetLogger(new \\OneBot\\Logger\\Console\\ConsoleLogger());\n$ob-\u003esetDriver(\n    // 此处也可以在 Linux 系统下安装 swoole 扩展后使用 SwooleDriver() 拥有协程能力\n    new \\OneBot\\Driver\\Workerman\\WorkermanDriver(), \n    new \\OneBot\\Config\\Repository('demo.json')\n);\n$ob-\u003esetActionHandlerClass(\\OneBot\\V12\\Action\\ReplAction::class);\n$ob-\u003erun();\n```\n\n在 `demo.json` 中写如下代码：\n\n```json\n{\n    \"lib\": {\n        \"db\": false\n    },\n    \"communications\": {\n        \"http\": {\n            \"enable\": true,\n            \"host\": \"0.0.0.0\",\n            \"port\": 9600,\n            \"event_enabled\": true,\n            \"event_buffer_size\": 0\n        }\n    }\n}\n```\n\n此 Demo 以一个命令行交互的方式使用 LibOneBot 快速完成了一个 OneBot 实现，命令行中输入内容即可发送到 OneBot，使用 HTTP 或 WebSocket 发送给 LibOneBot 后可以将信息显示在终端内。\n\n```bash\n# 运行 OneBot 实现\nphp demo.php\n```\n\n启动后可以利用 Postman 或 Curl 等工具发起请求，以 OneVot V12 协议的[发送消息动作](https://12.onebot.dev/interface/action/message/)为例：\n\n```shell\ncurl --location --request POST 'http://localhost:9600/' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n    \"action\": \"send_message\",\n    \"params\": {\n        \"detail_type\": \"group\",\n        \"group_id\": \"12467\",\n        \"message\": [\n            {\n                \"type\": \"text\",\n                \"data\": {\n                    \"text\": \"我是文字巴拉巴拉巴拉\"\n                }\n            }\n        ]\n    }\n}'\n```\n\n你应该可以看到 OneBot 命令行中出现以下消息：\n\n```shell\n[2021-11-18 18:44:39] [INFO] 我是文字巴拉巴拉巴拉\n```\n\n并收到以下响应：\n\n```text\n{\"status\":\"ok\",\"retcode\":0,\"data\":{\"message_id\":5007842},\"message\":\"\"}%\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbotuniverse%2Fphp-libonebot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbotuniverse%2Fphp-libonebot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbotuniverse%2Fphp-libonebot/lists"}