1. 程式人生 > >釘釘群機器人定時傳送訊息並@所有人

釘釘群機器人定時傳送訊息並@所有人

1.新增釘釘自定義群機器人

參考文章如下:

官方網址;https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.p2lr6t&treeId=257&articleId=105733&docType=1

2.如何使用自定義群機器人:

參考文章:https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.karFPe&treeId=257&articleId=105735&docType=1

注意:使用Java程式時需匯入相關jar包

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;
 
 
public class ChatbotSend {
 
    public static String WEBHOOK_TOKEN = "https://oapi.dingtalk.com/robot/send?access_token=xxxxxx";
 
    public static void main(String args[]) throws Exception{
 
        HttpClient httpclient = HttpClients.createDefault();
 
        HttpPost httppost = new HttpPost(WEBHOOK_TOKEN);
        httppost.addHeader("Content-Type", "application/json; charset=utf-8");
 
        
        String msg = "我就是我,是顏色不一樣的煙火";
	String textMsg = "{ \"msgtype\": \"text\", \"text\": {\"content\": \"" + msg + "\"},\"at\":{\"isAtAll\":true} }";

        StringEntity se = new StringEntity(textMsg, "utf-8");
        httppost.setEntity(se);
 
        HttpResponse response = httpclient.execute(httppost);
        if (response.getStatusLine().getStatusCode()== HttpStatus.SC_OK){
            String result= EntityUtils.toString(response.getEntity(), "utf-8");
            System.out.println(result);
        }
    }
}

3.java程式打成jar包,並建立windows定時任務。
參考文章:https://www.cnblogs.com/xuezhezlr/p/7725301.html

注意:匯出jar包,不同的eclipse版本匯出的選項不同,要把jar包一起匯出。

問題:
1.執行計劃時,報:Unable to access jarfile
解決辦法:.bat檔案中jar的路徑給全路徑

@echo off
java -jar E:\jar\test.jar
pause


2.因為本機安裝的jdk1.8,windows計劃執行的時候報:has value '1.8',but'1.7' is required
解決辦法:
https://www.cnblogs.com/freedom-wy/p/6945936.html
https://blog.csdn.net/manerfan/article/details/48492809