18 changed files with 482 additions and 83 deletions
-
12src/Shentun.WebPeis.Application.Contracts/UserTokenDto.cs
-
11src/Shentun.WebPeis.Application/PatientRegisters/PatientRegisterAppService.cs
-
127src/Shentun.WebPeis.Application/Persons/PersonAppService.cs
-
1src/Shentun.WebPeis.Application/Shentun.WebPeis.Application.csproj
-
45src/Shentun.WebPeis.Application/WeChatHelper.cs
-
13src/Shentun.WebPeis.Domain.Shared/Enums/WeChatGrant.cs
-
220src/Shentun.WebPeis.Domain/Data/CustomerAuditPropertySetter.cs
-
2src/Shentun.WebPeis.Domain/Models/PatientRegister.cs
-
4src/Shentun.WebPeis.Domain/Models/Person.cs
-
4src/Shentun.WebPeis.Domain/Models/PersonKinship.cs
-
49src/Shentun.WebPeis.Domain/OpenIddict/OpenIddictDataSeedContributor.cs
-
4src/Shentun.WebPeis.EntityFrameworkCore/Configures/PatientRegisterConfigure.cs
-
6src/Shentun.WebPeis.EntityFrameworkCore/Configures/PersonConfigure.cs
-
6src/Shentun.WebPeis.EntityFrameworkCore/Configures/PersonKinshipConfigure.cs
-
27src/Shentun.WebPeis.HttpApi.Host/Controllers/WeChatController.cs
-
18src/Shentun.WebPeis.HttpApi.Host/WebPeisHttpApiHostModule.cs
-
4src/Shentun.WebPeis.HttpApi.Host/appsettings.json
-
12test/Shentun.WebPeis.Application.Tests/PersonAppServiceTest.cs
@ -0,0 +1,12 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Shentun.WebPeis |
||||
|
{ |
||||
|
public class UserTokenDto |
||||
|
{ |
||||
|
public string AccessToken { get; set; } |
||||
|
public string RefreshToken { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Shentun.WebPeis.Wechats; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Net; |
||||
|
using System.Net.Http; |
||||
|
using System.Text; |
||||
|
using System.Text.Json; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Shentun.WebPeis |
||||
|
{ |
||||
|
public class WeChatHelper |
||||
|
{ |
||||
|
public static async Task<WechatSession> GetWechatSession(IConfiguration configSection1,string jsCode) |
||||
|
{ |
||||
|
IConfigurationSection wechatconfigSection = configSection1.GetSection("Wechat"); |
||||
|
string url = wechatconfigSection.GetValue("SessionUrl", "https://api.weixin.qq.com/sns/jscode2session?"); |
||||
|
string appId = wechatconfigSection.GetValue("AppID", ""); |
||||
|
string appSecret = wechatconfigSection.GetValue("AppSecret", ""); |
||||
|
|
||||
|
url = url + "appid=" + appId + "&secret=" + appSecret + "&js_code=" + jsCode + "&grant_type=authorization_code"; |
||||
|
|
||||
|
var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; |
||||
|
|
||||
|
using (var httpClient = new HttpClient(handler)) |
||||
|
{ |
||||
|
//await异步等待回应
|
||||
|
|
||||
|
var responseResult = await httpClient.GetAsync(url); |
||||
|
//确保HTTP成功状态值
|
||||
|
if (!responseResult.IsSuccessStatusCode) |
||||
|
{ |
||||
|
throw new Exception("获取微信小程序数据失败," + responseResult.StatusCode); |
||||
|
} |
||||
|
|
||||
|
//await异步读取最后的JSON(注意此时gzip已经被自动解压缩了,因为上面的AutomaticDecompression = DecompressionMethods.GZip)
|
||||
|
string responseContent = await responseResult.Content.ReadAsStringAsync(); |
||||
|
var wechatSession = JsonSerializer.Deserialize<WechatSession>(responseContent); |
||||
|
return wechatSession; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Collections.Immutable; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Shentun.WebPeis.Enums |
||||
|
{ |
||||
|
public class WeChatGrant |
||||
|
{ |
||||
|
public const string GrantType = "WeChat"; |
||||
|
public static readonly ImmutableArray<string> Scopes = ImmutableArray.Create("offline_access", "audience"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,220 @@ |
|||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Auditing; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Entities.Auditing; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.Timing; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Shentun.Peis.Data |
||||
|
{ |
||||
|
|
||||
|
//public class CustomerAuditPropertySetter
|
||||
|
//{
|
||||
|
|
||||
|
//}
|
||||
|
/// <summary>
|
||||
|
/// 生成默认ID
|
||||
|
/// </summary>
|
||||
|
public class CustomerAuditPropertySetter : IAuditPropertySetter, ITransientDependency |
||||
|
{ |
||||
|
protected ICurrentUser CurrentUser { get; } |
||||
|
protected ICurrentTenant CurrentTenant { get; } |
||||
|
|
||||
|
private readonly IConfiguration _configuration; |
||||
|
protected IClock Clock { get; } |
||||
|
|
||||
|
public CustomerAuditPropertySetter( |
||||
|
ICurrentUser currentUser, |
||||
|
ICurrentTenant currentTenant, |
||||
|
IClock clock, |
||||
|
IConfiguration configuration) |
||||
|
{ |
||||
|
CurrentUser = currentUser; |
||||
|
CurrentTenant = currentTenant; |
||||
|
Clock = clock; |
||||
|
_configuration = configuration; |
||||
|
} |
||||
|
|
||||
|
public void SetCreationProperties(object targetObject) |
||||
|
{ |
||||
|
SetCreationTime(targetObject); |
||||
|
SetCreatorId(targetObject); |
||||
|
} |
||||
|
|
||||
|
public void SetModificationProperties(object targetObject) |
||||
|
{ |
||||
|
SetLastModificationTime(targetObject); |
||||
|
SetLastModifierId(targetObject); |
||||
|
} |
||||
|
|
||||
|
public void SetDeletionProperties(object targetObject) |
||||
|
{ |
||||
|
SetDeletionTime(targetObject); |
||||
|
SetDeleterId(targetObject); |
||||
|
} |
||||
|
|
||||
|
protected virtual void SetCreationTime(object targetObject) |
||||
|
{ |
||||
|
if (!(targetObject is IHasCreationTime objectWithCreationTime)) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (objectWithCreationTime.CreationTime == default) |
||||
|
{ |
||||
|
ObjectHelper.TrySetProperty(objectWithCreationTime, x => x.CreationTime, () => Clock.Now); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected virtual void SetCreatorId(object targetObject) |
||||
|
{ |
||||
|
if (!CurrentUser.Id.HasValue) |
||||
|
{ |
||||
|
var defaultCreatorId = _configuration.GetValue<string>("AdminId"); |
||||
|
|
||||
|
#region 无登录操作
|
||||
|
if (targetObject is IMayHaveCreator mayHaveCreatorObjectNoLogin) |
||||
|
{ |
||||
|
ObjectHelper.TrySetProperty(mayHaveCreatorObjectNoLogin, x => x.CreatorId, () => Guid.Parse(defaultCreatorId)); |
||||
|
} |
||||
|
#endregion
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (targetObject is IMultiTenant multiTenantEntity) |
||||
|
{ |
||||
|
if (multiTenantEntity.TenantId != CurrentUser.TenantId) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/* TODO: The code below is from old ABP, not implemented yet |
||||
|
if (tenantId.HasValue && MultiTenancyHelper.IsHostEntity(entity)) |
||||
|
{ |
||||
|
//Tenant user created a host entity
|
||||
|
return; |
||||
|
} |
||||
|
*/ |
||||
|
|
||||
|
if (targetObject is IMayHaveCreator mayHaveCreatorObject) |
||||
|
{ |
||||
|
if (mayHaveCreatorObject.CreatorId.HasValue && mayHaveCreatorObject.CreatorId.Value != default) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
ObjectHelper.TrySetProperty(mayHaveCreatorObject, x => x.CreatorId, () => CurrentUser.Id); |
||||
|
} |
||||
|
else if (targetObject is IMustHaveCreator mustHaveCreatorObject) |
||||
|
{ |
||||
|
if (mustHaveCreatorObject.CreatorId != default) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
ObjectHelper.TrySetProperty(mustHaveCreatorObject, x => x.CreatorId, () => CurrentUser.Id.Value); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected virtual void SetLastModificationTime(object targetObject) |
||||
|
{ |
||||
|
if (targetObject is AuditedEntity objectWithModificationTime) |
||||
|
{ |
||||
|
objectWithModificationTime.LastModificationTime = Clock.Now; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected virtual void SetLastModifierId(object targetObject) |
||||
|
{ |
||||
|
if (!(targetObject is AuditedEntity modificationAuditedObject)) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (!CurrentUser.Id.HasValue) |
||||
|
{ |
||||
|
//modificationAuditedObject.LastModifierId = null;
|
||||
|
//return;
|
||||
|
var defaultCreatorId = _configuration.GetValue<string>("AdminId"); |
||||
|
#region 无登录操作
|
||||
|
modificationAuditedObject.LastModifierId = Guid.Parse(defaultCreatorId); |
||||
|
return; |
||||
|
#endregion
|
||||
|
} |
||||
|
|
||||
|
if (modificationAuditedObject is IMultiTenant multiTenantEntity) |
||||
|
{ |
||||
|
if (multiTenantEntity.TenantId != CurrentUser.TenantId) |
||||
|
{ |
||||
|
modificationAuditedObject.LastModifierId = null; |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/* TODO: The code below is from old ABP, not implemented yet |
||||
|
if (tenantId.HasValue && MultiTenancyHelper.IsHostEntity(entity)) |
||||
|
{ |
||||
|
//Tenant user modified a host entity
|
||||
|
modificationAuditedObject.LastModifierId = null; |
||||
|
return; |
||||
|
} |
||||
|
*/ |
||||
|
|
||||
|
modificationAuditedObject.LastModifierId = CurrentUser.Id; |
||||
|
} |
||||
|
|
||||
|
protected virtual void SetDeletionTime(object targetObject) |
||||
|
{ |
||||
|
//if (targetObject is AuditedEntity objectWithDeletionTime)
|
||||
|
//{
|
||||
|
// if (objectWithDeletionTime.DeletionTime == null)
|
||||
|
// {
|
||||
|
// objectWithDeletionTime.DeletionTime = Clock.Now;
|
||||
|
// }
|
||||
|
//}
|
||||
|
} |
||||
|
|
||||
|
protected virtual void SetDeleterId(object targetObject) |
||||
|
{ |
||||
|
//if (!(targetObject is IDeletionAuditedObject deletionAuditedObject))
|
||||
|
//{
|
||||
|
// return;
|
||||
|
//}
|
||||
|
|
||||
|
//if (deletionAuditedObject.DeleterId != null)
|
||||
|
//{
|
||||
|
// return;
|
||||
|
//}
|
||||
|
|
||||
|
//if (!CurrentUser.Id.HasValue)
|
||||
|
//{
|
||||
|
// deletionAuditedObject.DeleterId = null;
|
||||
|
// return;
|
||||
|
//}
|
||||
|
|
||||
|
//if (deletionAuditedObject is IMultiTenant multiTenantEntity)
|
||||
|
//{
|
||||
|
// if (multiTenantEntity.TenantId != CurrentUser.TenantId)
|
||||
|
// {
|
||||
|
// deletionAuditedObject.DeleterId = null;
|
||||
|
// return;
|
||||
|
// }
|
||||
|
//}
|
||||
|
|
||||
|
//deletionAuditedObject.DeleterId = CurrentUser.Id;
|
||||
|
} |
||||
|
|
||||
|
public void IncrementEntityVersionProperty(object targetObject) |
||||
|
{ |
||||
|
//throw new NotImplementedException();
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Shentun.WebPeis |
||||
|
{ |
||||
|
internal class PersonAppServiceTest |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue