com.alicizax.unity/Runtime/Base/Log/WebHookUtil.cs
陈思海 bf0d8340af init
2025-02-07 16:04:12 +08:00

45 lines
1.4 KiB
C#

using System;
using System.Net.Http;
using System.Text;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace AlicizaX.Runtime
{
public static class WebHookUtils
{
private static readonly HttpClient httpClient = new HttpClient();
private static readonly string WebHookKey = "https://open.feishu.cn/open-apis/bot/v2/hook/e9cdddcb-8ae0-4390-98d7-42e2c29efc00";
public static async UniTask SendLogToServerAsync(string logMessage)
{
string at = @"<at user_id=""all"">所有人</at> ";
try
{
// 创建请求体
var payload = new
{
msg_type = "text",
content = new
{
text = at+logMessage
}
};
string json = Utility.Json.ToJson(payload);
using (var content = new StringContent(json, Encoding.UTF8, "application/json"))
{
HttpResponseMessage response = await httpClient.PostAsync(WebHookKey, content).AsUniTask();
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
}
}
catch (Exception ex)
{
Debug.LogError($"Failed to send log to server: {ex.Message}");
}
}
}
}