diff --git a/README.md b/README.md index 3c22aa3..821de39 100644 --- a/README.md +++ b/README.md @@ -331,6 +331,150 @@ func main() { +
+C# 示例 +
+ +```csharp +using Newtonsoft.Json; +using RestSharp; + +namespace Demo +{ + public class Program + { + public static void Main(string[] args) + { + //推送消息 + var sendMsg = MessagePusherTool.SendMessage("标题", "描述", "**Markdown 内容**"); + if(sendMsg.Success) + { + Console.WriteLine($"推送成功!"); + } + else + { + Console.WriteLine($"推送失败:{sendMsg.Message}"); + } + } + } + + /// + /// 消息推送工具 + /// + /// 开源地址:https://github.com/songquanpeng/message-pusher + /// 支持:Framework、Net3.1、Net5、Net6 + /// 引用包: + /// dotnet add package Newtonsoft.Json -v 13.0.2 + /// dotnet add package RestSharp -v 108.0.3 + /// + public class MessagePusherTool + { + /// + /// ServerAddress + /// + public const string ServerAddress = "https://msgpusher.com"; + + /// + /// UserName + /// + public const string UserName = "test"; + + /// + /// Token + /// + public const string Token = "666"; + + /// + /// SendMessage + /// + /// title + /// description + /// content + public static Response SendMessage(string title, string description, string content) + { + var requestData = new Request() + { + Title = title, + Description = description, + Content = content, + Token = Token, + }; + var url = $"{ServerAddress}"; + var client = new RestClient(url); + var request = new RestRequest($"push/{UserName}", Method.Post); + request.AddJsonBody(requestData); + var response = client.Execute(request); + var responseData = response.Content; + var responseJson = JsonConvert.DeserializeObject(responseData); + return responseJson; + } + + /// + /// Request + /// + public class Request + { + /// + /// Title + /// + [JsonProperty(PropertyName = "title")] + public string Title { get; set; } + + /// + /// Description + /// + [JsonProperty(PropertyName = "description")] + public string Description { get; set; } + + /// + /// Content + /// + [JsonProperty(PropertyName = "content")] + public string Content { get; set; } + + /// + /// URL + /// + [JsonProperty(PropertyName = "url")] + public string URL { get; set; } + + /// + /// Channel + /// + [JsonProperty(PropertyName = "channel")] + public string Channel { get; set; } + + /// + /// Token + /// + [JsonProperty(PropertyName = "token")] + public string Token { get; set; } + } + + /// + /// Response + /// + public class Response + { + /// + /// Success + /// + [JsonProperty(PropertyName = "success")] + public bool Success { get; set; } + + /// + /// Message + /// + [JsonProperty(PropertyName = "message")] + public string Message { get; set; } + } + } +} +``` + +
+
+ 欢迎 PR 添加更多语言的示例。