一款使用C#/.NETCORE6.0 的钉钉sdk
电脑安装登录钉钉,随便找两个朋友,新建一个群(不用经过他们允许),然后新建一个 群机器人,再删除你的两个朋友就可以了,取得 webhook 和 secret.
成功获得AccessToken和UserSecret。
配置AccessToken和UserSecret到下图指定位置
根据单元测试配置代码
// IOC
private ServiceCollection _services;
private string _accessToken, _secret;
private IConfigurationRoot _configuration;
public UnitTests()
{
// 依赖注入
_services = new ServiceCollection();
_services.AddScoped<IDingtalkService, DingtalkService>();
// Read Secret
_configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json")
.AddUserSecrets<UnitTests>()
.Build();
_accessToken = _configuration["DingDing:accessToken"];
_secret = _configuration["DingDing:secret"];
}
[TestMethod]
public async Task TestMethod()
{
using (var sp = _services.BuildServiceProvider())
{
var dingtalkService = sp.GetRequiredService<IDingtalkService>();
var response = await dingtalkService.SendNotificationAsync("test123",_accessToken,_secret);
Console.WriteLine(response.Content);
Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK);
}
}