Esempio n. 1
0
        public DingTalkResult SentNotification(IDingTalkNotification notification)
        {
            try
            {
                var uri     = $"{DingTalkSettings.ServerUrl}/send?access_token={DingTalkSettings.ReceiverToken}";
                var jsonStr = JsonConvert.SerializeObject(notification);
                var content = new StringContent(jsonStr, Encoding.UTF8, "application/json");
                using (var _httpClient = new HttpClient())
                {
                    var response   = _httpClient.PostAsync(uri, content).Result;
                    var jsonResult = response.Content.ReadAsStringAsync().Result;
                    var result     = _jsonSerialzer.Deserialize <DingTalkResult>(jsonResult);
                    if (!result.IsSucceed())
                    {
                        _logger.Error($"发送钉钉消息失败,原因:{result.ErrMsg}");
                    }
                    else
                    {
                        _logger.Info($"发送钉钉消息成功.消息内容:{jsonStr}");
                    }

                    return(result);
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"发送钉钉消息异常,原因:{ex.ToString()}");
                return(new DingTalkResult(Error_DingTalk_Exception, ex.ToString()));
            }
        }
Esempio n. 2
0
 public async Task <DingTalkResult> SentNotificationAsync(IDingTalkNotification notification)
 {
     return(await Task.Run(() => SentNotification(notification)));
 }