go-cqhttp 机器人使用教程

devtools/2024/10/11 13:28:16/

API | go-cqhttp 帮助中心

参考 | go-cqhttp 帮助中心

机器人下载

发送消息

http://127.0.0.1:5700/send_msg?message_type=private&user_id=911412667&message=你好呀

检查端口是否打开

netstat -ano | findstr :5701

发送的请求

软件的dopost的解析

java">  @Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// 设置编码格式System.out.println("你好呀我获取了数据");request.setCharacterEncoding("UTF-8");
//        response.setContentType("text/json; charset=utf-8"); //设置编码格式和数据类型response.setHeader("Content-Type", "application/json;charset=UTF-8");// 获取请求体中的数据BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(),StandardCharsets.UTF_8)); //第一种方式
//        String requestBody = IOUtils.toString(request.getInputStream(), String.valueOf(StandardCharsets.UTF_8));//第二种方式
//        System.out.println("错误乱码检查:"+requestBody);String jsonStr = "";String line = null;while ((line = reader.readLine()) != null) {jsonStr += line;}System.out.println(jsonStr);//        // 解析JSON格式的数据
//        Gson gson = new Gson();
//        Message message = gson.fromJson(jsonStr, Message.class);
//
//        // 输出解析结果
//        System.out.println(message.getMessage());}

需要的jar包

commons的

java"><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.3</version>
</dependency>

json

java"><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.76</version>
</dependency>

通过WebSocket通信

java">package WebSocket.Server;import java.net.URI;
import javax.websocket.ClientEndpoint;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import org.glassfish.tyrus.client.ClientManager;@ClientEndpoint
public class WebsocketClient {public static void main(String[] args) throws Exception {String serverEndpoint = "ws://127.0.0.1:8081"; // 这里设置 Websocket 服务器的地址ClientManager client = ClientManager.createClient();WebsocketClient socket = new WebsocketClient();client.connectToServer(socket, new URI(serverEndpoint));// 等待接收服务器发来的消息while (true) {Thread.sleep(1000);}}@OnMessagepublic void onMessage(String message) {System.out.println("Received message from server: " + message);}@OnErrorpublic void onError(Throwable t) {t.printStackTrace(System.err);}
}

所有的jar包

<dependencies><dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf</artifactId><version>3.0.15.RELEASE</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.76</version></dependency><dependency><groupId>org.apache.maven.surefire</groupId><artifactId>surefire-booter</artifactId><version>2.22.2</version></dependency><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.3</version></dependency><dependency><groupId>javax.websocket</groupId><artifactId>javax.websocket-client-api</artifactId><version>1.1</version></dependency><dependency><groupId>org.glassfish.tyrus.bundles</groupId><artifactId>tyrus-standalone-client</artifactId><version>1.17</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>jul-to-slf4j</artifactId><version>1.7.36</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.20</version><scope>provided</scope></dependency></dependencies>


http://www.ppmy.cn/devtools/9456.html

相关文章

element UI 走马灯 initial-index动态赋值 不生效问题

图片列表点击展示大图&#xff0c;点开不是当前的图片 initial-index属性动态赋值不生效 解决方法&#xff1a; 1.设置initial-index初始值为null initialIndex:null2.设置走马灯轮播数组初始化为[] imgList:[]3.点击图片获取图片的索引&#xff0c;赋值给initialIndex&#x…

JetBrains相关的IDE有哪些?

JetBrains是一家成立于2002年的捷克软件开发公司&#xff0c;总部位于捷克的布拉格&#xff0c;同时在俄罗斯的圣彼得堡及美国麻州波士顿等地设有办公室。该公司以其高质量的集成开发环境&#xff08;IDE&#xff09;产品而闻名&#xff0c;这些产品被广泛应用于各种编程语言和…

【做一名健康的CSDNer】程序员哪几种行为最伤肾(程序员必看)

虽然没有专门针对程序员这一职业群体特有的伤肾行为的研究报道&#xff0c;但根据一般人群的健康风险和生活习惯&#xff0c;程序员由于其特殊的工作模式和环境&#xff0c;可能更容易出现如下伤肾的行为&#xff1a; 熬夜加班&#xff1a; 程序员由于项目进度、bug修复等原因&…

Spring Cloud Gateway详细介绍以及实现动态路由

一. 简介 Spring Cloud Gateway This project provides a libraries for building an API Gateway on top of Spring WebFlux or Spring WebMVC. Spring Cloud Gateway aims to provide a simple, yet effective way to route to APIs and provide cross cutting concerns to …

【python】直接在python3下安装 jupyter notebook,以及处理安装报错,启动不了问题

目录 问题&#xff1a; 1 先做准备&#xff0c;查看环境 1.1 先看python3 和pip &#xff0c;以及查看是否有 juypter 1.2 开始安装 1.3 安装完成后得到警告和报错 2 处理安装的报错问题 2.1 网上有说是因为 pip 自身需要更新&#xff0c;更新之 2.1.1 更新pip 2.1.…

MySQL运维故障解决方案:实战案例与深度解析

一、引言 MySQL数据库在企业应用中扮演着举足轻重的角色&#xff0c;但在运维过程中时常会遭遇各类故障。本文不仅梳理了常见的MySQL运维故障&#xff0c;还通过实战案例&#xff0c;展示了如何解决这些故障&#xff0c;确保数据库稳定运行。 二、常见故障及解决方案 1. 连接问…

20240418金融读报:银行参考汇丰全球化布局银行全球化布局现有路径再读金融助力新型工业化

1、银行全球化布局参考汇丰中国市场开拓思路&#xff08;时光机效应&#xff09;&#xff1a;&#xff08;1&#xff09;找对外开放的国家并利用我国现搭建的网络&#xff0c;比如一带一路沿线&#xff08;2&#xff09;找经济向好的国家&#xff08;3&#xff09;投资倾向于全…

高级IO和5种IO模型

目录 1. 高级IO1.1 IO的基本概念1.2 OS如何得知外设当中有数据可读取1.3 OS如何处理从网卡中读取到的数据包1.4 IO的步骤 2. 五种IO模型2.1 利用钓鱼来理解2.2 阻塞IO2.3 非阻塞IO2.4 信号驱动IO2.5 IO多路转接2.6 异步IO 3. 高级IO的概念3.1 同步通信 VS 异步通信3.2 阻塞 VS …