예제 #1
0
        internal static async Task DoNoticeAsync(JobBaseInfo jobBaseInfo, string message)
        {
            var noticeDingConfig = ConfigItems.JobsConfig?.NoticeDingConfig;

            if (noticeDingConfig == null)
            {
                noticeDingConfig = new NoticeDingConfig
                {
                    NoticeDingToken  = ConfigItems.DingtalkToken,
                    NoticeDingPhones = ConfigItems.DingtalkPhones,
                    NoticeDingAtAll  = ConfigItems.DingtalkAtAll,
                    NoticeDingIsOpen = !string.IsNullOrEmpty(ConfigItems.DingtalkToken),
                };
            }
            var token = noticeDingConfig?.NoticeDingToken ?? ConfigItems.DingtalkToken;

            if (string.IsNullOrEmpty(token))
            {
                return;
            }
            var postData = GetDingTalkPostData(jobBaseInfo, message, noticeDingConfig);

            if (postData == null)
            {
                return;
            }

            var requestUri = $"https://oapi.dingtalk.com/robot/send?access_token={token}";
            var rlt        = await HttpPostAsync(requestUri, postData);

            JobLogHelper.Debug($"DoNoticeAsync response is {rlt}, \r\n message is {postData.ToJsonStr()} ,\r\n token is {token}", nameof(DoNoticeAsync));
        }
예제 #2
0
        static object GetDingTalkPostData(JobBaseInfo jobBaseInfo, string message, NoticeDingConfig noticeDingConfig)
        {
            var atMobiles = string.Empty;
            var isAtAll   = false;

            if (noticeDingConfig != null)
            {
                if (!noticeDingConfig.NoticeDingIsOpen)
                {
                    return(null);
                }
                atMobiles = noticeDingConfig.NoticeDingPhones;
                isAtAll   = noticeDingConfig.NoticeDingAtAll;
            }
            else
            {
                atMobiles = ConfigItems.DingtalkPhones;
                isAtAll   = ConfigItems.DingtalkAtAll;
            }
            // <font color=#228B22>Failed</font>
            var content = GetNoticeContent(jobBaseInfo, message);

            var title = "调度任务通知";
            var obj   = new
            {
                msgtype  = "markdown",
                markdown = new
                {
                    title,
                    text = content
                },
                at = new
                {
                    atMobiles,
                    isAtAll
                }
            };

            return(obj);
        }