# NotificationService.Provider.WeChatOfficial

ABP version (opens new window) NuGet (opens new window) NuGet Download (opens new window) Discord online (opens new window) GitHub stars (opens new window)

微信服务号用户通知提供者。目前唯一的通知方式为公众号模板消息。

# Usage

You can create a notification using a notification factory or manually.

# Create with Notification Factory

  1. Create a factory.

    public class UserWelcomeNotificationFactory :
        NotificationFactory<UserWelcomeNotificationDataModel, CreateWeChatOfficialTemplateMessageNotificationEto>,
        ITransientDependency
    {
        // 如果 appId 为空,则自动获取配置的 AbpWeChatOfficialOptions
        // 如果你指定了 appId,请自行实现 IAbpWeChatOfficialOptionsProvider
        var appId = "my-official-appid";
        var templateData = new TemplateMessage($"Hello, {model.UserName}", "Thank you");
    
        templateData.AddKeywords("gift-card-code", model.GiftCardCode);
    
        var dataModel = new WeChatOfficialTemplateMessageDataModel("my-template-id", new MiniProgramRequest
        {
            AppId = "my-mini-program-appid",
            PagePath = "my-mini-program-page-path"
        }, "https://github.com", templateData, appId);
    
        return Task.FromResult(
            new CreateWeChatOfficialTemplateMessageNotificationEto(CurrentTenant.Id, userIds, dataModel));
    }
    
  2. Use the factory to create a notification and publish it.

    var eto = await userWelcomeNotificationFactory.CreateAsync(
        model: new UserWelcomeNotificationDataModel(userData.UserName, giftCardCode),
        userId: userData.Id
    );
    
    await distributedEventBus.PublishAsync(eto);
    

# Create Manually

Publish the notification.

await distributedEventBus.PublishAsync(
    new CreateWeChatOfficialTemplateMessageNotificationEto(
        CurrentTenant.Id, userIds, dataModel));
Last Updated: 11/18/2022, 9:10:36 AM