Skip to content

Commit

Permalink
feat: Add WeixinWork
Browse files Browse the repository at this point in the history
  • Loading branch information
wzh425 committed Jul 23, 2024
1 parent 09e8824 commit 376546a
Show file tree
Hide file tree
Showing 60 changed files with 1,952 additions and 385 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<MasaFrameworkPackageVersion>1.2.0-preview.2</MasaFrameworkPackageVersion>
<MasaStackSdksPackageVersion>1.1.0-preview.2</MasaStackSdksPackageVersion>
<MasaStackSdksPackageVersion>1.1.1-preview.3</MasaStackSdksPackageVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Masa.Mc.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Mc.Infrastructure.Mail
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Mc.Infrastructure.AppNotification", "src\Infrastructure\Masa.Mc.Infrastructure.AppNotification\Masa.Mc.Infrastructure.AppNotification.csproj", "{7F2708C3-F1EE-4BFD-9321-F8D90390BF3C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Mc.Infrastructure.Weixin.Work", "src\Infrastructure\Masa.Mc.Infrastructure.Weixin.Work\Masa.Mc.Infrastructure.Weixin.Work.csproj", "{58E1DBB5-409C-4DF7-BDCA-A36715E0BB86}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Mc.Infrastructure.Weixin.Work", "src\Infrastructure\Masa.Mc.Infrastructure.Weixin.Work\Masa.Mc.Infrastructure.Weixin.Work.csproj", "{58E1DBB5-409C-4DF7-BDCA-A36715E0BB86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public static class BusinessConsts
public const string INTENT_URL = "IntentUrl";
public const string IS_APNS_PRODUCTION = "IsApnsProduction";
public const string APP_PUSH_MSG_ID = "MsgId";
public const string MESSAGE_TYPE = "MessageType";
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class MessageInfoUpsertDto
public string Markdown { get; set; } = string.Empty;
public bool IsJump { get; set; }
public string JumpUrl { get; set; } = string.Empty;
public int Type { get; set; }
public ExtraPropertyDictionary ExtraProperties { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class MessageInfoUpsertDtoValidator : AbstractValidator<MessageInfoUpsert
{
public MessageInfoUpsertDtoValidator()
{
RuleFor(dto => dto.Title).Required("TitleRequired").Length(2, 50);
RuleFor(dto => dto.Content).Required("ContentRequired");
RuleFor(dto => dto.JumpUrl).Required("JumpUrlRequired").When(m => m.IsJump);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class InternalReceiverDto

public ExtraPropertyDictionary Variables { get; set; } = new();

public static implicit operator MessageTaskReceiverDto(InternalReceiverDto dto)
public static implicit operator MessageTaskReceiverUpsertDto(InternalReceiverDto dto)
{
return new MessageTaskReceiverDto
return new MessageTaskReceiverUpsertDto
{
SubjectId = dto.SubjectId,
Type = dto.Type,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

namespace Masa.Mc.Contracts.Admin.Dtos.MessageTasks;

public class MessageTaskReceiverUpsertDto
{
public Guid SubjectId { get; set; }

public string ChannelUserIdentity { get; set; } = string.Empty;

public MessageTaskReceiverTypes Type { get; set; }

public ExtraPropertyDictionary Variables { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MessageTaskUpsertDto

public string Sign { get; set; } = string.Empty;

public List<MessageTaskReceiverDto> Receivers { get; set; } = new();
public List<MessageTaskReceiverUpsertDto> Receivers { get; set; } = new();

public SendRuleDto SendRules { get; set; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public static implicit operator MessageTaskUpsertDto(SendOrdinaryMessageByExtern
SelectReceiverType = MessageTaskSelectReceiverTypes.ManualSelection,
Receivers = dto.Receivers.Select(x =>
{
var receiver = new MessageTaskReceiverDto() { Type = MessageTaskReceiverTypes.User };
receiver.SetChannelUserIdentity(dto.ChannelType, x.ChannelUserIdentity);
receiver.Variables = x.Variables;
return receiver;
return new MessageTaskReceiverUpsertDto {
ChannelUserIdentity = x.ChannelUserIdentity,
Type = MessageTaskReceiverTypes.User,
Variables = x.Variables
};
}).ToList(),
SendRules = dto.SendRules,
MessageInfo = dto.MessageInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static implicit operator MessageTaskUpsertDto(SendOrdinaryMessageByIntern
IsEnabled = true,
ReceiverType = dto.ReceiverType,
SelectReceiverType = MessageTaskSelectReceiverTypes.ManualSelection,
Receivers = dto.Receivers.Select(x => (MessageTaskReceiverDto)x).ToList(),
Receivers = dto.Receivers.Select(x => (MessageTaskReceiverUpsertDto)x).ToList(),
SendRules = dto.SendRules,
MessageInfo = dto.MessageInfo,
Variables = dto.Variables,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ public static implicit operator MessageTaskUpsertDto(SendTemplateMessageByExtern
Sign = dto.Sign,
Receivers = dto.Receivers.Select(x =>
{
var receiver = new MessageTaskReceiverDto() { Type = MessageTaskReceiverTypes.User };
receiver.SetChannelUserIdentity(dto.ChannelType, x.ChannelUserIdentity);
receiver.Variables = x.Variables;
return receiver;
return new MessageTaskReceiverUpsertDto
{
ChannelUserIdentity = x.ChannelUserIdentity,
Type = MessageTaskReceiverTypes.User,
Variables = x.Variables
};
}).ToList(),
SendRules = dto.SendRules,
Variables = dto.Variables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static implicit operator MessageTaskUpsertDto(SendTemplateMessageByIntern
ReceiverType = dto.ReceiverType,
SelectReceiverType = MessageTaskSelectReceiverTypes.ManualSelection,
Sign = dto.Sign,
Receivers = dto.Receivers.Select(x => (MessageTaskReceiverDto)x).ToList(),
Receivers = dto.Receivers.Select(x => (MessageTaskReceiverUpsertDto)x).ToList(),
SendRules = dto.SendRules,
Variables = dto.Variables,
Source = MessageTaskSources.Sdk,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public MessageTemplateUpsertDto()
public DateTimeOffset? InvalidTime { get; set; }
public string AuditReason { get; set; } = string.Empty;
public int TemplateType { get; set; }
public long PerDayLimit { get; set; } = 10;
public long PerDayLimit { get; set; }
public bool IsStatic { get; set; }
public List<MessageTemplateItemDto> Items { get; set; }
public MessageInfoUpsertDto MessageInfo { get; set; } = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MessageTemplateUpsertDtoValidator : AbstractValidator<MessageTempla
public MessageTemplateUpsertDtoValidator()
{
RuleFor(inputDto => inputDto.DisplayName).Required("MessageTemplateDisplayNameRequired")
.Length(2, 50).WithMessage("MessageTemplateDisplayNameLength");
.Length(2, 50).WithMessage("MessageTemplateDisplayNameLength").When(x => x.ChannelType != ChannelTypes.WeixinWork && x.TemplateType != (int)WeixinWorkTemplateTypes.Text);
RuleFor(inputDto => inputDto.Code).Required("MessageTemplateCodeRequired")
.LetterNumberSymbol().WithMessage("MessageTemplateCodeLetterNumberSymbol")
.Length(2, 50).WithMessage("MessageTemplateCodeLength");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

namespace Masa.Mc.Contracts.Admin.Enums.MessageTemplates;

public enum WeixinWorkTemplateTypes
{
Text = 1,
//Image = 2,
//Video = 3,
//File = 4,
TextCard = 5,
//News = 6,
//Markdown = 7,
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Masa.Mc.Infrastructure.Weixin.Work;

public interface IWeixinWorkMessageSender
public interface IWeixinWorkSender
{
Task<WeixinWorkMessageResponseBase> SendTextAsync(WeixinWorkTextMessage message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

namespace Masa.Mc.Infrastructure.Weixin.Work.Infrastructure.OptionsResolve.Contributors;

public class AsyncLocalOptionsResolveContributor : IWeixinWorkMessageOptionsResolveContributor
public class AsyncLocalOptionsResolveContributor : IWeixinWorkOptionsResolveContributor
{
public const string CONTRIBUTOR_NAME = "AsyncLocal";

public string Name => CONTRIBUTOR_NAME;

public Task ResolveAsync(WeixinWorkMessageOptionsResolveContext context)
public Task ResolveAsync(WeixinWorkOptionsResolveContext context)
{
var asyncLocal = context.ServiceProvider.GetRequiredService<IWeixinWorkMessageAsyncLocalAccessor>();
var asyncLocal = context.ServiceProvider.GetRequiredService<IWeixinWorkAsyncLocalAccessor>();

if (asyncLocal.Current != null)
{
Expand All @@ -22,56 +22,56 @@ public Task ResolveAsync(WeixinWorkMessageOptionsResolveContext context)
}
}

public interface IWeixinWorkMessageAsyncLocalAccessor
public interface IWeixinWorkAsyncLocalAccessor
{
IWeixinWorkMessageOptions Current { get; set; }
IWeixinWorkOptions Current { get; set; }
}

public class WeixinWorkMessageAsyncLocalAccessor : IWeixinWorkMessageAsyncLocalAccessor
public class WeixinWorkAsyncLocalAccessor : IWeixinWorkAsyncLocalAccessor
{
public IWeixinWorkMessageOptions Current
public IWeixinWorkOptions Current
{
get => _asyncLocal.Value;
set => _asyncLocal.Value = value;
}

private readonly AsyncLocal<IWeixinWorkMessageOptions> _asyncLocal;
private readonly AsyncLocal<IWeixinWorkOptions> _asyncLocal;

public WeixinWorkMessageAsyncLocalAccessor()
public WeixinWorkAsyncLocalAccessor()
{
_asyncLocal = new AsyncLocal<IWeixinWorkMessageOptions>();
_asyncLocal = new AsyncLocal<IWeixinWorkOptions>();
}
}

public interface IWeixinWorkMessageAsyncLocal
public interface IWeixinWorkAsyncLocal
{
IWeixinWorkMessageOptions CurrentOptions { get; }
IWeixinWorkOptions CurrentOptions { get; }

IDisposable Change(IWeixinWorkMessageOptions weChatMiniProgramOptions);
IDisposable Change(IWeixinWorkOptions weChatMiniProgramOptions);
}

public class WeixinWorkMessageAsyncLocal : IWeixinWorkMessageAsyncLocal
public class WeixinWorkAsyncLocal : IWeixinWorkAsyncLocal
{
public IWeixinWorkMessageOptions CurrentOptions { get; private set; }
public IWeixinWorkOptions CurrentOptions { get; private set; }

private readonly IWeixinWorkMessageAsyncLocalAccessor _weixinWorkMessageAsyncLocalAccessor;
private readonly IWeixinWorkAsyncLocalAccessor _weixinWorkAsyncLocalAccessor;

public WeixinWorkMessageAsyncLocal(IWeixinWorkMessageAsyncLocalAccessor weixinWorkMessageAsyncLocalAccessor)
public WeixinWorkAsyncLocal(IWeixinWorkAsyncLocalAccessor weixinWorkAsyncLocalAccessor)
{
_weixinWorkMessageAsyncLocalAccessor = weixinWorkMessageAsyncLocalAccessor;
_weixinWorkAsyncLocalAccessor = weixinWorkAsyncLocalAccessor;

CurrentOptions = weixinWorkMessageAsyncLocalAccessor.Current;
CurrentOptions = weixinWorkAsyncLocalAccessor.Current;
}

public IDisposable Change(IWeixinWorkMessageOptions weixinWorkMessageOptions)
public IDisposable Change(IWeixinWorkOptions weixinWorkOptions)
{
var parentScope = _weixinWorkMessageAsyncLocalAccessor.Current;
var parentScope = _weixinWorkAsyncLocalAccessor.Current;

_weixinWorkMessageAsyncLocalAccessor.Current = weixinWorkMessageOptions;
_weixinWorkAsyncLocalAccessor.Current = weixinWorkOptions;

return new DisposeAction(() =>
{
_weixinWorkMessageAsyncLocalAccessor.Current = parentScope;
_weixinWorkAsyncLocalAccessor.Current = parentScope;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace Masa.Mc.Infrastructure.Weixin.Work.Infrastructure.OptionsResolve.Contributors;

public class ConfigurationOptionsResolveContributor : IWeixinWorkMessageOptionsResolveContributor
public class ConfigurationOptionsResolveContributor : IWeixinWorkOptionsResolveContributor
{
public const string CONTRIBUTOR_NAME = "Configuration";
public string Name => CONTRIBUTOR_NAME;

public Task ResolveAsync(WeixinWorkMessageOptionsResolveContext context)
public Task ResolveAsync(WeixinWorkOptionsResolveContext context)
{
context.Options = context.ServiceProvider.GetRequiredService<IOptions<WeixinWorkMessageOptions>>().Value;
context.Options = context.ServiceProvider.GetRequiredService<IOptions<WeixinWorkOptions>>().Value;

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Masa.Mc.Infrastructure.Weixin.Work.Infrastructure.OptionsResolve;

public interface IWeixinWorkMessageOptions
public interface IWeixinWorkOptions
{
public string CorpId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Masa.Mc.Infrastructure.Weixin.Work.Infrastructure.OptionsResolve;

public interface IWeixinWorkMessageOptionsResolveContributor
public interface IWeixinWorkOptionsResolveContributor
{
string Name { get; }

Task ResolveAsync(WeixinWorkMessageOptionsResolveContext context);
Task ResolveAsync(WeixinWorkOptionsResolveContext context);
}
Loading

0 comments on commit 376546a

Please sign in to comment.