Skip to content

Commit

Permalink
Merge pull request #54 from EasyAbp/auto-change-current-platform
Browse files Browse the repository at this point in the history
Auto changes current platform on app event handling
  • Loading branch information
gdlcf88 committed Dec 21, 2022
2 parents 29e2b0e + 4aebadf commit e9bd5e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
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.7</Version>
<Version>2.0.0-rc.8</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 @@ -17,11 +17,9 @@ public interface IWeChatThirdPartyPlatformAppEventHandler
public string Event { get; }

/// <summary>
/// 事件处理实现
/// 请注意,此方法中如有需要调用微信 API,请在第一行使用:
/// using var changeOptions = WeChatXxxxAsyncLocal.Change(new AbpWeChatXxxxOptions { AppId = context.AuthorizerAppId; })
/// 不要设置 AppSecret,此时会自动使用微信第三方平台的 authorizer_access_token
/// 见 <see cref="HybridAccessTokenProvider"/>
/// 事件处理实现。
/// 请注意,此方法已在外层切换了 <see cref="ICurrentWeChatThirdPartyPlatform"/>,
/// 因此可以直接使用任意微信的接口服务,第三方平台会提供接口鉴权凭证。
/// </summary>
Task<WeChatRequestHandlingResult> HandleAsync(
[CanBeNull] string componentAppId, [NotNull] string authorizerAppId, WeChatAppEventModel model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ public class WeChatThirdPartyPlatformEventRequestHandlingService :
IWeChatThirdPartyPlatformEventRequestHandlingService, ITransientDependency
{
private readonly IServiceProvider _serviceProvider;
private readonly ICurrentWeChatThirdPartyPlatform _currentWeChatThirdPartyPlatform;
private readonly IAbpWeChatOptionsProvider<AbpWeChatThirdPartyPlatformOptions> _optionsProvider;
private readonly IWeChatNotificationEncryptor _weChatNotificationEncryptor;

public WeChatThirdPartyPlatformEventRequestHandlingService(
IServiceProvider serviceProvider,
ICurrentWeChatThirdPartyPlatform currentWeChatThirdPartyPlatform,
IAbpWeChatOptionsProvider<AbpWeChatThirdPartyPlatformOptions> optionsProvider,
IWeChatNotificationEncryptor weChatNotificationEncryptor)
{
_serviceProvider = serviceProvider;
_currentWeChatThirdPartyPlatform = currentWeChatThirdPartyPlatform;
_optionsProvider = optionsProvider;
_weChatNotificationEncryptor = weChatNotificationEncryptor;
}
Expand Down Expand Up @@ -68,6 +71,8 @@ public virtual async Task<WeChatRequestHandlingResult> NotifyAppAsync(NotifyAppI
{
var options = await _optionsProvider.GetAsync(input.ComponentAppId);

using var currentPlatform = _currentWeChatThirdPartyPlatform.Change(input.ComponentAppId);

var model = await DecryptMsgAsync<WeChatAppEventModel>(options, input.EventRequest);

var handlers = _serviceProvider.GetService<IEnumerable<IWeChatThirdPartyPlatformAppEventHandler>>();
Expand Down

0 comments on commit e9bd5e9

Please sign in to comment.