50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
|
|
using System;
|
|||
|
|
using System.Net.Http;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using Etor.Infrastructure.Common;
|
|||
|
|
using Etor.Infrastructure.Extension;
|
|||
|
|
using Etor.Infrastructure.Serializer;
|
|||
|
|
using Etor.Infrastructure.WebApi;
|
|||
|
|
|
|||
|
|
namespace ScheduledTaskClient
|
|||
|
|
{
|
|||
|
|
public class ScheduledTaskHttpClient
|
|||
|
|
{
|
|||
|
|
private IHttpClientFactory _httpClientFactory;
|
|||
|
|
|
|||
|
|
internal static string _BaseUrl = "";
|
|||
|
|
|
|||
|
|
public ScheduledTaskHttpClient(IHttpClientFactory httpClientFactory)
|
|||
|
|
{
|
|||
|
|
_httpClientFactory = httpClientFactory;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string BaseUrl => _BaseUrl;
|
|||
|
|
|
|||
|
|
private HttpClient CreateHttpClient()
|
|||
|
|
{
|
|||
|
|
return _httpClientFactory.CreateClient();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 设置计划消息
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="message"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public async Task<ApiResult> SetScheduledMmessage(ScheduledMessage message)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var res = await CreateHttpClient()
|
|||
|
|
.PostAsJsonGetString("/api/scheduledtask/v1/message/Set", message);
|
|||
|
|
|
|||
|
|
return res.FromJsonTo<ApiResult>();
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
LogHelper.Error("设置计划消息失败", $"{e}\n消息内容:\n{message.ToJson(true)}");
|
|||
|
|
return new ApiResult(ResultCode.C_UNKNOWN_ERROR);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|