using Furion; using Furion.EventBus; using Furion.RemoteRequest.Extensions; using Microsoft.Extensions.Logging; using Myshipping.Core.Entity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Myshipping.Core { public class DingTalkSubscriber : IEventSubscriber { private readonly ILogger _logger; public DingTalkSubscriber(ILogger logger) { _logger = logger; } [EventSubscribe("DingTalkGroup:Send")] public async Task SendDingTalkGroup(EventHandlerExecutingContext context) { _logger.LogInformation($"收到钉钉发送消息订阅消息:{context.Source.Payload.ToJsonString()}"); var rep = App.GetService>(); dynamic obj = context.Source.Payload; string code = obj.code; var cfg = rep.FirstOrDefault(x => x.Code == code); var postdata = new { text = new { content = $"【{ obj.title}】\r\n{obj.content}\r\n----{cfg.Keyword}" }, msgtype = "text" }; _logger.LogInformation($"准备发送钉钉消息:{postdata.ToJsonString()}"); var rtn = await cfg.Url.SetBody(postdata).PostAsStringAsync(); _logger.LogInformation($"发送钉钉消息返回:{rtn}"); } } }