加入VS项目

master
bicijinlian 5 years ago
parent 46e12a6ff1
commit 2765298606

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.705
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tianyi.DingtalkRobotKit", "Tianyi.DingtalkRobotKit\Tianyi.DingtalkRobotKit.csproj", "{267E50DE-B16A-41D0-888F-A5F369DCA9EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tianyi.DingtalkRobotKit.Test", "Tianyi.DingtalkRobotKit.Test\Tianyi.DingtalkRobotKit.Test.csproj", "{B203751E-0266-4B10-934E-08944B105B58}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{267E50DE-B16A-41D0-888F-A5F369DCA9EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{267E50DE-B16A-41D0-888F-A5F369DCA9EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{267E50DE-B16A-41D0-888F-A5F369DCA9EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{267E50DE-B16A-41D0-888F-A5F369DCA9EB}.Release|Any CPU.Build.0 = Release|Any CPU
{B203751E-0266-4B10-934E-08944B105B58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B203751E-0266-4B10-934E-08944B105B58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B203751E-0266-4B10-934E-08944B105B58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B203751E-0266-4B10-934E-08944B105B58}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {781E339B-7C68-45CB-A43D-EEEE63AE295F}
EndGlobalSection
EndGlobal

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
namespace Tianyi.DingtalkRobotKit.Test
{
public class SendMessageTest
{
[Fact]
public void Test()
{
var textMsg = new TextMessage("明天是美好的一天");
textMsg.at.isAtAll = true;
var result = SendMessage.Send<TextMessage>(textMsg);
Assert.Equal(0, result.errcode);
}
}
}

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="RestSharp" Version="106.6.10" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tianyi.DingtalkRobotKit\Tianyi.DingtalkRobotKit.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,14 @@
using System;
using Xunit;
namespace Tianyi.DingtalkRobotKit.Test
{
public class UseXunit
{
[Fact]
public void Test1()
{
Assert.True(true,"使用Xunit进行单元测试");
}
}
}

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Tianyi.DingtalkRobotKit
{
/// <summary>
/// 消息基类
/// </summary>
public abstract class MessageBase
{
public MessageBase()
{
at = new at();
}
public abstract string msgtype { get;}
public at at { get; set; }
public abstract string ToJson();
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Tianyi.DingtalkRobotKit
{
/// <summary>
/// 消息发送返回值
/// </summary>
public class MessageResult
{
/// <summary>
/// 结果代码
/// 0 成功,其它均失败
/// </summary>
public int errcode { get; set; }
/// <summary>
/// 结果说明
/// </summary>
public string errmsg { get; set; }
}
}

@ -0,0 +1,46 @@
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;
}
}
}

@ -0,0 +1,49 @@
using Newtonsoft.Json;
using System;
namespace Tianyi.DingtalkRobotKit
{
/// <summary>
/// 文本消息
/// </summary>
public class TextMessage : MessageBase
{
public TextMessage(TextOption option) :base()
{
this.text = option;
}
public TextMessage(string message) : base()
{
var option = new TextOption()
{
content = message
};
this.text = option;
}
public TextOption text { get; set; }
/// <summary>
/// 消息类型
/// </summary>
public override string msgtype { get => "text"; }
/// <summary>
/// 转换为json字符串
/// </summary>
public override string ToJson()
{
var meaasge = new
{
msgtype = this.msgtype,
text = this.text,
at = this.at
};
string messageJson = JsonConvert.SerializeObject(meaasge);
return messageJson;
}
}
}

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Tianyi.DingtalkRobotKit
{
public class TextOption
{
public string content { get; set; }
}
}

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="RestSharp" Version="106.6.10" />
</ItemGroup>
</Project>

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Tianyi.DingtalkRobotKit
{
public class at
{
public at()
{
atMobiles = new List<string>();
isAtAll = false;
}
public List<string> atMobiles { get; set; }
public bool isAtAll { get; set; }
}
}
Loading…
Cancel
Save