diff --git a/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 13a7775b..8ab799cf 100644 --- a/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -1,9 +1,13 @@  - netstandard2.0 + netcoreapp3.0;netstandard2.0 + + + + diff --git a/src/admin/Bootstrap.DataAccess/Helper/OAuthHelper.cs b/src/admin/Bootstrap.DataAccess/Helper/OAuthHelper.cs index ce1e8608..0b143b83 100644 --- a/src/admin/Bootstrap.DataAccess/Helper/OAuthHelper.cs +++ b/src/admin/Bootstrap.DataAccess/Helper/OAuthHelper.cs @@ -50,6 +50,27 @@ namespace Bootstrap.DataAccess }; } +#if NETCOREAPP3_0 + private static T ToObject(this System.Text.Json.JsonElement element) where T: OAuthUser + { + var user = new OAuthUser(); + var target = element.EnumerateObject(); + user.Id = target.TryGetValue("Id"); + user.Login = target.TryGetValue("Login"); + user.Name = target.TryGetValue("Name"); + user.Avatar_Url = target.TryGetValue("Avatar_Url"); + return user as T; + } + + private static string TryGetValue(this System.Text.Json.JsonElement.ObjectEnumerator target, string propertyName) + { + var ret = string.Empty; + var property = target.FirstOrDefault(t => t.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase)); + ret = property.Value.ToString(); + return ret; + } +#endif + /// /// 插入 Gitee 授权用户到数据库中 /// diff --git a/src/admin/Bootstrap.DataAccess/Helper/WeChatHelper.cs b/src/admin/Bootstrap.DataAccess/Helper/WeChatHelper.cs index 491a4f63..eeb5b89a 100644 --- a/src/admin/Bootstrap.DataAccess/Helper/WeChatHelper.cs +++ b/src/admin/Bootstrap.DataAccess/Helper/WeChatHelper.cs @@ -3,6 +3,7 @@ using Longbow.Security.Cryptography; using Longbow.WeChatAuth; using Microsoft.AspNetCore.Authentication.OAuth; using System; +using System.Linq; namespace Bootstrap.DataAccess { @@ -50,5 +51,32 @@ namespace Bootstrap.DataAccess Description = $"{context.Scheme.Name}" }; } + +#if NETCOREAPP3_0 + private static T ToObject(this System.Text.Json.JsonElement element) where T : WeChatUser + { + var user = new WeChatUser(); + var target = element.EnumerateObject(); + user.OpenId = target.TryGetValue("OpenId"); + user.UnionId = target.TryGetValue("UnionId"); + user.NickName = target.TryGetValue("NickName"); + user.Privilege = target.TryGetValue("Privilege"); + user.Sex = target.TryGetValue("Sex"); + user.Province = target.TryGetValue("Province"); + user.City = target.TryGetValue("City"); + user.Country = target.TryGetValue("Country"); + user.HeadImgUrl = target.TryGetValue("HeadImgUrl"); + user.Privilege = target.TryGetValue("Privilege"); + return user as T; + } + + private static string TryGetValue(this System.Text.Json.JsonElement.ObjectEnumerator target, string propertyName) + { + var ret = string.Empty; + var property = target.FirstOrDefault(t => t.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase)); + ret = property.Value.ToString(); + return ret; + } +#endif } }