using System; using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using Hncore.Infrastructure.Serializer; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Hncore.Infrastructure.Common.DingTalk { public class DingTalkHelper { private static HttpClient _httpClient = new HttpClient(new HttpClientHandler() {UseProxy = false}) {Timeout = TimeSpan.FromMinutes(1)}; static DingTalkHelper() { _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } public static Task SendMessage(object message) { return null; // return _httpClient.PostAsync("https://oapi.dingtalk.com/robot/send?access_token=33", JsonContent(message)); } private static StringContent JsonContent(object obj) { return new StringContent(obj.ToJson(), Encoding.UTF8, "application/json"); } private static async Task CheckSuccess(HttpResponseMessage res) { var content = await res.Content.ReadAsStringAsync(); JObject jObject = JsonConvert.DeserializeObject(content); if (jObject["errmsg"].ToString() == "ok" && Convert.ToInt32(jObject["errcode"]) != 0) { return false; } return true; } } /// /// 此消息类型为固定text /// public class TextModel { /// /// 此消息类型为固定text /// public string msgtype => "text"; /// /// 消息内容 /// public text text { get; set; } /// /// @人 /// public atText at { get; set; } } /// /// 消息内容 /// public class text { /// /// 消息内容 /// public string content { get; set; } } /// /// @人 /// public class atText { /// /// 被@人的手机号 /// public List atMobiles { get; set; } /// /// @所有人时:true,否则为:false /// public bool isAtAll { get; set; } = false; } /// /// 此消息类型为固定markdown /// public class MarkDownModel { /// /// 此消息类型为固定markdown /// public string msgtype => "markdown"; /// /// 消息内容 /// public markdown markdown { get; set; } /// /// @人 /// public atMarkdown at { get; set; } } /// /// 消息内容 /// public class markdown { /// /// 标题 /// public string title { get; set; } /// /// 消息内容 /// public string text { get; set; } } /// /// @人 /// public class atMarkdown { /// /// 被@人的手机号 /// public List atMobiles { get; set; } /// /// @所有人时:true,否则为:false /// public bool isAtAll { get; set; } = false; } }