公共通知模块

sodo-common-notify

sodo-common-notify 使得在系统运行时可以让smsmailwxding 通知的启用状态、模板内容是可配置的。

1. 在Maven的Pom.xml中引入sodo-common-notify项目

<dependency>
    <groupId>com.shuodao</groupId>
    <artifactId>sodo-common-notify</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

2.继承Controller提供配置页面

public class NotifyConfigCongroller extends CommonNotifyBaseController{

    @PostConstruct
    public void init(){
        notifyManager.addPage("平台管理员消息通知配置", new NotifyParamInterface() {
                @Override
                public String getWxAppId(String belong) {
                    return WxAccountManager.getWxManagerAppId();
                }

                @Override
                public DingNotifyParam getDingNotifyParam(String belong) {
                    return null;
                }
            })
            .config($.NOTIFY.COMPANY_REGISTER, "新用户注册", null, "companyName", "phone") //提供通知事件配置
            .disable(NotifyWay.mail)    //禁用的通道将不在配置页面显示
            .receiverMode(NotifyAdminPage.ReceiverMode.AUTO) //配置接收人模式为AUTO时,配置页面将不提供手动维护接收人功能,
        ;
    }

    @Override
    protected Belong belong() {
        return $.BELONG.ADMIN;
    }
}

3.发送消息通知

//In Spring context.
@Resource 
private CommonNotifyManager notifyManager;

ParamMap param = ParamMap.create("phone", phone, "companyName", company);

//使用配置页面指定的接收人
notifyManager.notify($.NOTIFY.COMPANY_REGISTER, $.BELONG.ADMIN, param);

//代码指定接受者
notifyManager.notify($.NOTIFY.COMPANY_REGISTER, $.BELONG.ADMIN, param, new NotifyReceiver() {
        @Override
        public String getName() { return "name"; }

        @Override
        public String getPhone() { return "receiver's phone number";}

        @Override
        public String getEmail() { return "receiver's email address";}

        @Override
        public String getOpenId() { return "receiver's wechat open id"; }

        @Override
        public String getDingId() { return "receiver's dingding id"; }
    }
);
Copyright © Sodo Tech 2014-2018 all right reserved,powered by Gitbook最后更新: 2018-08-10 23:37

results matching ""

    No results matching ""