{"id":15567120,"url":"https://github.com/lz1998/spring-cq","last_synced_at":"2025-07-21T04:07:16.915Z","repository":{"id":57737402,"uuid":"208413402","full_name":"lz1998/Spring-CQ","owner":"lz1998","description":"新框架 https://github.com/ProtobufBot/ProtobufBot 。这是一个spring boot starter。基于SpringBoot的QQ机器人框架，demo分支是例子，jar分支是框架。","archived":false,"fork":false,"pushed_at":"2021-12-15T14:07:04.000Z","size":25908,"stargazers_count":187,"open_issues_count":2,"forks_count":43,"subscribers_count":9,"default_branch":"demo","last_synced_at":"2025-07-04T07:51:41.833Z","etag":null,"topics":["bot","coolq","coolq-http-api","cqhttp","java","qq","qqbot","qqrobot","spring-cq","springboot","websocket"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lz1998.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-14T08:45:34.000Z","updated_at":"2025-05-21T12:02:03.000Z","dependencies_parsed_at":"2022-08-24T10:52:20.789Z","dependency_job_id":null,"html_url":"https://github.com/lz1998/Spring-CQ","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/lz1998/Spring-CQ","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lz1998%2FSpring-CQ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lz1998%2FSpring-CQ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lz1998%2FSpring-CQ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lz1998%2FSpring-CQ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lz1998","download_url":"https://codeload.github.com/lz1998/Spring-CQ/tar.gz/refs/heads/demo","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lz1998%2FSpring-CQ/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266236869,"owners_count":23897273,"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":["bot","coolq","coolq-http-api","cqhttp","java","qq","qqbot","qqrobot","spring-cq","springboot","websocket"],"created_at":"2024-10-02T17:09:59.315Z","updated_at":"2025-07-21T04:07:16.896Z","avatar_url":"https://github.com/lz1998.png","language":"Java","readme":"# Spring-CQ\n[![maven](https://img.shields.io/maven-central/v/net.lz1998/spring-cq)](https://search.maven.org/artifact/net.lz1998/spring-cq)\n[![QQ群](https://img.shields.io/static/v1?label=QQ%E7%BE%A4\u0026message=335783090\u0026color=blue)](https://jq.qq.com/?_wv=1027\u0026k=5BKAROL)\n\n- 【推荐】新项目使用新框架 [pbbot-spring-boot-starter](https://github.com/ProtobufBot/pbbot-spring-boot-starter)。建议直接下载 [demo](https://github.com/ProtobufBot/Spring-Mirai-Server) 修改，配合 [Go-Mirai-Client](https://github.com/ProtobufBot/Go-Mirai-Client/releases) （相当于酷Q）运行。代码结构与 Spring-CQ 基本相同，可以参考下方文档。\n\n- 因为酷Q已停运，老项目请使用 [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) 等替代酷Q。\n\n- 基于 Spring-CQ-Client、SpringBoot、反向websocket 的 QQ 机器人框架\n\n- 这是一个自定义spring-boot-starter，项目名暂时不改了\n\n- 比起其他http框架，可以很方便地开多个QQ号，不需要额外配置cqhttp端口\n\n- 这个README主要讲了大概的使用方法，详细API和EVENT看下面两个链接\n\n- 详细API文档:https://github.com/lz1998/Spring-CQ/blob/demo/API.md\n\n- 详细Event文档：https://github.com/lz1998/Spring-CQ/blob/demo/Event.md\n\n- 新手推荐视频教程：https://www.bilibili.com/video/av89649630/  （版本更新：已删除Config，`CQGlobal.pluginList.add`改为在`resources/application.yml`中配置，其他相同）\n\n- Kotlin也可以用：https://github.com/lz1998/Spring-CQ-Kotlin-Demo\n\n- Groovy也可以用：https://github.com/lz1998/Spring-CQ-Groovy-Demo\n\n- demo分支是例子，jar分支是maven仓库的spring-cq\n\n## 开发环境\n- IntelliJ IDEA Ultimate(学生认证免费)\n- IntelliJ IDEA中的lombok插件，File-\u003eSettings-\u003ePlugins-\u003e搜索Lombok-\u003eInstall-\u003e重启IDEA\n- JDK IDEA自动安装，不需要自己装\n- MAVEN IDEA自动安装，不需要自己装\n\n## 导入maven依赖\n```xml\n    \u003cdependency\u003e\n        \u003cgroupId\u003enet.lz1998\u003c/groupId\u003e\n        \u003cartifactId\u003espring-cq\u003c/artifactId\u003e\n        \u003cversion\u003e4.14.1.1\u003c/version\u003e\n    \u003c/dependency\u003e\n```\n\n推荐SpringBoot 2.1.8  \n为了避免一些问题，可以直接下载demo修改\n\n## 编写插件\n\n1. 编写XXXPlugin，继承CQPlugin  \n    ```java\n   /**\n    * 示例插件\n    * 插件必须继承CQPlugin，上面要 @Component\n    *\n    * 添加事件：光标移动到类中，按 Ctrl+O 添加事件(讨论组消息、加群请求、加好友请求等)\n    * 查看API参数类型：光标移动到方法括号中按Ctrl+P\n    * 查看API说明：光标移动到方法括号中按Ctrl+Q\n    */\n   @Component\n   public class DemoPlugin extends CQPlugin {\n       /**\n        * 收到私聊消息时会调用这个方法\n        *\n        * @param cq    机器人对象，用于调用API，例如发送私聊消息 sendPrivateMsg\n        * @param event 事件对象，用于获取消息内容、群号、发送者QQ等\n        * @return 是否继续调用下一个插件，IGNORE表示继续，BLOCK表示不继续\n        */\n       @Override\n       public int onPrivateMessage(CoolQ cq, CQPrivateMessageEvent event) {\n           // 获取 发送者QQ 和 消息内容\n           long userId = event.getUserId();\n           String msg = event.getMessage();\n   \n           if (msg.equals(\"hi\")) {\n               // 调用API发送hello\n               cq.sendPrivateMsg(userId, \"hello\", false);\n   \n               // 不执行下一个插件\n               return MESSAGE_BLOCK;\n           }\n           // 继续执行下一个插件\n           return MESSAGE_IGNORE;\n       }\n   \n   \n       /**\n        * 收到群消息时会调用这个方法\n        *\n        * @param cq    机器人对象，用于调用API，例如发送群消息 sendGroupMsg\n        * @param event 事件对象，用于获取消息内容、群号、发送者QQ等\n        * @return 是否继续调用下一个插件，IGNORE表示继续，BLOCK表示不继续\n        */\n       @Override\n       public int onGroupMessage(CoolQ cq, CQGroupMessageEvent event) {\n           // 获取 消息内容 群号 发送者QQ\n           String msg = event.getMessage();\n           long groupId = event.getGroupId();\n           long userId = event.getUserId();\n   \n           if (msg.equals(\"hello\")) {\n               // 回复内容为 at发送者 + hi\n               String result = CQCode.at(userId) + \"hi\";\n   \n               // 调用API发送消息\n               cq.sendGroupMsg(groupId, result, false);\n   \n               // 不执行下一个插件\n               return MESSAGE_BLOCK;\n           }\n   \n           // 继续执行下一个插件\n           return MESSAGE_IGNORE;\n       }\n   }\n    ```\n\n2. 配置resources/application.yml\n    ```yml\n    server:\n      port: 8081 # 下面的cqhttp都是8081端口，可以自己改\n    \n    spring:\n      cq:\n        # 在这里配置各个功能执行顺序\n        # 如果前一个功能返回MESSAGE_BLOCK，下一个功能不会被执行\n        # 如果前一个功能返回MESSAGE_IGNORE，会继续执行下一个功能\n        plugin-list:\n          - com.example.demo.plugin.DemoPlugin\n          - com.example.demo.plugin.TestPlugin\n          - com.example.demo.plugin.HelloPlugin\n    ```\n\n\n\n    \n## 测试应用\n1. 运行SpringCqApplication的main方法\n\n## 打包应用\n1. 使用maven打包应用\n    ```bash\n    mvn clean package\n    ```\n2. 在target目录下，spring-cq-0.0.1-SNAPSHOT.jar即为打包的jar\n\n## 运行应用\n1. 输入指令\n    ```bash\n    java -jar spring-cq-0.0.1-SNAPSHOT.jar\n    ```\n如果是Windows，并且不需要查看运行情况，可以直接双击jar文件运行，右下角托盘会出现小图标\n\n## Windows运行酷Q和cqhttp\n1. 准备酷Q Air\n    - 方案一：下载已经配置好cqhttp的[酷Q Air](http://cq.lz1998.xin/CQA.zip)\n    - 方案二：自己配置\n        1. 下载[酷Q Air](https://cqp.cc/t/23253)\n        2. 下载[CQHTTP插件](https://github.com/richardchien/coolq-http-api/releases)\n        3. 创建文件`酷Q Air\\data\\app\\io.github.richardchien.coolqhttpapi\\config.ini`\n            ```ini\n            [general]\n            use_http=false\n            use_ws_reverse=true\n            ws_reverse_url=ws://127.0.0.1:8081/ws/cq/\n            ws_reverse_use_universal_client=true\n            enable_heartbeat=true\n            heartbeat_interval=60000\n            ```\n2. 解压后运行 CQA.exe 登录QQ账号 \n\n如果需要[酷Q Pro](http://dlsec.cqp.me/cqp-tuling)，下载解压后替换exe文件，其他不需要动\n\n\n\n\n## Docker运行酷Q和cqhttp\n1. 安装酷Q和CQHTTP插件\n    ```shell\n    docker run -d --name cq01 \\\n    -v $(pwd)/coolq:/home/user/coolq \\\n    -p 9000:9000 \\\n    -e VNC_PASSWD=你的VNC密码(不超过8位) \\\n    -e COOLQ_URL=http://dlsec.cqp.me/cqa-tuling \\\n    -e COOLQ_ACCOUNT=你的机器人QQ号 \\\n    -e CQHTTP_USE_HTTP=false \\\n    -e CQHTTP_USE_WS_REVERSE=true \\\n    -e CQHTTP_WS_REVERSE_URL=ws://宿主机地址:8081/ws/cq/ \\\n    -e CQHTTP_WS_REVERSE_USE_UNIVERSAL_CLIENT=true \\\n    -e CQHTTP_ENABLE_HEARTBEAT=true \\\n    -e CQHTTP_HEARTBEAT_INTERVAL=60000 \\\n    richardchien/cqhttp\n    ```\n    如果不知道宿主机地址是什么，可以使用Docker的host模式，共享主机网络\n    ```bash\n    docker run -d --name cq01 \\\n    -v $(pwd)/coolq:/home/user/coolq \\\n    --net=host \\\n    -e VNC_PASSWD=你的VNC密码(不超过8位) \\\n    -e COOLQ_URL=http://dlsec.cqp.me/cqa-tuling \\\n    -e COOLQ_ACCOUNT=你的机器人QQ号 \\\n    -e CQHTTP_USE_HTTP=false \\\n    -e CQHTTP_USE_WS_REVERSE=true \\\n    -e CQHTTP_WS_REVERSE_URL=ws://127.0.0.1:8081/ws/cq/ \\\n    -e CQHTTP_WS_REVERSE_USE_UNIVERSAL_CLIENT=true \\\n    -e CQHTTP_ENABLE_HEARTBEAT=true \\\n    -e CQHTTP_HEARTBEAT_INTERVAL=60000 \\\n    richardchien/cqhttp\n    ```\n2. 访问 http://127.0.0.1:9000 登录QQ账号\n\n如果需要酷Q Pro，把`http://dlsec.cqp.me/cqa-tuling`改为`http://dlsec.cqp.me/cqp-tuling`\n\n## 截图\n    \n\u003cimg src=\"http://cq.lz1998.xin/screenshot_private.png\" width=\"40%\"/\u003e \u003cimg src=\"http://cq.lz1998.xin/screenshot_group.png\"  width=\"40%\"/\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flz1998%2Fspring-cq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flz1998%2Fspring-cq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flz1998%2Fspring-cq/lists"}