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

Improvement event handling #46

Merged
merged 3 commits into from
Dec 14, 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-preview.5</Version>
<Version>2.0.0-preview.6</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 @@ -4,15 +4,12 @@ public class WeChatEventHandlingResult
{
public bool Success { get; set; }

public string FailureReason { get; set; }

public WeChatEventHandlingResult()
{
}

public WeChatEventHandlingResult(bool success, string failureReason = null)
public WeChatEventHandlingResult(bool success)
{
Success = success;
FailureReason = failureReason;
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
using System;
using System.Threading.Tasks;
using EasyAbp.Abp.WeChat.Common.EventHandling;
using EasyAbp.Abp.WeChat.Common.Models;
using EasyAbp.Abp.WeChat.OpenPlatform.Infrastructure.Models.ThirdPartyPlatform;
using EasyAbp.Abp.WeChat.OpenPlatform.Infrastructure.ThirdPartyPlatform.VerifyTicket;
using Microsoft.Extensions.Logging;
using Volo.Abp.DependencyInjection;

namespace EasyAbp.Abp.WeChat.OpenPlatform.Infrastructure.ThirdPartyPlatform.EventNotification;

public class TicketRecordingWeChatThirdPartyPlatformAuthEventHandler : IWeChatThirdPartyPlatformAuthEventHandler
public class TicketRecordingWeChatThirdPartyPlatformAuthEventHandler :
IWeChatThirdPartyPlatformAuthEventHandler, ITransientDependency
{
public string InfoType => WeChatThirdPartyPlatformAuthEventInfoTypes.ComponentVerifyTicket;

private readonly ILogger<TicketRecordingWeChatThirdPartyPlatformAuthEventHandler> _logger;
private readonly IComponentVerifyTicketStore _componentVerifyTicketStore;

public TicketRecordingWeChatThirdPartyPlatformAuthEventHandler(
ILogger<TicketRecordingWeChatThirdPartyPlatformAuthEventHandler> logger,
IComponentVerifyTicketStore componentVerifyTicketStore)
{
_logger = logger;
_componentVerifyTicketStore = componentVerifyTicketStore;
}

public virtual async Task<WeChatEventHandlingResult> HandleAsync(AuthNotificationModel model)
{
if (model.ComponentVerifyTicket.IsNullOrWhiteSpace())
{
return new WeChatEventHandlingResult(false, "缺少 ComponentVerifyTicket");
_logger.LogWarning("缺少 ComponentVerifyTicket,通知消息无效。AppId:{0}", model.AppId);

return new WeChatEventHandlingResult(false);
}

try
{
await _componentVerifyTicketStore.SetAsync(model.AppId, model.ComponentVerifyTicket);
}
catch
{
_logger.LogWarning(
"ComponentVerifyTicketStore 保存出错,导致,导致 ComponentVerifyTicket 设置失败。AppId:{0}", model.AppId);

await _componentVerifyTicketStore.SetAsync(model.AppId, model.ComponentVerifyTicket);
return new WeChatEventHandlingResult(false);
}

return new WeChatEventHandlingResult(true);
}
Expand Down