80 lines
3.1 KiB
C#
80 lines
3.1 KiB
C#
using System.Net.Http.Json;
|
||
using WGShare.Domain.DTOs.AgoraCallback;
|
||
using WGShare.Domain.Entities;
|
||
|
||
namespace WGShare.Domain.FriendlyException
|
||
{
|
||
/// <summary>
|
||
/// 异常通知
|
||
/// </summary>
|
||
public class ExceptionNotice
|
||
{
|
||
private static HttpClient httpClient = new HttpClient()
|
||
{
|
||
BaseAddress = new Uri("https://oapi.dingtalk.com/robot/send?access_token=6ddafcada8f44f4bad4a7314c4d9bd19a895ded0a1ba1afdaff5dd01a5af6781"),
|
||
};
|
||
|
||
/// <summary>
|
||
/// 发送异常信息
|
||
/// </summary>
|
||
/// <param name="exp">异常</param>
|
||
/// <param name="expSrc">异常来源(用于显示)</param>
|
||
/// <returns></returns>
|
||
public static async Task<bool> SendAsync(Exception exp, string expSrc)
|
||
{
|
||
#if DEBUG
|
||
Console.WriteLine("*************** Excpetion ***************");
|
||
Console.WriteLine(exp.Message, exp);
|
||
Console.WriteLine("*************** Excpetion ***************");
|
||
return true;
|
||
#endif
|
||
|
||
var reponse = await httpClient.PostAsync(string.Empty, JsonContent.Create(new
|
||
{
|
||
msgtype = "markdown",
|
||
markdown = new
|
||
{
|
||
title = "WGShare异常",
|
||
text = $"WGShare异常.描述:{exp.Message}\n详情:{exp}"
|
||
},
|
||
}));
|
||
return reponse.IsSuccessStatusCode;
|
||
|
||
}
|
||
|
||
public static async Task JoinAsync(EventBody eventBody, Room roomInfo)
|
||
{
|
||
// 获取当前的日期
|
||
DateTime today = DateTime.Today;
|
||
|
||
// 定义东八区的时区信息
|
||
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time");
|
||
|
||
// 创建东八区今天00:00:01的DateTime对象
|
||
DateTime startOfDayLocal = new DateTime(today.Year, today.Month, today.Day, 0, 0, 1, DateTimeKind.Unspecified);
|
||
|
||
// 创建东八区今天23:59:00的DateTime对象
|
||
DateTime endOfDayLocal = new DateTime(today.Year, today.Month, today.Day, 23, 59, 0, DateTimeKind.Unspecified);
|
||
|
||
// 将时间转换为UTC
|
||
DateTimeOffset startOfDayUtc = TimeZoneInfo.ConvertTimeToUtc(startOfDayLocal, timeZoneInfo);
|
||
DateTimeOffset endOfDayUtc = TimeZoneInfo.ConvertTimeToUtc(endOfDayLocal, timeZoneInfo);
|
||
|
||
// 获取Unix时间戳(秒)
|
||
long startTimestamp = startOfDayUtc.ToUnixTimeSeconds();
|
||
long endTimestamp = endOfDayUtc.ToUnixTimeSeconds();
|
||
|
||
var reponse = await httpClient.PostAsync(string.Empty, JsonContent.Create(new
|
||
{
|
||
msgtype = "markdown",
|
||
markdown = new
|
||
{
|
||
title = "有人入会通知",
|
||
text = $"有人进入会议室了,学校:{roomInfo.TenantName},会议室名称:{roomInfo.RoomName},会议号:{eventBody.payload.channelName}. \r\n 点击查看:https://analytics-lab.agora.io/analytics/call/search?projectId=0tOpVUrmf&fromTs={startTimestamp}&toTs={endTimestamp}"
|
||
},
|
||
}));
|
||
}
|
||
}
|
||
|
||
}
|