Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions Masa.Mc.sln

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/ApiGateways/Caller/Masa.Mc.ApiGateways.Caller/McCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class McCaller : StackHttpClientCaller
#region Field
ChannelService? _channelService;
MessageTemplateService? _messageTemplateService;
WeixinMiniProgramTemplateService? _weixinMiniProgramTemplateService;
ReceiverGroupService? _receiverGroupService;
SmsTemplateService? _smsTemplateService;
MessageTaskService? _messageTaskService;
Expand All @@ -24,6 +25,8 @@ public class McCaller : StackHttpClientCaller

public MessageTemplateService MessageTemplateService => _messageTemplateService ?? (_messageTemplateService = new(Caller));

public WeixinMiniProgramTemplateService WeixinMiniProgramTemplateService => _weixinMiniProgramTemplateService ?? (_weixinMiniProgramTemplateService = new(Caller));

public ReceiverGroupService ReceiverGroupService => _receiverGroupService ?? (_receiverGroupService = new(Caller));

public SmsTemplateService SmsTemplateService => _smsTemplateService ?? (_smsTemplateService = new(Caller));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.ApiGateways.Caller.Services.MessageTemplates;

public class WeixinMiniProgramTemplateService : ServiceBase
{
protected override string BaseUrl { get; set; }

internal WeixinMiniProgramTemplateService(ICaller caller) : base(caller)
{
BaseUrl = "api/weixin-mini-program-template";
}

public async Task<List<WeixinMiniProgramTemplateDto>> GetListAsync(Guid channelId)
{
return await GetAsync<List<WeixinMiniProgramTemplateDto>>($"channels/{channelId}/templates") ?? new();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.MessageReceipts;

public class WeixinMiniProgramReceiptInput
{
public string OpenId { get; set; } = string.Empty;

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

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

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

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

public DateTimeOffset ReceiveTime { get; set; } = DateTimeOffset.UtcNow;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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.Imports;

public class WeixinMiniProgramReceiverImportDto
{
[ImporterHeader(Name = "OpenId", IsAllowRepeat = false)]
[Required(ErrorMessage = "OpenId是必填的")]
public string OpenId { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public void SetChannelUserIdentity(ChannelTypes channelType, string channelUserI
case ChannelTypes.WebsiteMessage:
SubjectId = new Guid(channelUserIdentity);
break;
case ChannelTypes.WeixinWork:
case ChannelTypes.WeixinWorkWebhook:
case ChannelTypes.WeixinMiniProgram:
Account = channelUserIdentity;
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ public MessageTaskUpsertDtoValidator()
RuleFor(inputDto => inputDto.ChannelId).Required().When(m => !m.IsDraft);
RuleFor(inputDto => inputDto.EntityId).Required().When(m => m.EntityType == MessageEntityTypes.Template).When(m => !m.IsDraft);
RuleFor(inputDto => inputDto.EntityType).IsInEnum().When(m => !m.IsDraft);
RuleFor(inputDto => inputDto.EntityType)
.Equal(MessageEntityTypes.Template)
.WithMessage("WeixinMiniProgramOnlySupportsTemplateMessage")
.When(m => m.ChannelType == ChannelTypes.WeixinMiniProgram && !m.IsDraft);
RuleFor(inputDto => inputDto.ReceiverType).IsInEnum().When(m => !m.IsDraft);
RuleFor(inputDto => inputDto.ReceiverType)
.NotEqual(ReceiverTypes.Broadcast)
.WithMessage("WeixinMiniProgramDoesNotSupportBroadcast")
.When(m => m.ChannelType == ChannelTypes.WeixinMiniProgram && !m.IsDraft);
RuleFor(inputDto => inputDto.SelectReceiverType).IsInEnum().When(m => !m.IsDraft);
RuleFor(inputDto => inputDto.Receivers).Required().When(m => m.ReceiverType == ReceiverTypes.Assign && !m.IsDraft);
RuleFor(inputDto => inputDto.MessageInfo).SetValidator(new MessageInfoUpsertDtoValidator()).When(m => m.EntityType == MessageEntityTypes.Ordinary).When(m => !m.IsDraft);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.MessageTemplates;

public class WeixinMiniProgramTemplateDto
{
public Guid ChannelId { get; set; }

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

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

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

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

public int TemplateType { get; set; }

public List<MessageTemplateItemDto> Items { get; set; } = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.Options.Channels;

public class WeixinMiniProgramChannelOptions
{
public string AppId { get; set; } = string.Empty;

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

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

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

public string MiniprogramState { get; set; } = "formal";

public string Lang { get; set; } = "zh_CN";
}
3 changes: 2 additions & 1 deletion src/Domain/Masa.Mc.Domain.Shared/Channels/ChannelTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public enum ChannelTypes
App,
WeixinWork,
WeixinWorkWebhook,
}
WeixinMiniProgram,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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.Domain.Shared.MessageTemplates;

public enum WeixinMiniProgramTemplateTypes
{
OneTime = 2,
LongTerm = 3
}
35 changes: 34 additions & 1 deletion src/Domain/Masa.Mc.Domain/Channels/Aggregates/ChannelType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

public static ChannelType WeixinWorkWebhook = new WeixinWorkWebhookChannel();

public static ChannelType WeixinMiniProgram = new WeixinMiniProgramChannel();

Check failure on line 20 in src/Domain/Masa.Mc.Domain/Channels/Aggregates/ChannelType.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change the visibility of 'WeixinMiniProgram' or make it 'const' or 'readonly'.

See more on https://sonarcloud.io/project/issues?id=masastack_MASA.MC&issues=AZ9-qWodQLX0TfryHm95&open=AZ9-qWodQLX0TfryHm95&pullRequest=676

Check warning on line 20 in src/Domain/Masa.Mc.Domain/Channels/Aggregates/ChannelType.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make this field 'private' and encapsulate it in a 'public' property.

See more on https://sonarcloud.io/project/issues?id=masastack_MASA.MC&issues=AZ9-qWodQLX0TfryHm94&open=AZ9-qWodQLX0TfryHm94&pullRequest=676

public ChannelType(int id, string name) : base(id, name)
{
}
Expand Down Expand Up @@ -193,4 +195,35 @@

public override bool SupportsBroadcast => false;
}
}

private class WeixinMiniProgramChannel : ChannelType

Check warning on line 199 in src/Domain/Masa.Mc.Domain/Channels/Aggregates/ChannelType.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Private classes which are not derived in the current assembly should be marked as 'sealed'.

See more on https://sonarcloud.io/project/issues?id=masastack_MASA.MC&issues=AZ9-qWodQLX0TfryHm93&open=AZ9-qWodQLX0TfryHm93&pullRequest=676
{
public WeixinMiniProgramChannel() : base(7, nameof(WeixinMiniProgram)) { }

public override SendMessageEvent GetSendMessageEvent(Guid channelId, MessageData messageData, MessageTaskHistory messageTaskHistory)
{
return new SendWeixinMiniProgramMessageEvent(channelId, messageData, messageTaskHistory);
}

public override SendSimpleMessageEvent GetSendSimpleMessageEvent(string channelUserIdentity, string channelCode, MessageData messageData, ExtraPropertyDictionary variables, string systemId)
{
return new SendSimpleWeixinMiniProgramMessageEvent(channelUserIdentity, channelCode, messageData)
{
Variables = variables,
SystemId = systemId
};
}

public override RetryMessageEvent GetRetryMessageEvent(Guid messageRecordId)
{
return new RetryWeixinMiniProgramMessageEvent(messageRecordId);
}

public override string GetChannelUserIdentity(UserModel user)
{
return string.Empty;
}

public override bool SupportsBroadcast => false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public void UpdateResult(bool success, string failureReason)
{
Success = success;
FailureReason = failureReason;

if (MessageTaskHistoryId != Guid.Empty)
{
AddDomainEvent(new UpdateMessageTaskHistoryStatusEvent(MessageTaskHistoryId));
}
}

public virtual T GetDataValue<T>(string name)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.Domain.MessageRecords.Events;

public record RetryWeixinMiniProgramMessageEvent : RetryMessageEvent
{
public RetryWeixinMiniProgramMessageEvent(Guid messageRecordId)
: base(messageRecordId)
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.Domain.MessageTasks.Events;

public record SendSimpleWeixinMiniProgramMessageEvent : SendSimpleMessageEvent
{
public ExtraPropertyDictionary Variables { get; set; }

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

public SendSimpleWeixinMiniProgramMessageEvent(string channelUserIdentity, string channelCode, MessageData messageData)
: base(channelUserIdentity, channelCode, messageData)
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.Domain.MessageTasks.Events;

public record SendWeixinMiniProgramMessageEvent : SendMessageEvent
{
public SendWeixinMiniProgramMessageEvent(Guid channelId, MessageData messageData, MessageTaskHistory messageTaskHistory)
: base(channelId, messageData, messageTaskHistory)
{

}
}
Loading
Loading