Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ReleaseTestWeChatThirdPartyPlatformAppEventHandler #61

Merged
merged 1 commit into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>2.0.0-rc.16</Version>
<Version>2.0.0-rc.17</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ public class ReleaseTestWeChatThirdPartyPlatformAppEventHandler : IWeChatThirdPa
{
if (ReleaseTestConsts.OfficialAppIds.Contains(authorizerAppId))
{
return await HandleOfficialReleaseTestAsync(model);
return await HandleOfficialReleaseTestAsync(componentAppId, model);
}

if (ReleaseTestConsts.MiniProgramsAppIds.Contains(authorizerAppId))
{
return await HandleMiniProgramReleaseTestAsync(model);
return await HandleMiniProgramReleaseTestAsync(componentAppId, model);
}

return new AppEventHandlingResult(true);
}

protected virtual async Task<AppEventHandlingResult> HandleOfficialReleaseTestAsync(WeChatAppEventModel model)
protected virtual async Task<AppEventHandlingResult> HandleOfficialReleaseTestAsync(string componentAppId,
WeChatAppEventModel model)
{
var content = model.GetProperty<string>("Content");

Expand Down Expand Up @@ -74,7 +75,7 @@ protected virtual async Task<AppEventHandlingResult> HandleOfficialReleaseTestAs
var httpClientFactory = _serviceProvider.GetRequiredService<IHttpClientFactory>();
var jsonSerializer = _serviceProvider.GetRequiredService<IJsonSerializer>();

var service = await abpWeChatServiceFactory.CreateAsync<ThirdPartyPlatformWeService>();
var service = await abpWeChatServiceFactory.CreateAsync<ThirdPartyPlatformWeService>(componentAppId);

var response = await service.QueryAuthAsync(queryAuthCode);

Expand Down Expand Up @@ -106,7 +107,8 @@ protected virtual async Task<AppEventHandlingResult> HandleOfficialReleaseTestAs
return new AppEventHandlingResult(true);
}

protected virtual async Task<AppEventHandlingResult> HandleMiniProgramReleaseTestAsync(WeChatAppEventModel model)
protected virtual async Task<AppEventHandlingResult> HandleMiniProgramReleaseTestAsync(string componentAppId,
WeChatAppEventModel model)
{
var content = model.GetProperty<string>("Content");

Expand All @@ -123,7 +125,7 @@ protected virtual async Task<AppEventHandlingResult> HandleMiniProgramReleaseTes
var httpClientFactory = _serviceProvider.GetRequiredService<IHttpClientFactory>();
var jsonSerializer = _serviceProvider.GetRequiredService<IJsonSerializer>();

var service = await abpWeChatServiceFactory.CreateAsync<ThirdPartyPlatformWeService>();
var service = await abpWeChatServiceFactory.CreateAsync<ThirdPartyPlatformWeService>(componentAppId);

var response = await service.QueryAuthAsync(queryAuthCode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public virtual Task<List<IWeChatThirdPartyPlatformAppEventHandler>> GetAppEventH
{
if (AuthEventHandlerCachedTypes is null)
{
var objs = ServiceProvider
.GetRequiredService<IEnumerable<IWeChatThirdPartyPlatformAuthEventHandler>>().ToArray();
var objs = ServiceProvider.GetServices<IWeChatThirdPartyPlatformAuthEventHandler>().ToArray();

var cacheTypes = objs.GroupBy(obj => obj.InfoType)
.ToDictionary(x => x.Key, x => x.Select(y => y.GetType()).ToList());
Expand All @@ -69,8 +68,7 @@ public virtual Task<List<IWeChatThirdPartyPlatformAppEventHandler>> GetAppEventH
{
if (AppEventHandlerCachedTypes is null)
{
var objs = ServiceProvider
.GetRequiredService<IEnumerable<IWeChatThirdPartyPlatformAppEventHandler>>().ToArray();
var objs = ServiceProvider.GetServices<IWeChatThirdPartyPlatformAppEventHandler>().ToArray();

var cacheTypes = objs.GroupBy(obj => obj.MsgType)
.ToDictionary(x => x.Key, x => x.Select(y => y.GetType()).ToList());
Expand All @@ -89,6 +87,7 @@ public virtual Task<List<IWeChatThirdPartyPlatformAppEventHandler>> GetAppEventH

protected virtual Task<List<TObj>> CreateObjectsAsync<TObj>(IEnumerable<Type> types)
{
return Task.FromResult(types.Select(type => (TObj)ServiceProvider.GetRequiredService(type)).ToList());
return Task.FromResult(types.Select(type => ServiceProvider.GetService(type)).Where(x => x != null)
.Select(x => (TObj)x).ToList());
}
}