• go-cqhttp 机器人使用教程


    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的解析

    1. @Override
    2. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    3. // 设置编码格式
    4. System.out.println("你好呀我获取了数据");
    5. request.setCharacterEncoding("UTF-8");
    6. // response.setContentType("text/json; charset=utf-8"); //设置编码格式和数据类型
    7. response.setHeader("Content-Type", "application/json;charset=UTF-8");
    8. // 获取请求体中的数据
    9. BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(),StandardCharsets.UTF_8)); //第一种方式
    10. // String requestBody = IOUtils.toString(request.getInputStream(), String.valueOf(StandardCharsets.UTF_8));//第二种方式
    11. // System.out.println("错误乱码检查:"+requestBody);
    12. String jsonStr = "";
    13. String line = null;
    14. while ((line = reader.readLine()) != null) {
    15. jsonStr += line;
    16. }
    17. System.out.println(jsonStr);
    18. // // 解析JSON格式的数据
    19. // Gson gson = new Gson();
    20. // Message message = gson.fromJson(jsonStr, Message.class);
    21. //
    22. // // 输出解析结果
    23. // System.out.println(message.getMessage());
    24. }

    需要的jar包

    commons的

    1. commons-fileupload
    2. commons-fileupload
    3. 1.3.3

    json

    1. com.alibaba
    2. fastjson
    3. 1.2.76

    通过WebSocket通信

    1. package WebSocket.Server;
    2. import java.net.URI;
    3. import javax.websocket.ClientEndpoint;
    4. import javax.websocket.OnError;
    5. import javax.websocket.OnMessage;
    6. import org.glassfish.tyrus.client.ClientManager;
    7. @ClientEndpoint
    8. public class WebsocketClient {
    9. public static void main(String[] args) throws Exception {
    10. String serverEndpoint = "ws://127.0.0.1:8081"; // 这里设置 Websocket 服务器的地址
    11. ClientManager client = ClientManager.createClient();
    12. WebsocketClient socket = new WebsocketClient();
    13. client.connectToServer(socket, new URI(serverEndpoint));
    14. // 等待接收服务器发来的消息
    15. while (true) {
    16. Thread.sleep(1000);
    17. }
    18. }
    19. @OnMessage
    20. public void onMessage(String message) {
    21. System.out.println("Received message from server: " + message);
    22. }
    23. @OnError
    24. public void onError(Throwable t) {
    25. t.printStackTrace(System.err);
    26. }
    27. }

    所有的jar包

    1. <dependencies>
    2. <dependency>
    3. <groupId>org.thymeleafgroupId>
    4. <artifactId>thymeleafartifactId>
    5. <version>3.0.15.RELEASEversion>
    6. dependency>
    7. <dependency>
    8. <groupId>com.alibabagroupId>
    9. <artifactId>fastjsonartifactId>
    10. <version>1.2.76version>
    11. dependency>
    12. <dependency>
    13. <groupId>org.apache.maven.surefiregroupId>
    14. <artifactId>surefire-booterartifactId>
    15. <version>2.22.2version>
    16. dependency>
    17. <dependency>
    18. <groupId>commons-fileuploadgroupId>
    19. <artifactId>commons-fileuploadartifactId>
    20. <version>1.3.3version>
    21. dependency>
    22. <dependency>
    23. <groupId>javax.websocketgroupId>
    24. <artifactId>javax.websocket-client-apiartifactId>
    25. <version>1.1version>
    26. dependency>
    27. <dependency>
    28. <groupId>org.glassfish.tyrus.bundlesgroupId>
    29. <artifactId>tyrus-standalone-clientartifactId>
    30. <version>1.17version>
    31. dependency>
    32. <dependency>
    33. <groupId>org.slf4jgroupId>
    34. <artifactId>jul-to-slf4jartifactId>
    35. <version>1.7.36version>
    36. dependency>
    37. <dependency>
    38. <groupId>org.projectlombokgroupId>
    39. <artifactId>lombokartifactId>
    40. <version>1.18.20version>
    41. <scope>providedscope>
    42. dependency>
    43. dependencies>

  • 相关阅读:
    SpringCloud Config 分布式服务配置
    Docker镜像安全深度扫描
    (02)Cartographer源码无死角解析-(13) 开始轨迹→Node::AddTrajectory()
    Nginx配置Https证书
    解决Kettle在Maven仓库中找不到的办法
    基于Thrift的分布式Hive数据源连接器
    C++ 字符串的 拼接,插入,查找与截取。
    多线程同步,信号,生产者消费者模型
    2021CCPC哈尔滨【个人题解BDEGIJ】
    【5种数据结构的操作】RedisTemplate模版类!
  • 原文地址:https://blog.csdn.net/qq_56040798/article/details/137976159