Search in sources :

Example 6 with OapiRobotSendRequest

use of com.dingtalk.api.request.OapiRobotSendRequest in project dynamic-threadpool by acmenlt.

the class OpenChangeTimedTask method sendDingMessage.

public void sendDingMessage(OpenChangeInfo itemInfo) {
    String gitHubItemUrl = itemInfo.getHtml_url();
    String markdownText = String.format("<font color='#2a9d8f'>[通知] </font> GitHub Star Fork 变更通知 \n\n" + " --- \n\n " + "<font color='#708090' size=2>项目名称:HIPPO-JAVA</font> \n\n" + "<font color='#708090' size=2>项目地址:[%s](%s)</font> \n\n" + " --- \n\n " + "<font color='#708090' size=2>Hippo Stars Add:</font><font color='#FF8C00' size=2>%s</font> \n\n " + "<font color='#708090' size=2>Hippo Forks Add:</font><font color='#FF8C00' size=2>%s</font> \n\n " + " --- \n\n  " + "<font color='#708090' size=2>Hippo Now Star:[%d](" + gitHubItemUrl + "/stargazers)</font> \n\n" + "<font color='#708090' size=2>Hippo Now Fork:[%d](" + gitHubItemUrl + "/members)</font> \n\n" + "<font color='#708090' size=2>Hippo Open Issue:[%d](" + gitHubItemUrl + "/issues)</font> \n\n" + "<font color='#708090' size=2>Hippo Subscribers Count:[%d](" + gitHubItemUrl + "/watchers)</font> \n\n" + " --- \n\n  " + "<font color='#708090' size=2>友情提示:5 分钟内 Star Fork 有变更则通知(可配置)</font> \n\n" + "<font color='#708090' size=2>OWNER:Long-Tai</font> \n\n" + " --- \n\n  " + "**播报时间:%s**", itemInfo.getName().toUpperCase(), gitHubItemUrl, itemInfo.getStar_add() == null ? "-" : itemInfo.getStar_add().toString() + "+", itemInfo.getFork_add() == null ? "-" : itemInfo.getFork_add().toString() + "+", itemInfo.getStargazers_count(), itemInfo.getForks_count(), itemInfo.getOpen_issues_count(), itemInfo.getSubscribers_count(), DateUtil.now());
    OpenChangeNotifyBootstrapProperties.NotifyConfig notifyConfig = bootstrapProperties.getNotifys().get(0);
    String serverUrl = notifyConfig.getUrl() + notifyConfig.getToken();
    DingTalkClient dingTalkClient = new DefaultDingTalkClient(serverUrl);
    OapiRobotSendRequest request = new OapiRobotSendRequest();
    request.setMsgtype("markdown");
    OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
    markdown.setTitle("GitHub Star Fork 变更通知");
    markdown.setText(markdownText);
    request.setMarkdown(markdown);
    try {
        dingTalkClient.execute(request);
    } catch (ApiException ex) {
        log.error("Ding failed to send message.", ex.getMessage());
    }
}
Also used : DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DingTalkClient(com.dingtalk.api.DingTalkClient) OapiRobotSendRequest(com.dingtalk.api.request.OapiRobotSendRequest) ApiException(com.taobao.api.ApiException)

Aggregations

DefaultDingTalkClient (com.dingtalk.api.DefaultDingTalkClient)6 DingTalkClient (com.dingtalk.api.DingTalkClient)6 OapiRobotSendRequest (com.dingtalk.api.request.OapiRobotSendRequest)6 ApiException (com.taobao.api.ApiException)6 Mac (javax.crypto.Mac)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3 Receiver (io.metersphere.notice.domain.Receiver)1 UserDetail (io.metersphere.notice.domain.UserDetail)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1