├── DingtalkChatbotSdk ├── global.json ├── UnitTest45 │ ├── packages.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── UnitTest1.cs │ └── UnitTest45.csproj ├── UnitTest451 │ ├── packages.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── UnitTest1.cs │ └── UnitTest451.csproj ├── src │ ├── DingtalkChatbotSdk │ │ ├── Models │ │ │ ├── IDingDingMessage.cs │ │ │ ├── DingDingMessage.cs │ │ │ ├── MarkdownMessage.cs │ │ │ ├── LinkMessage.cs │ │ │ ├── FeedCardMessage.cs │ │ │ ├── TextMessage.cs │ │ │ ├── FullActionCardMessage.cs │ │ │ └── SingleActionCardMessage.cs │ │ ├── SendResult.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── DingtalkChatbotSdk.xproj │ │ ├── project.json │ │ └── DingDingClient.cs │ └── NetCoreTest │ │ ├── project.json │ │ ├── Program.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ └── NetCoreTest.xproj ├── UnitTest │ ├── packages.config │ ├── app.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── UnitTest1.cs │ └── UnitTest40.csproj └── DingtalkChatbotSdk.sln ├── README.md ├── MIT-LICENSE.txt ├── .gitattributes └── .gitignore /DingtalkChatbotSdk/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "projects": [ "src", "test" ], 3 | "sdk": { 4 | "version": "1.0.0-preview2-003131" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #钉钉群机器人SDK 2 | 3 | #NuGET:Install-Package DingtalkChatbotSdk 4 | 5 | 支持以下平台 6 | net40 7 | net45 8 | net451 9 | dotnetcore 10 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest45/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest451/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/Models/IDingDingMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace DingtalkChatbotSdk.Models 7 | { 8 | /// 9 | /// 钉钉机器人消息类型接口 10 | /// 11 | public interface IDingDingMessage 12 | { 13 | string ToJson(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/NetCoreTest/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | "emitEntryPoint": true 5 | }, 6 | 7 | "dependencies": { 8 | "DingtalkChatbotSdk": "1.0.1", 9 | "Microsoft.NETCore.App": { 10 | "type": "platform", 11 | "version": "1.0.1" 12 | } 13 | }, 14 | 15 | "frameworks": { 16 | "netcoreapp1.0": { 17 | "imports": "dnxcore50" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/SendResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Newtonsoft.Json; 6 | 7 | namespace DingtalkChatbotSdk 8 | { 9 | /// 10 | /// 发送消息结果 11 | /// 12 | public class SendResult 13 | { 14 | [JsonProperty("errmsg")] 15 | public string ErrMsg { get; set; } 16 | 17 | [JsonProperty("errcode")] 18 | public int ErrCode { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/NetCoreTest/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using DingtalkChatbotSdk; 6 | 7 | namespace NetCoreTest 8 | { 9 | public class Program 10 | { 11 | public static string WebHookUrl = "https://oapi.dingtalk.com/robot/send?access_token=8968f46ab77718c6f2532a3d3aba3eef3b9725594e988b76e5fc807b8aef6c35"; 12 | 13 | 14 | 15 | public static void Main(string[] args) 16 | { 17 | var result = DingDingClient.SendMessageAsync(WebHookUrl, "测试").Result; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/Models/DingDingMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace DingtalkChatbotSdk.Models 7 | { 8 | /// 9 | /// 抽象的消息类型 10 | /// 11 | public abstract class DingDingMessage : IDingDingMessage 12 | { 13 | 14 | public abstract string GetMsgType(); 15 | 16 | public virtual string ToJson() 17 | { 18 | var t = GetMsgType(); 19 | 20 | return "{\"msgtype\": \"" + t + "\",\"" + t + "\" : @ }"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/NetCoreTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("NetCoreTest")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("cddddc66-3820-418f-8ff4-ff1af0a2663e")] 20 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("DingtalkChatbotSdk")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("01366446-2dda-461e-85e8-09e9af7f1520")] 20 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/Models/MarkdownMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Newtonsoft.Json; 6 | 7 | namespace DingtalkChatbotSdk.Models 8 | { 9 | /// 10 | /// markdown类型 11 | /// 12 | public class MarkdownMessage : DingDingMessage 13 | { 14 | public override string GetMsgType() 15 | { 16 | return "markdown"; 17 | } 18 | 19 | /// 20 | /// 首屏会话透出的展示内容 21 | /// 22 | [JsonProperty("title")] 23 | public string Title { get; set; } 24 | 25 | /// 26 | /// markdown格式的消息 27 | /// 28 | [JsonProperty("text")] 29 | public string Text { get; set; } 30 | 31 | public override string ToJson() 32 | { 33 | var baseJson = base.ToJson(); 34 | var thisJon = JsonConvert.SerializeObject(this); 35 | return baseJson.Replace("@", thisJon); 36 | } 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 zdyu <1877682825@qq.com> 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/NetCoreTest/NetCoreTest.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | cddddc66-3820-418f-8ff4-ff1af0a2663e 11 | NetCoreTest 12 | .\obj 13 | .\bin\ 14 | v4.5 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/DingtalkChatbotSdk.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | 01366446-2dda-461e-85e8-09e9af7f1520 11 | DingtalkChatbotSdk 12 | .\obj 13 | .\bin\ 14 | v4.5 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/Models/LinkMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Newtonsoft.Json; 6 | 7 | namespace DingtalkChatbotSdk.Models 8 | { 9 | /// 10 | /// link类型 11 | /// 12 | public class LinkMessage : DingDingMessage 13 | { 14 | /// 15 | /// 消息内容。如果太长只会部分展示 16 | /// 17 | [JsonProperty("text")] 18 | public string Text { get; set; } 19 | 20 | /// 21 | /// 消息标题 22 | /// 23 | [JsonProperty("title")] 24 | public string Title { get; set; } 25 | 26 | /// 27 | /// 图片URL 28 | /// 29 | [JsonProperty("picUrl")] 30 | public string PicUrl { get; set; } 31 | 32 | /// 33 | /// 点击消息跳转的URL 34 | /// 35 | [JsonProperty("messageUrl")] 36 | public string MessageUrl { get; set; } 37 | 38 | public override string GetMsgType() 39 | { 40 | return "link"; 41 | } 42 | 43 | public override string ToJson() 44 | { 45 | var baseJson = base.ToJson(); 46 | var thisJon = JsonConvert.SerializeObject(this); 47 | return baseJson.Replace("@", thisJon); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("UnitTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("UnitTest")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e0cf4109-b3e7-47ca-ae44-12d5f129b7ee")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest45/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("UnitTest45")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("UnitTest45")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0f26e210-5aa4-4369-82c4-ebf37d8dac38")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest451/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("UnitTest451")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("UnitTest451")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("39a2ef1c-3558-4af8-bc7b-984b0dd8adb3")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/Models/FeedCardMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Newtonsoft.Json; 6 | 7 | namespace DingtalkChatbotSdk.Models 8 | { 9 | 10 | /// 11 | /// FeedCard类型 12 | /// 13 | public class FeedCardMessage : DingDingMessage 14 | { 15 | public override string GetMsgType() 16 | { 17 | return "feedCard"; 18 | } 19 | 20 | /// 21 | /// 列表 22 | /// 23 | [JsonProperty("links")] 24 | public List FeedCardItems { get; set; } 25 | 26 | 27 | public override string ToJson() 28 | { 29 | var baseJson = base.ToJson(); 30 | var thisJon = JsonConvert.SerializeObject(this); 31 | return baseJson.Replace("@", thisJon); 32 | } 33 | } 34 | 35 | /// 36 | /// FeedCard类型Item 37 | /// 38 | public class FeedCardItem 39 | { 40 | /// 41 | /// 单条信息文本 42 | /// 43 | [JsonProperty("title")] 44 | public string Title { get; set; } 45 | 46 | /// 47 | /// 点击单条信息到跳转链接 48 | /// 49 | [JsonProperty("messageURL")] 50 | public string MessageURL { get; set; } 51 | 52 | /// 53 | /// 单条信息后面图片的URL 54 | /// 55 | [JsonProperty("picURL")] 56 | public string PicURL { get; set; } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/Models/TextMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Newtonsoft.Json; 6 | 7 | namespace DingtalkChatbotSdk.Models 8 | { 9 | 10 | /// 11 | /// 文本类型 12 | /// 13 | public class TextMessage : DingDingMessage 14 | { 15 | public override string GetMsgType() 16 | { 17 | return "text"; 18 | } 19 | 20 | /// 21 | /// 消息内容 22 | /// 23 | [JsonProperty("content")] 24 | public string Content { get; set; } 25 | 26 | /// 27 | /// 被@的信息 28 | /// 29 | [JsonIgnore] 30 | public AtSetting at { get; set; } 31 | 32 | public override string ToJson() 33 | { 34 | var baseJson = base.ToJson(); 35 | var thisJon = JsonConvert.SerializeObject(this); 36 | var prefix = baseJson.Replace("@", thisJon); 37 | var temp = prefix.Substring(0, prefix.Length - 1); 38 | var subfix = temp + "," + at.ToJson() + "}"; 39 | return subfix; 40 | } 41 | } 42 | /// 43 | /// @ 配置 44 | /// 45 | public class AtSetting 46 | { 47 | public AtSetting() 48 | { 49 | AtMobiles = new List(); 50 | } 51 | 52 | /// 53 | /// 被@人的手机号 54 | /// 55 | [JsonProperty("atMobiles")] 56 | public List AtMobiles { get; set; } 57 | 58 | /// 59 | /// @所有人时:true,否则为:false 60 | /// 61 | [JsonProperty("isAtAll")] 62 | public bool IsAtAll { get; set; } 63 | 64 | public string ToJson() 65 | { 66 | return "\"at\":" + JsonConvert.SerializeObject(this); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/Models/FullActionCardMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Newtonsoft.Json; 6 | 7 | namespace DingtalkChatbotSdk.Models 8 | { 9 | /// 10 | /// 整体跳转ActionCard类型 11 | /// 12 | public class FullActionCardMessage : DingDingMessage 13 | { 14 | public override string GetMsgType() 15 | { 16 | return "actionCard"; 17 | } 18 | 19 | /// 20 | /// 首屏会话透出的展示内容 21 | /// 22 | [JsonProperty("title")] 23 | public string Title { get; set; } 24 | 25 | /// 26 | /// markdown格式的消息 27 | /// 28 | [JsonProperty("text")] 29 | public string Text { get; set; } 30 | 31 | /// 32 | /// 0-正常发消息者头像,1-隐藏发消息者头像 33 | /// 34 | [JsonIgnore] 35 | public int HideAvatar { get; set; } 36 | 37 | /// 38 | /// 0-正常发消息者头像,1-隐藏发消息者头像 39 | /// 40 | [JsonProperty("hideAvatar")] 41 | private string HideAvatar1 42 | { 43 | get { return HideAvatar.ToString(); } 44 | } 45 | 46 | /// 47 | /// 0-按钮竖直排列,1-按钮横向排列 48 | /// 49 | [JsonIgnore] 50 | public int BtnOrientation { get; set; } 51 | 52 | /// 53 | /// 0-按钮竖直排列,1-按钮横向排列 54 | /// 55 | [JsonProperty("btnOrientation")] 56 | private string BtnOrientation1 57 | { 58 | get { return BtnOrientation.ToString(); } 59 | } 60 | 61 | /// 62 | /// 点击singleTitle按钮触发的URL 63 | /// 64 | [JsonProperty("singleURL")] 65 | public string SingleURL { get; set; } 66 | 67 | /// 68 | /// 单个按钮的方案。(设置此项和singleURL后btns无效。) 69 | /// 70 | [JsonProperty("singleTitle")] 71 | public string SingleTitle { get; set; } 72 | 73 | 74 | public override string ToJson() 75 | { 76 | var baseJson = base.ToJson(); 77 | var thisJon = JsonConvert.SerializeObject(this); 78 | return baseJson.Replace("@", thisJon); 79 | } 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/Models/SingleActionCardMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Newtonsoft.Json; 6 | 7 | namespace DingtalkChatbotSdk.Models 8 | { 9 | /// 10 | /// 独立跳转ActionCard类型 11 | /// 12 | public class SingleActionCardMessage : DingDingMessage 13 | { 14 | public override string GetMsgType() 15 | { 16 | return "actionCard"; 17 | } 18 | 19 | /// 20 | /// 首屏会话透出的展示内容 21 | /// 22 | [JsonProperty("title")] 23 | public string Title { get; set; } 24 | 25 | /// 26 | /// markdown格式的消息 27 | /// 28 | [JsonProperty("text")] 29 | public string Text { get; set; } 30 | 31 | /// 32 | /// 0-正常发消息者头像,1-隐藏发消息者头像 33 | /// 34 | [JsonIgnore] 35 | public int HideAvatar { get; set; } 36 | 37 | /// 38 | /// 0-正常发消息者头像,1-隐藏发消息者头像 39 | /// 40 | [JsonProperty("hideAvatar")] 41 | private string HideAvatar1 42 | { 43 | get { return HideAvatar.ToString(); } 44 | } 45 | 46 | /// 47 | /// 0-按钮竖直排列,1-按钮横向排列 48 | /// 49 | [JsonIgnore] 50 | public int BtnOrientation { get; set; } 51 | 52 | /// 53 | /// 0-按钮竖直排列,1-按钮横向排列 54 | /// 55 | [JsonProperty("btnOrientation")] 56 | private string BtnOrientation1 57 | { 58 | get { return BtnOrientation.ToString(); } 59 | } 60 | 61 | /// 62 | /// 按钮的信息 63 | /// 64 | [JsonProperty("btns")] 65 | public List SingleActionCardButtons { get; set; } 66 | 67 | public override string ToJson() 68 | { 69 | var baseJson = base.ToJson(); 70 | var thisJon = JsonConvert.SerializeObject(this); 71 | return baseJson.Replace("@", thisJon); 72 | } 73 | } 74 | 75 | /// 76 | /// 按钮的信息 77 | /// 78 | public class SingleActionCardButton 79 | { 80 | /// 81 | /// 按钮文案 82 | /// 83 | [JsonProperty("title")] 84 | public string Title { get; set; } 85 | 86 | /// 87 | /// 点击按钮触发的URL 88 | /// 89 | [JsonProperty("actionURL")] 90 | public string ActionURL { get; set; } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DingtalkChatbotSdk", 3 | "version": "1.0.1-*", 4 | "authors": [ "zdyu" ], 5 | "description": "钉钉群机器人SDK", 6 | "packOptions": { 7 | "licenseUrl": "https://github.com/yuzd/DingtalkChatbotSdk", 8 | "projectUrl": "https://github.com/yuzd/DingtalkChatbotSdk", 9 | "requireLicenseAcceptance": false, 10 | "tags": [ 11 | "DingDing", 12 | "chat", 13 | "robot", 14 | "sdk" 15 | ] 16 | }, 17 | "buildOptions": { 18 | "outputName": "DingtalkChatbotSdk", 19 | "embed": [ "**/*.resx", "**/*.txt" ] 20 | }, 21 | "dependencies": { 22 | }, 23 | 24 | "frameworks": { 25 | "net40": { 26 | "frameworkAssemblies": { 27 | "Microsoft.CSharp": "", 28 | "System": "", 29 | "System.Core": "", 30 | "System.Data.DataSetExtensions": "", 31 | "System.Data": "", 32 | "System.Runtime.Serialization": "", 33 | "System.Net": "" 34 | }, 35 | "dependencies": { 36 | "Microsoft.Bcl.Async": "1.0.*", 37 | "Newtonsoft.Json": "9.0.*" 38 | }, 39 | "buildOptions": { 40 | "define": [ "FW4", "NOASYNC" ], 41 | "compile": { 42 | "exclude": [ 43 | ] 44 | } 45 | } 46 | 47 | }, 48 | "net45": { 49 | "frameworkAssemblies": { 50 | "Microsoft.CSharp": "", 51 | "System": "", 52 | "System.Core": "", 53 | "System.Data.DataSetExtensions": "", 54 | "System.Data": "", 55 | "System.Runtime.Serialization": "", 56 | "System.Net": "" 57 | }, 58 | "dependencies": { 59 | "Newtonsoft.Json": "9.0.*" 60 | }, 61 | "buildOptions": { 62 | "define": [ "FW4" ], 63 | "compile": { 64 | "exclude": [ 65 | ] 66 | } 67 | } 68 | }, 69 | "net451": { 70 | "frameworkAssemblies": { 71 | "Microsoft.CSharp": "", 72 | "System": "", 73 | "System.Core": "", 74 | "System.Data.DataSetExtensions": "", 75 | "System.Data": "", 76 | "System.Runtime.Serialization": "", 77 | "System.Net": "" 78 | }, 79 | "dependencies": { 80 | "Newtonsoft.Json": "9.0.*" 81 | }, 82 | "buildOptions": { 83 | "define": [ "FW4" ], 84 | "compile": { 85 | "exclude": [ 86 | ] 87 | } 88 | } 89 | 90 | }, 91 | "netstandard1.6": { 92 | "buildOptions": { 93 | "define": [ "FW4", "NETSTANDARD" ], 94 | "compile": { 95 | "exclude": [ 96 | ] 97 | } 98 | }, 99 | "dependencies": { 100 | "NETStandard.Library": "1.6.1", 101 | "Microsoft.CSharp": "4.3.0", 102 | "System.Runtime.Serialization.Primitives": "4.3.0", 103 | "System.Threading.Thread": "4.3.0", 104 | "Newtonsoft.Json": "9.0.*", 105 | "System.Net.Requests": "4.3.0" 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | #Auto Generate files 10 | __ConfigTemp/ 11 | 12 | # Build results 13 | 14 | [Dd]ebug/ 15 | [Rr]elease/ 16 | x64/ 17 | build/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | 21 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 22 | !packages/*/build/ 23 | 24 | # MSTest test Results 25 | [Tt]est[Rr]esult*/ 26 | [Bb]uild[Ll]og.* 27 | Gruntfile.js 28 | *.nuspec 29 | *_i.c 30 | *_p.c 31 | *.ilk 32 | *.meta 33 | *.obj 34 | *.pch 35 | *.pdb 36 | *.pgc 37 | *.pgd 38 | *.rsp 39 | *.sbr 40 | *.tlb 41 | *.tli 42 | *.tlh 43 | *.tmp 44 | *.tmp_proj 45 | *.log 46 | *.vspscc 47 | *.vssscc 48 | .builds 49 | *.pidb 50 | *.log 51 | *.scc 52 | 53 | 54 | # Visual C++ cache files 55 | ipch/ 56 | *.aps 57 | *.ncb 58 | *.opensdf 59 | *.sdf 60 | *.cachefile 61 | 62 | # Visual Studio profiler 63 | *.psess 64 | *.vsp 65 | *.vspx 66 | 67 | # Guidance Automation Toolkit 68 | *.gpState 69 | 70 | # ReSharper is a .NET coding add-in 71 | _ReSharper*/ 72 | *.[Rr]e[Ss]harper 73 | 74 | # TeamCity is a build add-in 75 | _TeamCity* 76 | 77 | # DotCover is a Code Coverage Tool 78 | *.dotCover 79 | 80 | # NCrunch 81 | *.ncrunch* 82 | .*crunch*.local.xml 83 | 84 | # Installshield output folder 85 | [Ee]xpress/ 86 | 87 | # DocProject is a documentation generator add-in 88 | DocProject/buildhelp/ 89 | DocProject/Help/*.HxT 90 | DocProject/Help/*.HxC 91 | DocProject/Help/*.hhc 92 | DocProject/Help/*.hhk 93 | DocProject/Help/*.hhp 94 | DocProject/Help/Html2 95 | DocProject/Help/html 96 | 97 | # Click-Once directory 98 | publish/ 99 | 100 | # Publish Web Output 101 | *.Publish.xml 102 | 103 | # NuGet Packages Directory 104 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 105 | #packages/ 106 | 107 | # Windows Azure Build Output 108 | csx 109 | *.build.csdef 110 | 111 | # Windows Store app package directory 112 | AppPackages/ 113 | 114 | # Others 115 | *.Cache 116 | ClientBin/ 117 | [Ss]tyle[Cc]op.* 118 | ~$* 119 | *~ 120 | *.dbmdl 121 | *.[Pp]ublish.xml 122 | *.pfx 123 | *.publishsettings 124 | 125 | # RIA/Silverlight projects 126 | Generated_Code/ 127 | 128 | # Backup & report files from converting an old project file to a newer 129 | # Visual Studio version. Backup files are not needed, because we have git ;-) 130 | _UpgradeReport_Files/ 131 | Backup*/ 132 | UpgradeLog*.XML 133 | UpgradeLog*.htm 134 | 135 | # SQL Server files 136 | App_Data/*.mdf 137 | App_Data/*.ldf 138 | 139 | 140 | #LightSwitch generated files 141 | GeneratedArtifacts/ 142 | _Pvt_Extensions/ 143 | ModelManifest.xml 144 | 145 | # ========================= 146 | # Windows detritus 147 | # ========================= 148 | 149 | # Windows image file caches 150 | Thumbs.db 151 | ehthumbs.db 152 | 153 | # Folder config file 154 | Desktop.ini 155 | 156 | # Recycle Bin used on file shares 157 | $RECYCLE.BIN/ 158 | 159 | # Mac desktop service store files 160 | .DS_Store 161 | node_modules/ 162 | packages/ 163 | 164 | 165 | DingtalkChatbotSdk/.vs/restore.dg 166 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/DingtalkChatbotSdk.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{37D31C29-4B24-4580-A72E-C72D78C62C09}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C1D4C059-B9A8-481A-A3A9-9A15D7D594A0}" 9 | ProjectSection(SolutionItems) = preProject 10 | global.json = global.json 11 | EndProjectSection 12 | EndProject 13 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "DingtalkChatbotSdk", "src\DingtalkChatbotSdk\DingtalkChatbotSdk.xproj", "{01366446-2DDA-461E-85E8-09E9AF7F1520}" 14 | EndProject 15 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest40", "UnitTest\UnitTest40.csproj", "{E0CF4109-B3E7-47CA-AE44-12D5F129B7EE}" 16 | EndProject 17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest45", "UnitTest45\UnitTest45.csproj", "{0F26E210-5AA4-4369-82C4-EBF37D8DAC38}" 18 | EndProject 19 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest451", "UnitTest451\UnitTest451.csproj", "{39A2EF1C-3558-4AF8-BC7B-984B0DD8ADB3}" 20 | EndProject 21 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NetCoreTest", "src\NetCoreTest\NetCoreTest.xproj", "{CDDDDC66-3820-418F-8FF4-FF1AF0A2663E}" 22 | EndProject 23 | Global 24 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 25 | Debug|Any CPU = Debug|Any CPU 26 | Release|Any CPU = Release|Any CPU 27 | EndGlobalSection 28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 | {01366446-2DDA-461E-85E8-09E9AF7F1520}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {01366446-2DDA-461E-85E8-09E9AF7F1520}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {01366446-2DDA-461E-85E8-09E9AF7F1520}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {01366446-2DDA-461E-85E8-09E9AF7F1520}.Release|Any CPU.Build.0 = Release|Any CPU 33 | {E0CF4109-B3E7-47CA-AE44-12D5F129B7EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {E0CF4109-B3E7-47CA-AE44-12D5F129B7EE}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {E0CF4109-B3E7-47CA-AE44-12D5F129B7EE}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {E0CF4109-B3E7-47CA-AE44-12D5F129B7EE}.Release|Any CPU.Build.0 = Release|Any CPU 37 | {0F26E210-5AA4-4369-82C4-EBF37D8DAC38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 38 | {0F26E210-5AA4-4369-82C4-EBF37D8DAC38}.Debug|Any CPU.Build.0 = Debug|Any CPU 39 | {0F26E210-5AA4-4369-82C4-EBF37D8DAC38}.Release|Any CPU.ActiveCfg = Release|Any CPU 40 | {0F26E210-5AA4-4369-82C4-EBF37D8DAC38}.Release|Any CPU.Build.0 = Release|Any CPU 41 | {39A2EF1C-3558-4AF8-BC7B-984B0DD8ADB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 42 | {39A2EF1C-3558-4AF8-BC7B-984B0DD8ADB3}.Debug|Any CPU.Build.0 = Debug|Any CPU 43 | {39A2EF1C-3558-4AF8-BC7B-984B0DD8ADB3}.Release|Any CPU.ActiveCfg = Release|Any CPU 44 | {39A2EF1C-3558-4AF8-BC7B-984B0DD8ADB3}.Release|Any CPU.Build.0 = Release|Any CPU 45 | {CDDDDC66-3820-418F-8FF4-FF1AF0A2663E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {CDDDDC66-3820-418F-8FF4-FF1AF0A2663E}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {CDDDDC66-3820-418F-8FF4-FF1AF0A2663E}.Release|Any CPU.ActiveCfg = Release|Any CPU 48 | {CDDDDC66-3820-418F-8FF4-FF1AF0A2663E}.Release|Any CPU.Build.0 = Release|Any CPU 49 | EndGlobalSection 50 | GlobalSection(SolutionProperties) = preSolution 51 | HideSolutionNode = FALSE 52 | EndGlobalSection 53 | GlobalSection(NestedProjects) = preSolution 54 | {01366446-2DDA-461E-85E8-09E9AF7F1520} = {37D31C29-4B24-4580-A72E-C72D78C62C09} 55 | {E0CF4109-B3E7-47CA-AE44-12D5F129B7EE} = {37D31C29-4B24-4580-A72E-C72D78C62C09} 56 | {0F26E210-5AA4-4369-82C4-EBF37D8DAC38} = {37D31C29-4B24-4580-A72E-C72D78C62C09} 57 | {39A2EF1C-3558-4AF8-BC7B-984B0DD8ADB3} = {37D31C29-4B24-4580-A72E-C72D78C62C09} 58 | {CDDDDC66-3820-418F-8FF4-FF1AF0A2663E} = {37D31C29-4B24-4580-A72E-C72D78C62C09} 59 | EndGlobalSection 60 | EndGlobal 61 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/src/DingtalkChatbotSdk/DingDingClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using DingtalkChatbotSdk.Models; 9 | using Newtonsoft.Json; 10 | namespace DingtalkChatbotSdk 11 | { 12 | /// 13 | /// 钉钉群机器人Client端 14 | /// 15 | public class DingDingClient 16 | { 17 | /// 18 | /// 异步发送文本信息 19 | /// 20 | /// webhook的url地址 21 | /// 文本内容 22 | /// @的手机号列表 23 | /// 是否@所有人 24 | /// 25 | public static async Task SendMessageAsync(string webHookUrl,string message, List AtMobiles = null,bool isAtAll = false) 26 | { 27 | if (string.IsNullOrWhiteSpace(message) || string.IsNullOrEmpty(webHookUrl)) 28 | { 29 | return new SendResult 30 | { 31 | ErrMsg = "参数不正确", 32 | ErrCode = -1 33 | }; 34 | } 35 | var msg = new TextMessage 36 | { 37 | Content = message, 38 | at = new AtSetting() 39 | }; 40 | if (AtMobiles != null) 41 | { 42 | msg.at.AtMobiles = AtMobiles; 43 | msg.at.IsAtAll = false; 44 | } 45 | else 46 | { 47 | if(isAtAll) msg.at.IsAtAll = true; 48 | } 49 | 50 | var json = msg.ToJson(); 51 | return await SendAsync(webHookUrl,json); 52 | } 53 | 54 | 55 | /// 56 | /// 异步发送其他类型的信息 57 | /// 58 | /// webhook的url地址 59 | /// 信息model 60 | /// 61 | public static async Task SendMessageAsync(string webHookUrl,IDingDingMessage message) 62 | { 63 | if (message == null || string.IsNullOrEmpty(webHookUrl)) 64 | { 65 | return new SendResult 66 | { 67 | ErrMsg = "参数不正确", 68 | ErrCode = -1 69 | }; 70 | } 71 | var json = message.ToJson(); 72 | return await SendAsync(webHookUrl,json); 73 | } 74 | 75 | 76 | /// 77 | /// 异步发送 78 | /// 79 | /// 80 | /// 81 | /// 82 | private static async Task SendAsync(string webHookUrl,string data) 83 | { 84 | try 85 | { 86 | string result = string.Empty; 87 | WebRequest WReq = WebRequest.Create(webHookUrl); 88 | WReq.Method = "POST"; 89 | byte[] byteArray = Encoding.UTF8.GetBytes(data); 90 | WReq.ContentType = "application/json; charset=utf-8"; 91 | using (var newStream = await WReq.GetRequestStreamAsync()) 92 | { 93 | await newStream.WriteAsync(byteArray, 0, byteArray.Length); 94 | } 95 | WebResponse WResp = await WReq.GetResponseAsync(); 96 | using (var stream = WResp.GetResponseStream()) 97 | { 98 | if (stream != null) 99 | { 100 | using (var reader = new StreamReader(stream)) 101 | { 102 | result = await reader.ReadToEndAsync(); 103 | } 104 | 105 | } 106 | } 107 | if (!string.IsNullOrEmpty(result)) 108 | { 109 | var re = JsonConvert.DeserializeObject(result); 110 | return re; 111 | } 112 | return new SendResult { ErrMsg = "", ErrCode = -1 }; 113 | } 114 | catch (Exception ex) 115 | { 116 | return new SendResult { ErrMsg = ex.Message, ErrCode = -1 }; 117 | } 118 | } 119 | } 120 | 121 | 122 | 123 | } 124 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using DingtalkChatbotSdk; 4 | using DingtalkChatbotSdk.Models; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | 7 | namespace UnitTest 8 | { 9 | [TestClass] 10 | public class UnitTest1 11 | { 12 | public static string WebHookUrl = "https://oapi.dingtalk.com/robot/send?access_token=8968f46ab77718c6f2532a3d3aba3eef3b9725594e988b76e5fc807b8aef6c35"; 13 | [TestMethod] 14 | public void TestMethod3() 15 | { 16 | var result = DingDingClient.SendMessageAsync(WebHookUrl, "测试").Result; 17 | Assert.AreEqual(result.ErrCode, 0); 18 | } 19 | 20 | [TestMethod] 21 | public void TestMethod2() 22 | { 23 | LinkMessage link = new LinkMessage 24 | { 25 | Text = "这个即将发布的新版本,创始人陈航(花名“无招”)称它为“红树林”。而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是“红树林”?", 26 | Title = "时代的火车向前开", 27 | PicUrl = "", 28 | MessageUrl = "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI" 29 | }; 30 | 31 | DingDingClient.SendMessageAsync(WebHookUrl, link).Wait(); 32 | } 33 | 34 | [TestMethod] 35 | public void TestMethod4() 36 | { 37 | IDingDingMessage msg = new MarkdownMessage 38 | { 39 | Title = "杭州天气", 40 | Text = "#### 杭州天气\n" + 41 | "> 9度,西北风1级,空气良89,相对温度73%\n\n" + 42 | "> ![screenshot](http://image.jpg)\n" + 43 | "> ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \n" 44 | }; 45 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 46 | } 47 | 48 | [TestMethod] 49 | public void TestMethod5() 50 | { 51 | IDingDingMessage msg = new FullActionCardMessage 52 | { 53 | Title = "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", 54 | Text = "![screenshot](@lADOpwk3K80C0M0FoA) ### 乔布斯 20 年前想打造的苹果咖啡厅 Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", 55 | HideAvatar = 0, 56 | BtnOrientation = 0, 57 | SingleTitle = "阅读全文", 58 | SingleURL = "https://www.dingtalk.com/" 59 | 60 | }; 61 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 62 | } 63 | 64 | [TestMethod] 65 | public void TestMethod6() 66 | { 67 | IDingDingMessage msg = new SingleActionCardMessage 68 | { 69 | Title = "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", 70 | Text = "![screenshot](@lADOpwk3K80C0M0FoA) ### 乔布斯 20 年前想打造的苹果咖啡厅 Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", 71 | HideAvatar = 0, 72 | BtnOrientation = 0, 73 | SingleActionCardButtons = new List 74 | { 75 | new SingleActionCardButton 76 | { 77 | Title = "内容不错", 78 | ActionURL = "https://www.dingtalk.com/" 79 | }, 80 | new SingleActionCardButton 81 | { 82 | Title = "不感兴趣", 83 | ActionURL = "https://www.dingtalk.com/" 84 | } 85 | } 86 | 87 | }; 88 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 89 | } 90 | 91 | 92 | [TestMethod] 93 | public void TestMethod7() 94 | { 95 | IDingDingMessage msg = new FeedCardMessage 96 | { 97 | FeedCardItems = new List 98 | { 99 | new FeedCardItem 100 | { 101 | Title = "时代的火车向前开", 102 | MessageURL = "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI", 103 | PicURL = "https://www.dingtalk.com/" 104 | }, 105 | new FeedCardItem 106 | { 107 | Title = "时代的火车向前开2", 108 | MessageURL = "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI", 109 | PicURL = "https://www.dingtalk.com/" 110 | } 111 | } 112 | 113 | }; 114 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest451/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using DingtalkChatbotSdk; 4 | using DingtalkChatbotSdk.Models; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | 7 | namespace UnitTest451 8 | { 9 | [TestClass] 10 | public class UnitTest1 11 | { 12 | public static string WebHookUrl = "https://oapi.dingtalk.com/robot/send?access_token=8968f46ab77718c6f2532a3d3aba3eef3b9725594e988b76e5fc807b8aef6c35"; 13 | [TestMethod] 14 | public void TestMethod3() 15 | { 16 | var result = DingDingClient.SendMessageAsync(WebHookUrl, "测试").Result; 17 | Assert.AreEqual(result.ErrCode, 0); 18 | } 19 | 20 | [TestMethod] 21 | public void TestMethod2() 22 | { 23 | LinkMessage link = new LinkMessage 24 | { 25 | Text = "这个即将发布的新版本,创始人陈航(花名“无招”)称它为“红树林”。而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是“红树林”?", 26 | Title = "时代的火车向前开", 27 | PicUrl = "", 28 | MessageUrl = "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI" 29 | }; 30 | 31 | DingDingClient.SendMessageAsync(WebHookUrl, link).Wait(); 32 | } 33 | 34 | [TestMethod] 35 | public void TestMethod4() 36 | { 37 | IDingDingMessage msg = new MarkdownMessage 38 | { 39 | Title = "杭州天气", 40 | Text = "#### 杭州天气\n" + 41 | "> 9度,西北风1级,空气良89,相对温度73%\n\n" + 42 | "> ![screenshot](http://image.jpg)\n" + 43 | "> ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \n" 44 | }; 45 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 46 | } 47 | 48 | [TestMethod] 49 | public void TestMethod5() 50 | { 51 | IDingDingMessage msg = new FullActionCardMessage 52 | { 53 | Title = "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", 54 | Text = "![screenshot](@lADOpwk3K80C0M0FoA) ### 乔布斯 20 年前想打造的苹果咖啡厅 Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", 55 | HideAvatar = 0, 56 | BtnOrientation = 0, 57 | SingleTitle = "阅读全文", 58 | SingleURL = "https://www.dingtalk.com/" 59 | 60 | }; 61 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 62 | } 63 | 64 | [TestMethod] 65 | public void TestMethod6() 66 | { 67 | IDingDingMessage msg = new SingleActionCardMessage 68 | { 69 | Title = "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", 70 | Text = "![screenshot](@lADOpwk3K80C0M0FoA) ### 乔布斯 20 年前想打造的苹果咖啡厅 Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", 71 | HideAvatar = 0, 72 | BtnOrientation = 0, 73 | SingleActionCardButtons = new List 74 | { 75 | new SingleActionCardButton 76 | { 77 | Title = "内容不错", 78 | ActionURL = "https://www.dingtalk.com/" 79 | }, 80 | new SingleActionCardButton 81 | { 82 | Title = "不感兴趣", 83 | ActionURL = "https://www.dingtalk.com/" 84 | } 85 | } 86 | 87 | }; 88 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 89 | } 90 | 91 | 92 | [TestMethod] 93 | public void TestMethod7() 94 | { 95 | IDingDingMessage msg = new FeedCardMessage 96 | { 97 | FeedCardItems = new List 98 | { 99 | new FeedCardItem 100 | { 101 | Title = "时代的火车向前开", 102 | MessageURL = "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI", 103 | PicURL = "https://www.dingtalk.com/" 104 | }, 105 | new FeedCardItem 106 | { 107 | Title = "时代的火车向前开2", 108 | MessageURL = "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI", 109 | PicURL = "https://www.dingtalk.com/" 110 | } 111 | } 112 | 113 | }; 114 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest45/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using DingtalkChatbotSdk; 4 | using DingtalkChatbotSdk.Models; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | 7 | namespace UnitTest45 8 | { 9 | [TestClass] 10 | public class UnitTest1 11 | { 12 | public static string WebHookUrl = "https://oapi.dingtalk.com/robot/send?access_token=8968f46ab77718c6f2532a3d3aba3eef3b9725594e988b76e5fc807b8aef6c35"; 13 | [TestMethod] 14 | public void TestMethod3() 15 | { 16 | var result = DingDingClient.SendMessageAsync(WebHookUrl, "测试",isAtAll:true).Result; 17 | Assert.AreEqual(result.ErrCode, 0); 18 | } 19 | 20 | [TestMethod] 21 | public void TestMethod2() 22 | { 23 | LinkMessage link = new LinkMessage 24 | { 25 | Text = "这个即将发布的新版本,创始人陈航(花名“无招”)称它为“红树林”。而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是“红树林”?", 26 | Title = "时代的火车向前开", 27 | PicUrl = "", 28 | MessageUrl = "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI" 29 | }; 30 | 31 | DingDingClient.SendMessageAsync(WebHookUrl, link).Wait(); 32 | } 33 | 34 | [TestMethod] 35 | public void TestMethod4() 36 | { 37 | IDingDingMessage msg = new MarkdownMessage 38 | { 39 | Title = "杭州天气", 40 | Text = "#### 杭州天气\n" + 41 | "> 9度,西北风1级,空气良89,相对温度73%\n\n" + 42 | "> ![screenshot](http://image.jpg)\n" + 43 | "> ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \n" 44 | }; 45 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 46 | } 47 | 48 | [TestMethod] 49 | public void TestMethod5() 50 | { 51 | IDingDingMessage msg = new FullActionCardMessage 52 | { 53 | Title = "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", 54 | Text = "![screenshot](@lADOpwk3K80C0M0FoA) ### 乔布斯 20 年前想打造的苹果咖啡厅 Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", 55 | HideAvatar = 0, 56 | BtnOrientation = 0, 57 | SingleTitle = "阅读全文", 58 | SingleURL = "https://www.dingtalk.com/" 59 | 60 | }; 61 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 62 | } 63 | 64 | [TestMethod] 65 | public void TestMethod6() 66 | { 67 | IDingDingMessage msg = new SingleActionCardMessage 68 | { 69 | Title = "乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身", 70 | Text = "![screenshot](@lADOpwk3K80C0M0FoA) ### 乔布斯 20 年前想打造的苹果咖啡厅 Apple Store 的设计正从原来满满的科技感走向生活化,而其生活化的走向其实可以追溯到 20 年前苹果一个建立咖啡馆的计划", 71 | HideAvatar = 0, 72 | BtnOrientation = 0, 73 | SingleActionCardButtons = new List 74 | { 75 | new SingleActionCardButton 76 | { 77 | Title = "内容不错", 78 | ActionURL = "https://www.dingtalk.com/" 79 | }, 80 | new SingleActionCardButton 81 | { 82 | Title = "不感兴趣", 83 | ActionURL = "https://www.dingtalk.com/" 84 | } 85 | } 86 | 87 | }; 88 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 89 | } 90 | 91 | 92 | [TestMethod] 93 | public void TestMethod7() 94 | { 95 | IDingDingMessage msg = new FeedCardMessage 96 | { 97 | FeedCardItems = new List 98 | { 99 | new FeedCardItem 100 | { 101 | Title = "时代的火车向前开", 102 | MessageURL = "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI", 103 | PicURL = "https://www.dingtalk.com/" 104 | }, 105 | new FeedCardItem 106 | { 107 | Title = "时代的火车向前开2", 108 | MessageURL = "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI", 109 | PicURL = "https://www.dingtalk.com/" 110 | } 111 | } 112 | 113 | }; 114 | DingDingClient.SendMessageAsync(WebHookUrl, msg).Wait(); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest45/UnitTest45.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {0F26E210-5AA4-4369-82C4-EBF37D8DAC38} 7 | Library 8 | Properties 9 | UnitTest45 10 | UnitTest45 11 | v4.5 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | ..\packages\DingtalkChatbotSdk.1.0.1\lib\net45\DingtalkChatbotSdk.dll 40 | True 41 | 42 | 43 | 44 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 45 | True 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | False 77 | 78 | 79 | False 80 | 81 | 82 | False 83 | 84 | 85 | False 86 | 87 | 88 | 89 | 90 | 91 | 92 | 99 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest451/UnitTest451.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {39A2EF1C-3558-4AF8-BC7B-984B0DD8ADB3} 7 | Library 8 | Properties 9 | UnitTest451 10 | UnitTest451 11 | v4.5.1 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | ..\packages\DingtalkChatbotSdk.1.0.1\lib\net451\DingtalkChatbotSdk.dll 41 | True 42 | 43 | 44 | 45 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 46 | True 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | False 78 | 79 | 80 | False 81 | 82 | 83 | False 84 | 85 | 86 | False 87 | 88 | 89 | 90 | 91 | 92 | 93 | 100 | -------------------------------------------------------------------------------- /DingtalkChatbotSdk/UnitTest/UnitTest40.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {E0CF4109-B3E7-47CA-AE44-12D5F129B7EE} 7 | Library 8 | Properties 9 | UnitTest40 10 | UnitTest40 11 | v4.0 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | ..\packages\DingtalkChatbotSdk.1.0.1\lib\net40\DingtalkChatbotSdk.dll 41 | True 42 | 43 | 44 | 45 | ..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll 46 | True 47 | 48 | 49 | ..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll 50 | True 51 | 52 | 53 | ..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll 54 | True 55 | 56 | 57 | ..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll 58 | True 59 | 60 | 61 | 62 | 63 | 64 | ..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll 65 | True 66 | 67 | 68 | 69 | ..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Runtime.dll 70 | True 71 | 72 | 73 | 74 | ..\packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll 75 | True 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | False 103 | 104 | 105 | False 106 | 107 | 108 | False 109 | 110 | 111 | False 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 130 | --------------------------------------------------------------------------------