1、新建钉钉机器人
2、下载Java包
https://ding-doc.dingtalk.com/doc#/faquestions/vzbp02
3、Java工程
public class Dingtest {
public static void main(String[] args){
try{
DingTalkClient client =new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=3a1xxxxxxx");
OapiRobotSendRequest request=new OapiRobotSendRequest();
request.setMsgtype("test");
OapiRobotSendRequest.Text test =new OapiRobotSendRequest.Text();
test .setContent("试试测试文本消息java发送");
request.setText(test);
OapiRobotSendRequest.At at=new OapiRobotSendRequest.At();
at.setAtMobiles(Arrays.asList("15001333166"));
request.setAt(at);
request.setMsgtype("link");
OapiRobotSendRequest.Link link=new OapiRobotSendRequest.Link();
link.setMessageUrl("https://www.dingtalk.com");
link.setPicUrl("");
link.setTitle("试试这个是新版本");
request.setLink(link);
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown=new OapiRobotSendRequest.Markdown();
markdown.setTitle("北京天气");
markdown.setText("试JAVA测试:空气好,天气热"+"9度"+"sss"+"ssss");
request.setMarkdown(markdown);
OapiRobotSendResponse response=client.execute(request);
//错误信息
System.out.println(response.getErrmsg());
} catch (Exception e){
return;
}
}
}
4、运行