1. 在群设置 点击添加群机器人



要记住webhook地址 此处前置条件已完成
程序
这是官方文档
案例
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
/**
* @Author:那日花开
* @Package:com.geovis.webservice.util
* @Project:digit-trade-platform
* @name:RobotMessageUtil
* @Date:2024/12/25 9:06
* @Filename:RobotMessageUtil
*/
@Slf4j
@Component
public class RobotMessageUtil {
@Value("${webhool}")
public String webhool;
@Value("${environment}")
public String environment;
public void sentRobotMessage(String content){
try {
// 创建URL对象
URL url = new URL(webhool);
// 打开连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// 设置请求方法为POST
connection.setRequestMethod("POST");
// 设置请求头Content-Type为application/json
connection.setRequestProperty("Content-Type", "application/json; utf-8");
// 允许输出(发送请求体)
connection.setDoOutput(true);
content

最低0.47元/天 解锁文章
1950

被折叠的 条评论
为什么被折叠?



