using DS.Module.Core; using DS.Module.SqlSugar; using DS.Module.UserModule; using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Interface; using DS.WMS.Core.Sys.Entity; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using NLog; using SqlSugar; using System; using System.Collections.Generic; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using DS.Module.Core.Extensions; using LogicExtensions; using DS.Module.Core.Helpers; using Newtonsoft.Json.Linq; using DS.Module.Core.Data; using DS.WMS.Core.Sys.Interface; using DS.WMS.Core.Code.Method; using DS.WMS.Core.Code.Interface; using System.Text.Json.Nodes; namespace DS.WMS.Core.Utils { public class DingTalkGroupHelper : IDingTalkGroupHelper { private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger(); private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; private readonly IUser user; private readonly ISaasDbService saasService; private readonly IConfigService _configService; private readonly ICodeThirdPartyService _codeThirdPartyService; public DingTalkGroupHelper(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _configService = serviceProvider.GetRequiredService(); _codeThirdPartyService = serviceProvider.GetRequiredService(); db = _serviceProvider.GetRequiredService(); } /// /// 发送钉钉客服群组消息通知 /// /// 钉钉群配置code /// 标题 /// 内容 public async Task SendDingTalkGroupMessage(string code, string title, string content) { var dingdingCfg = db.Queryable().Filter(null, true) .Where(x => x.Code == code && x.TenantId == 1288018625843826688).First(); var postdata = new { text = new { content = $"【{title}】\r\n{content}\r\n----{dingdingCfg.Note}" }, msgtype = "text" }; Logger.Log(NLog.LogLevel.Info, $"准备发送钉钉消息:{postdata.ToJsonString()}"); var rtn = RequestHelper.Post(JsonConvert.SerializeObject(postdata), dingdingCfg.Value); Logger.Log(NLog.LogLevel.Info, $"发送钉钉消息返回:{rtn}"); } /// /// 发送钉钉客服群组消息通知 /// /// 钉钉群配置code /// 标题 /// 内容 /// @所有人 /// @手机号数组 /// @用户id数组 public async Task SendDingTalkGroupMessage(string code, string title, string content, bool atAll, string[] atMobiles, string[] atUserIds) { var dingdingCfg = db.Queryable().Filter(null, true) .Where(x => x.Code == code && x.TenantId == 1288018625843826688).First(); var postdata = new { text = new { content = $"【{title}】\r\n{content}\r\n----{dingdingCfg.Note}" }, msgtype = "text", at = new { isAtAll = atAll, atMobiles = atMobiles, atUserIds = atUserIds } }; Logger.Log(NLog.LogLevel.Info, $"准备发送钉钉消息:{postdata.ToJsonString()}"); var rtn = RequestHelper.Post(JsonConvert.SerializeObject(postdata), dingdingCfg.Value); Logger.Log(NLog.LogLevel.Info, $"发送钉钉消息返回:{rtn}"); } } public interface IDingTalkGroupHelper { /// /// 发送钉钉客服群组消息通知 /// /// 钉钉群配置code /// 标题 /// 内容 Task SendDingTalkGroupMessage(string code, string title, string content); /// /// 发送钉钉客服群组消息通知 /// /// 钉钉群配置code /// 标题 /// 内容 /// @所有人 /// @手机号数组 /// @用户id数组 Task SendDingTalkGroupMessage(string code, string title, string content, bool atAll, string[] atMobiles, string[] atUserIds); } }