47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
using RestSharp;
|
|
|
|
namespace Tianyi.DingtalkRobotKit
|
|
{
|
|
public static class SendMessage
|
|
{
|
|
public static string DingtalkRobotUrl
|
|
{
|
|
get
|
|
{
|
|
return "https://oapi.dingtalk.com/robot/send?access_token=f28974dc6d79e3c75570dda86e98a770a21e406aaf885804d9e7a7b73a33240f";
|
|
}
|
|
set
|
|
{
|
|
DingtalkRobotUrl = value;
|
|
}
|
|
}
|
|
|
|
public static MessageResult Send<T>(T message) where T : MessageBase
|
|
{
|
|
MessageResult result = new MessageResult()
|
|
{
|
|
errcode=-1,
|
|
errmsg=""
|
|
};
|
|
|
|
|
|
var client = new RestClient("https://oapi.dingtalk.com");
|
|
|
|
var request = new RestRequest("robot/send?access_token=f28974dc6d79e3c75570dda86e98a770a21e406aaf885804d9e7a7b73a33240f", Method.POST);
|
|
|
|
request.AddHeader("Content-Type", "application/json");
|
|
request.AddJsonBody(message.ToJson());
|
|
|
|
var response2 = client.Execute<MessageResult>(request);
|
|
result.errcode = response2.Data.errcode;
|
|
result.errmsg = response2.Data.errmsg;
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|