From 60b515b86b7668e755d9aebcde4364bf45324fce Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Fri, 5 Mar 2021 09:52:17 +0800 Subject: [PATCH] add ISteamService.SetCurrentUser --- .../Models/AlibabaCloud/SmsOptions.cs | 7 +- .../Models/NetEaseCloud/SmsOptions.cs | 9 +- .../Models/_21VianetBlueCloud/SmsOptions.cs | 41 +++++++++ .../Services/ISmsSender.cs | 11 +-- .../AlibabaCloud/SmsSenderProvider.cs | 3 +- .../NetEaseCloud/SmsSenderProvider.cs | 3 +- .../_21VianetBlueCloud/SmsSenderProvider.cs | 85 +++++++++++++++++++ .../_21VianetBlueCloud/SmsSenderProvider.cs | 30 ------- .../LinuxDesktopPlatformServiceImpl.cs | 2 + .../MacDesktopPlatformServiceImpl.cs | 2 + .../WindowsDesktopPlatformServiceImpl.cs | 5 ++ .../Services/IDesktopPlatformService.cs | 3 + .../Services/ISteamService.cs | 6 ++ .../Implementation/SteamServiceImpl.cs | 2 + 14 files changed, 165 insertions(+), 44 deletions(-) create mode 100644 System.Application.Services.SmsSender/Models/_21VianetBlueCloud/SmsOptions.cs rename System.Application.Services.SmsSender/Services/{ => Implementation}/AlibabaCloud/SmsSenderProvider.cs (98%) rename System.Application.Services.SmsSender/Services/{ => Implementation}/NetEaseCloud/SmsSenderProvider.cs (98%) create mode 100644 System.Application.Services.SmsSender/Services/Implementation/_21VianetBlueCloud/SmsSenderProvider.cs delete mode 100644 System.Application.Services.SmsSender/Services/_21VianetBlueCloud/SmsSenderProvider.cs diff --git a/System.Application.Services.SmsSender/Models/AlibabaCloud/SmsOptions.cs b/System.Application.Services.SmsSender/Models/AlibabaCloud/SmsOptions.cs index a7947930c..eac93660d 100644 --- a/System.Application.Services.SmsSender/Models/AlibabaCloud/SmsOptions.cs +++ b/System.Application.Services.SmsSender/Models/AlibabaCloud/SmsOptions.cs @@ -1,6 +1,6 @@ namespace System.Application.Models.AlibabaCloud { - public class SmsOptions + public class SmsOptions : IExplicitHasValue { /// /// 平台分配的appkey @@ -28,7 +28,10 @@ { return !string.IsNullOrWhiteSpace(AccessKeyId) && !string.IsNullOrWhiteSpace(AccessKeySecret) && - !string.IsNullOrWhiteSpace(SignName); + !string.IsNullOrWhiteSpace(SignName) && + Templates.Any_Nullable(); } + + bool IExplicitHasValue.ExplicitHasValue() => IsValid(); } } \ No newline at end of file diff --git a/System.Application.Services.SmsSender/Models/NetEaseCloud/SmsOptions.cs b/System.Application.Services.SmsSender/Models/NetEaseCloud/SmsOptions.cs index 50ce0f0d4..508e8c905 100644 --- a/System.Application.Services.SmsSender/Models/NetEaseCloud/SmsOptions.cs +++ b/System.Application.Services.SmsSender/Models/NetEaseCloud/SmsOptions.cs @@ -1,6 +1,6 @@ namespace System.Application.Models.NetEaseCloud { - public class SmsOptions + public class SmsOptions : IExplicitHasValue { /// /// 开发者平台分配的appkey @@ -15,12 +15,15 @@ /// /// 开发者平台分配的模板标志 /// - public SmsOptionsTemplateId[]? Templates { get; set; } + public SmsOptionsTemplateId[]? Templates { get; set; } public bool IsValid() { return !string.IsNullOrWhiteSpace(AppKey) && - !string.IsNullOrWhiteSpace(AppSecret); + !string.IsNullOrWhiteSpace(AppSecret) && + Templates.Any_Nullable(); } + + bool IExplicitHasValue.ExplicitHasValue() => IsValid(); } } \ No newline at end of file diff --git a/System.Application.Services.SmsSender/Models/_21VianetBlueCloud/SmsOptions.cs b/System.Application.Services.SmsSender/Models/_21VianetBlueCloud/SmsOptions.cs new file mode 100644 index 000000000..741e8e8b1 --- /dev/null +++ b/System.Application.Services.SmsSender/Models/_21VianetBlueCloud/SmsOptions.cs @@ -0,0 +1,41 @@ +namespace System.Application.Models._21VianetBlueCloud +{ + public class SmsOptions : IExplicitHasValue + { + /// + /// ccs account name + /// + public string? Account { get; set; } + + /// + /// 密钥名称 + /// + public string? KeyName { get; set; } + + /// + /// 密钥 + /// + public string? KeyValue { get; set; } + + /// + /// 下发扩展码,两位纯数字 + /// + public string ExtendCode { get; set; } = "08"; + + /// + /// 开发者平台分配的模板标志 + /// + public SmsOptionsTemplateId[]? Templates { get; set; } + + public bool IsValid() + { + return !string.IsNullOrWhiteSpace(Account) && + !string.IsNullOrWhiteSpace(ExtendCode) && + !string.IsNullOrWhiteSpace(KeyName) && + !string.IsNullOrWhiteSpace(KeyValue) && + Templates.Any_Nullable(); + } + + bool IExplicitHasValue.ExplicitHasValue() => IsValid(); + } +} \ No newline at end of file diff --git a/System.Application.Services.SmsSender/Services/ISmsSender.cs b/System.Application.Services.SmsSender/Services/ISmsSender.cs index 7591fce53..2132079a6 100644 --- a/System.Application.Services.SmsSender/Services/ISmsSender.cs +++ b/System.Application.Services.SmsSender/Services/ISmsSender.cs @@ -29,9 +29,9 @@ namespace System.Application.Services /// /// 发送短信验证码 /// - /// 收信人手机号码。 - /// 发送的短信内容。 - /// 发送短信用途。 + /// 收信人手机号码 + /// 发送的短信内容 + /// 发送短信用途 /// /// Task SendSmsAsync(string number, string message, int type, CancellationToken cancellationToken = default); @@ -39,8 +39,9 @@ namespace System.Application.Services /// /// 校验短信验证码,某些平台要求校验短信也要调用他提供的接口 /// - /// 收信人手机号码。 - /// 短信验证码内容。 + /// 收信人手机号码 + /// 短信验证码内容 + /// /// Task CheckSmsAsync(string number, string message, CancellationToken cancellationToken = default); diff --git a/System.Application.Services.SmsSender/Services/AlibabaCloud/SmsSenderProvider.cs b/System.Application.Services.SmsSender/Services/Implementation/AlibabaCloud/SmsSenderProvider.cs similarity index 98% rename from System.Application.Services.SmsSender/Services/AlibabaCloud/SmsSenderProvider.cs rename to System.Application.Services.SmsSender/Services/Implementation/AlibabaCloud/SmsSenderProvider.cs index e20afb915..1b327351f 100644 --- a/System.Application.Services.SmsSender/Services/AlibabaCloud/SmsSenderProvider.cs +++ b/System.Application.Services.SmsSender/Services/Implementation/AlibabaCloud/SmsSenderProvider.cs @@ -2,7 +2,6 @@ using Newtonsoft.Json; using System.Application.Models; using System.Application.Models.AlibabaCloud; -using System.Application.Services.Implementation; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -13,7 +12,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -namespace System.Application.Services.AlibabaCloud +namespace System.Application.Services.Implementation.AlibabaCloud { /// /// 短信服务提供商 - 阿里云 diff --git a/System.Application.Services.SmsSender/Services/NetEaseCloud/SmsSenderProvider.cs b/System.Application.Services.SmsSender/Services/Implementation/NetEaseCloud/SmsSenderProvider.cs similarity index 98% rename from System.Application.Services.SmsSender/Services/NetEaseCloud/SmsSenderProvider.cs rename to System.Application.Services.SmsSender/Services/Implementation/NetEaseCloud/SmsSenderProvider.cs index f8f3c475b..dac2ca972 100644 --- a/System.Application.Services.SmsSender/Services/NetEaseCloud/SmsSenderProvider.cs +++ b/System.Application.Services.SmsSender/Services/Implementation/NetEaseCloud/SmsSenderProvider.cs @@ -3,7 +3,6 @@ using Newtonsoft.Json; using System.Application.Models; using System.Application.Models.Abstractions; using System.Application.Models.NetEaseCloud; -using System.Application.Services.Implementation; using System.Collections.Generic; using System.IO; using System.Linq; @@ -36,7 +35,7 @@ http 响应:json 500 服务器内部错误 */ -namespace System.Application.Services.NetEaseCloud +namespace System.Application.Services.Implementation.NetEaseCloud { /// /// 短信服务(网易云实现) 需要实现校验接口 diff --git a/System.Application.Services.SmsSender/Services/Implementation/_21VianetBlueCloud/SmsSenderProvider.cs b/System.Application.Services.SmsSender/Services/Implementation/_21VianetBlueCloud/SmsSenderProvider.cs new file mode 100644 index 000000000..6221d4ba6 --- /dev/null +++ b/System.Application.Services.SmsSender/Services/Implementation/_21VianetBlueCloud/SmsSenderProvider.cs @@ -0,0 +1,85 @@ +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using System.Application.Models; +using System.Application.Models._21VianetBlueCloud; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace System.Application.Services.Implementation._21VianetBlueCloud +{ + /// + /// 短信服务提供商 - 世纪互联蓝云 + /// + public class SmsSenderProvider : AbstractSmsSender, ISmsSender + { + public const string Name = nameof(_21VianetBlueCloud); + + public override string Channel => Name; + + public override bool SupportCheck => false; + + readonly HttpClient httpClient; + readonly SmsOptions options; + readonly ILogger logger; + readonly JsonSerializer jsonSerializer = new(); + + public SmsSenderProvider(ILogger logger, SmsOptions options, HttpClient httpClient) + { + this.logger = logger; + this.options = options; + this.httpClient = httpClient; + } + + public override Task SendSmsAsync(string number, string message, int type, CancellationToken cancellationToken) + { + var dictionary = new Dictionary { + { "phoneNumber", new[] { number } }, + { "extend", options.ExtendCode }, + { "messageBody", options.ExtendCode }, + }; + + // 明天再写 + throw new NotImplementedException(); + } + + public override Task CheckSmsAsync(string __, string ___, CancellationToken _) + { + throw new NotImplementedException(); + } + + class RequestData + { + /// + /// 接收手机号 + /// + [JsonProperty("phoneNumber")] + public string[]? PhoneNumber { get; set; } + + /// + /// 下发扩展码,两位纯数字 + /// + [JsonProperty("extend")] + public string? ExtendCode { get; set; } + + [JsonProperty("messageBody")] + public MessageBody? MessageBody { get; set; } + } + + class MessageBody + { + /// + /// 短信模板名称 + /// + [JsonProperty("templateName")] + public string? TemplateName { get; set; } + + /// + /// 短信模板参数,和模板中变量一一对应,没有变量则不需要 + /// + [JsonProperty("templateParam")] + public Dictionary? TemplateParam { get; set; } + } + } +} \ No newline at end of file diff --git a/System.Application.Services.SmsSender/Services/_21VianetBlueCloud/SmsSenderProvider.cs b/System.Application.Services.SmsSender/Services/_21VianetBlueCloud/SmsSenderProvider.cs deleted file mode 100644 index d09be2697..000000000 --- a/System.Application.Services.SmsSender/Services/_21VianetBlueCloud/SmsSenderProvider.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Application.Models; -using System.Application.Services.Implementation; -using System.Threading; -using System.Threading.Tasks; - -namespace System.Application.Services._21VianetBlueCloud -{ - /// - /// 短信服务提供商 - 世纪互联蓝云 - /// - public class SmsSenderProvider : AbstractSmsSender, ISmsSender - { - public const string Name = nameof(_21VianetBlueCloud); - - public override string Channel => Name; - - public override bool SupportCheck => throw new NotImplementedException(); - - public override Task SendSmsAsync(string number, string message, int type, CancellationToken cancellationToken) - { - // 明天再写 - throw new NotImplementedException(); - } - - public override Task CheckSmsAsync(string number, string message, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Linux/Application/Services/Implementation/LinuxDesktopPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Linux/Application/Services/Implementation/LinuxDesktopPlatformServiceImpl.cs index 2eaf0d48d..8f3271bf5 100644 --- a/System.Application.SteamTools.Client.Desktop.Linux/Application/Services/Implementation/LinuxDesktopPlatformServiceImpl.cs +++ b/System.Application.SteamTools.Client.Desktop.Linux/Application/Services/Implementation/LinuxDesktopPlatformServiceImpl.cs @@ -38,5 +38,7 @@ namespace System.Application.Services.Implementation } public string GetLastSteamLoginUserName() => string.Empty; + + public void SetCurrentUser(string userName) { } } } \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Mac/Application/Services/Implementation/MacDesktopPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Mac/Application/Services/Implementation/MacDesktopPlatformServiceImpl.cs index e2e2dd22a..89eae86e5 100644 --- a/System.Application.SteamTools.Client.Desktop.Mac/Application/Services/Implementation/MacDesktopPlatformServiceImpl.cs +++ b/System.Application.SteamTools.Client.Desktop.Mac/Application/Services/Implementation/MacDesktopPlatformServiceImpl.cs @@ -53,5 +53,7 @@ namespace System.Application.Services.Implementation } public string GetLastSteamLoginUserName() => string.Empty; + + public void SetCurrentUser(string userName) { } } } \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Windows/Application/Services/Implementation/WindowsDesktopPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Windows/Application/Services/Implementation/WindowsDesktopPlatformServiceImpl.cs index b3cfbad9b..b76eaec61 100644 --- a/System.Application.SteamTools.Client.Desktop.Windows/Application/Services/Implementation/WindowsDesktopPlatformServiceImpl.cs +++ b/System.Application.SteamTools.Client.Desktop.Windows/Application/Services/Implementation/WindowsDesktopPlatformServiceImpl.cs @@ -142,6 +142,11 @@ namespace System.Application.Services.Implementation public string GetLastSteamLoginUserName() => Registry.CurrentUser.Read(SteamRegistryPath, "AutoLoginUser"); + + public void SetCurrentUser(string userName) + { + Registry.CurrentUser.AddOrUpdate(SteamRegistryPath, "AutoLoginUser", userName, RegistryValueKind.String); + } } } #pragma warning restore CA1416 // 验证平台兼容性 \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop/Services/IDesktopPlatformService.cs b/System.Application.SteamTools.Client.Desktop/Services/IDesktopPlatformService.cs index f5d431b5f..0b8095bd5 100644 --- a/System.Application.SteamTools.Client.Desktop/Services/IDesktopPlatformService.cs +++ b/System.Application.SteamTools.Client.Desktop/Services/IDesktopPlatformService.cs @@ -119,6 +119,9 @@ namespace System.Application.Services /// string GetLastSteamLoginUserName(); + /// + void SetCurrentUser(string userName); + #endregion public const ResizeMode ResizeMode_NoResize = 0; diff --git a/System.Application.SteamTools.Client.Desktop/Services/ISteamService.cs b/System.Application.SteamTools.Client.Desktop/Services/ISteamService.cs index 0440ac493..a4eacb91a 100644 --- a/System.Application.SteamTools.Client.Desktop/Services/ISteamService.cs +++ b/System.Application.SteamTools.Client.Desktop/Services/ISteamService.cs @@ -56,6 +56,12 @@ namespace System.Application.Services /// List GetRememberUserList(); + /// + /// 设置下次登陆 Steam 用户 + /// + /// + void SetCurrentUser(string userName); + List? GetAppListJson(string filePath); bool UpdateAppListJson(List apps, string filePath); diff --git a/System.Application.SteamTools.Client.Desktop/Services/Implementation/SteamServiceImpl.cs b/System.Application.SteamTools.Client.Desktop/Services/Implementation/SteamServiceImpl.cs index 55c0d7d15..83ba5b87d 100644 --- a/System.Application.SteamTools.Client.Desktop/Services/Implementation/SteamServiceImpl.cs +++ b/System.Application.SteamTools.Client.Desktop/Services/Implementation/SteamServiceImpl.cs @@ -146,6 +146,8 @@ namespace System.Application.Services.Implementation return users; } + public string SetCurrentUser(string userName) => platformService.SetCurrentUser(userName); + public List? GetAppListJson(string filePath) { if (!File.Exists(filePath))