public void Initialize() { //日志函数 void LogAction(string tag, string message) { if (tag.Equals("error", StringComparison.CurrentCultureIgnoreCase)) { Logger.Error(message); } else { Logger.Debug(message); } } try { //阿里云短信设置 AliyunSmsBuilder.Create() //设置日志记录 .WithLoggerAction(LogAction) .SetSettingsFunc(() => GetConfigFromConfigOrSettingsByKey <AliyunSmsSettting>().Result).Build(); SmsService = new AliyunSmsService(); } catch (Exception ex) { Logger.Error("阿里云短信未配置或者配置错误!", ex); } }
public void Initialize() { //日志函数 void LogAction(string tag, string message) { if (tag.Equals("error", StringComparison.CurrentCultureIgnoreCase)) { Logger.Error(message); } else { Logger.Debug(message); } } try { if (Convert.ToBoolean(SettingManager .GetSettingValueAsync(AppSettings.AliSmsCodeManagement.IsEnabled).Result)) { //阿里云短信设置 AliyunSmsBuilder.Create() //设置日志记录 .WithLoggerAction(LogAction) .SetSettingsFunc(() => new AliyunSmsSettting() { AccessKeyId = SettingManager.GetSettingValueAsync(AppSettings.AliSmsCodeManagement.AccessKeyId) .Result, AccessKeySecret = SettingManager.GetSettingValueAsync(AppSettings.AliSmsCodeManagement.AccessKeySecret) .Result, SignName = SettingManager.GetSettingValueAsync(AppSettings.AliSmsCodeManagement.SignName) .Result, TemplateCode = SettingManager.GetSettingValueAsync(AppSettings.AliSmsCodeManagement.TemplateCode) .Result, TemplateParam = SettingManager.GetSettingValueAsync(AppSettings.AliSmsCodeManagement.TemplateParam) .Result }).Build(); } else { //阿里云短信设置 AliyunSmsBuilder.Create() //设置日志记录 .WithLoggerAction(LogAction) .SetSettingsFunc(() => new AliyunSmsSettting(AppConfigurationAccessor?.Configuration)).Build(); } SmsService = new AliyunSmsService(); } catch (Exception ex) { Logger.Error("阿里云短信未配置或者配置错误!", ex); } }