parent
3e1b7e94d3
commit
330167447c
|
@ -1,9 +1,13 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFrameworks>netcoreapp3.0;netstandard2.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
|
||||||
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
|
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
|
||||||
<PackageReference Include="Longbow" Version="3.0.0-beta1" />
|
<PackageReference Include="Longbow" Version="3.0.0-beta1" />
|
||||||
|
|
|
@ -50,6 +50,27 @@ namespace Bootstrap.DataAccess
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NETCOREAPP3_0
|
||||||
|
private static T ToObject<T>(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
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 插入 Gitee 授权用户到数据库中
|
/// 插入 Gitee 授权用户到数据库中
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -3,6 +3,7 @@ using Longbow.Security.Cryptography;
|
||||||
using Longbow.WeChatAuth;
|
using Longbow.WeChatAuth;
|
||||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bootstrap.DataAccess
|
namespace Bootstrap.DataAccess
|
||||||
{
|
{
|
||||||
|
@ -50,5 +51,32 @@ namespace Bootstrap.DataAccess
|
||||||
Description = $"{context.Scheme.Name}"
|
Description = $"{context.Scheme.Name}"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NETCOREAPP3_0
|
||||||
|
private static T ToObject<T>(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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue