接口文件
This commit is contained in:
151
Infrastructure/Hncore.Infrastructure/Common/DingTalkHelper.cs
Normal file
151
Infrastructure/Hncore.Infrastructure/Common/DingTalkHelper.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
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<bool> CheckSuccess(HttpResponseMessage res)
|
||||
{
|
||||
var content = await res.Content.ReadAsStringAsync();
|
||||
|
||||
JObject jObject = JsonConvert.DeserializeObject<JObject>(content);
|
||||
|
||||
if (jObject["errmsg"].ToString() == "ok" && Convert.ToInt32(jObject["errcode"]) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 此消息类型为固定text
|
||||
/// </summary>
|
||||
public class TextModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 此消息类型为固定text
|
||||
/// </summary>
|
||||
public string msgtype => "text";
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
public text text { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// @人
|
||||
/// </summary>
|
||||
public atText at { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
public class text
|
||||
{
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
public string content { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// @人
|
||||
/// </summary>
|
||||
public class atText
|
||||
{
|
||||
/// <summary>
|
||||
/// 被@人的手机号
|
||||
/// </summary>
|
||||
public List<string> atMobiles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// @所有人时:true,否则为:false
|
||||
/// </summary>
|
||||
public bool isAtAll { get; set; } = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 此消息类型为固定markdown
|
||||
/// </summary>
|
||||
public class MarkDownModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 此消息类型为固定markdown
|
||||
/// </summary>
|
||||
public string msgtype => "markdown";
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
public markdown markdown { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// @人
|
||||
/// </summary>
|
||||
public atMarkdown at { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
public class markdown
|
||||
{
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
public string text { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// @人
|
||||
/// </summary>
|
||||
public class atMarkdown
|
||||
{
|
||||
/// <summary>
|
||||
/// 被@人的手机号
|
||||
/// </summary>
|
||||
public List<string> atMobiles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// @所有人时:true,否则为:false
|
||||
/// </summary>
|
||||
public bool isAtAll { get; set; } = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user