Skip to content

Latest commit

 

History

History
65 lines (48 loc) · 2.86 KB

WeChatOfficial.md

File metadata and controls

65 lines (48 loc) · 2.86 KB

NotificationService.Provider.WeChatOfficial

ABP version NuGet NuGet Download Discord online GitHub stars

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

Usage

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

实现 IWeChatOfficialUserOpenIdProvider

你需要实现IWeChatOfficialUserOpenIdProvider,否则本模块无法获知目标用户的 OpenId。

Todo: demo

Create with Notification Factory

  1. Create a factory.

    public class UserWelcomeNotificationFactory :
        NotificationFactory<UserWelcomeNotificationDataModel, CreateWeChatOfficialTemplateMessageNotificationEto>,
        ITransientDependency
    {
        // 如果 appId 为空,则自动获取配置的 AbpWeChatOfficialOptions
        // 如果你指定了 appId,请自行实现 IAbpWeChatOptionsProvider<AbpWeChatOfficialOptions>
        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));