cs 钉钉机器人 markdown类型

     来啊,玩机器人啊

package cn.yuhuans.tianfutv.utils;

import cn.yuhuans.tianfutv.beans.dingdingrobot.Robot;
import com.alibaba.fastjson.JSON;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class RobotSendUtils {

    public static void send(Robot robot, String WEBHOOK){

        //创建HttpClient对象
        HttpClient httpClient = HttpClients.createDefault();

        // 创建请求方法的实例
        HttpPost httpPost = new HttpPost(WEBHOOK);

        //请求参数
        httpPost.addHeader("Content-Type", "application/json; charset=utf-8");
        HttpEntity httpEntity = new StringEntity(JSON.toJSONString(robot),"utf-8");
        httpPost.setEntity(httpEntity);

        HttpResponse response;
        String result;
        try {
            response = httpClient.execute(httpPost);

            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

                result = EntityUtils.toString(response.getEntity(), "utf-8");

                System.out.println(result);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

特别的  

Robot.java

package cn.yuhuans.tianfutv.beans.dingdingrobot;

public class Robot {

    private String msgtype = "markdown";//默认markdown

    private Markdown markdown;//信息

    private At at;//@的人

}

markdown.java

package cn.yuhuans.tianfutv.beans.dingdingrobot;

public class Markdown {

    private String title;//标题

    private String text;//内容

}

At.java

package cn.yuhuans.tianfutv.beans.dingdingrobot;

import java.util.List;

public class At {

    private List atMobiles;//@的人
    private Boolean isAtAll = false;//默认不@all

}

 

你可能感兴趣的:(java)