|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using NPin.Framework.SettingManagement.Domain;
|
|
|
|
|
using NPin.Framework.Upms.Domain.Settings;
|
|
|
|
@ -12,25 +13,25 @@ namespace NPin.Framework.Upms.Domain.Managers;
|
|
|
|
|
|
|
|
|
|
public class SmsManager : DomainService
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<SmsManager> _logger;
|
|
|
|
|
public ILogger<SmsManager> Logger { get; set; }
|
|
|
|
|
|
|
|
|
|
private readonly ISettingManager _settingManager;
|
|
|
|
|
|
|
|
|
|
private readonly IEnumerable<ISms> _smsProviders;
|
|
|
|
|
|
|
|
|
|
public SmsManager(ILogger<SmsManager> logger, ISettingManager settingManager, IEnumerable<ISms> smsProviders)
|
|
|
|
|
public SmsManager(ISettingManager settingManager, IEnumerable<ISms> smsProviders)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
Logger = NullLogger<SmsManager>.Instance;
|
|
|
|
|
_settingManager = settingManager;
|
|
|
|
|
_smsProviders = smsProviders;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<SmsConfigModel> GetSmsConfigModelAsync()
|
|
|
|
|
{
|
|
|
|
|
var configJson = await _settingManager.GetOrNullUpmsAsync(ConfigConst.SmsConfigModelKey);
|
|
|
|
|
var settingsJson = await _settingManager.GetOrNullUpmsAsync(ConfigConst.SmsSettingsKey);
|
|
|
|
|
var providersJson = await _settingManager.GetOrNullUpmsAsync(ConfigConst.SmsProvidersKey);
|
|
|
|
|
var templateJson = await _settingManager.GetOrNullUpmsAsync(ConfigConst.SmsTemplatesKey);
|
|
|
|
|
var configJson = await _settingManager.GetOrNullUpmsAsync(ConfigKeyConst.SmsConfigModel);
|
|
|
|
|
var settingsJson = await _settingManager.GetOrNullUpmsAsync(ConfigKeyConst.SmsSettings);
|
|
|
|
|
var providersJson = await _settingManager.GetOrNullUpmsAsync(ConfigKeyConst.SmsProviders);
|
|
|
|
|
var templateJson = await _settingManager.GetOrNullUpmsAsync(ConfigKeyConst.SmsTemplates);
|
|
|
|
|
|
|
|
|
|
var ret = JsonConvert.DeserializeObject<SmsConfigModel>(configJson ?? string.Empty) ?? new SmsConfigModel();
|
|
|
|
|
|
|
|
|
@ -71,7 +72,7 @@ public class SmsManager : DomainService
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, $"短信发送失败: {ex.Message}");
|
|
|
|
|
Logger.LogError(ex, $"短信发送失败: {ex.Message}");
|
|
|
|
|
throw new UserFriendlyException($"短信发送失败: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|