Dry goods sharing | The message management component of HZERO series components can meet your various sending needs

picture

In the process of project implementation, the following requirements often arise. It is necessary to send SMS emails or in-site message reminders to the corresponding agent, or some data in the system needs to be automatically sent when the data expires. For example, when the agreement expires, a message needs to be automatically sent. To remind the user that the agreement has expired.

Based on the above requirements, the message sending component provided by HZERO can realize the function of message sending through configuration and simple code to meet our needs .

 

Component overview

The message service supports the sending of messages such as SMS, mailboxes, on-site messages, and enterprise WeChat, and can flexibly manage message templates and connect to microservices supported by the cloud platform.

component coordinates

<dependency>    <groupId>org.hzero</groupId>    <artifactId>hzero-message-saas</artifactId></dependency>

Component Architecture Diagram

picture

 

In-Site Messaging Quick Start

The following is a simple in-site messaging configuration and development example to get you started quickly.

SMS plugin

The short message service of the message service needs to rely on the plug-in, otherwise the short message cannot be sent.

There are three plugins that can be added: Alibaba Cloud, Baidu Cloud, and Tencent Cloud.

  • Ali Cloud

<dependency>   <groupId>org.hzero.starter</groupId> <artifactId>hzero-starter-sms-aliyun</artifactId></dependency>
  • Baidu cloud

<dependency>   <groupId>org.hzero.starter</groupId>   <artifactId>hzero-starter-sms-baidu</artifactId></dependency>
  • Tencent Cloud

<dependency>   <groupId>org.hzero.starter</groupId>  <artifactId>hzero-starter-sms-qcloud</artifactId></dependency>

message template

Message templates are used to define and manage message templates used for message sending, so that users can directly use templates to send different types of messages.

Path: Message Management -> Message Template

picture

message sending configuration

By configuring and managing associated message sending, associated templates and sending servers. After the association is successful, you can test sending the message

Path: Message Management -> Message Sending Configuration

picture

message receiving configuration

Configure the default form of receiving messages for the user, and the user can select a specific receiving form in the receiving configuration of the personal center.

picture

Receiver configuration

Dynamically select users or groups of users to whom messages are received.

picture

code call

@Servicepublic class MessageServiceImpl implements MessageService {    private final MessageClient messageClient;    @Autowired    public MessageServiceImpl(MessageClient messageClient) {        this.messageClient = messageClient;    }    @Override    public void sendWebMessage() {        long tenantId = 0L;        String messageTemplateCode = "HWFP.REMIND";        String lang = "zh_CN";        Receiver receiver = new Receiver().setUserId(1L).setTargetUserTenantId(0L);        Map<String, String> args = new HashMap<>(16);        args.put("processName", "测试消息");        args.put("processDescription", "测试消息");        // 同步发送站内消息        messageClient.sendWebMessage(tenantId, messageTemplateCode, lang, Collections.singletonList(receiver), args);        // 异步发送站内消息        messageClient.async().sendWebMessage(tenantId, messageTemplateCode, lang, Collections.singletonList(receiver), args);    }}

 

Common API Call Reference

Send SMS

@Servicepublic class MessageServiceImpl implements MessageService {    private final MessageClient messageClient;    @Autowired    public MessageServiceImpl(MessageClient messageClient) {        this.messageClient = messageClient;    }    @Override    public void sendSms() {        long tenantId = 0L;        String serverCode = "HZERO";        String messageTemplateCode = "HIAM.CAPTCHA";        Receiver receiver = new Receiver().setIdd("+86").setPhone("18866886688");        Map<String, String> args = new HashMap<>(16);        args.put("captcha", "123456");        // 同步发送站内消息        messageClient.sendSms(tenantId, serverCode, messageTemplateCode, Collections.singletonList(receiver), args);        // 异步发送站内消息        messageClient.async().sendSms(tenantId, serverCode, messageTemplateCode, Collections.singletonList(receiver), args);    }}

 

send email

@Servicepublic class MessageServiceImpl implements MessageService {    private final MessageClient messageClient;    @Autowired    public MessageServiceImpl(MessageClient messageClient) {        this.messageClient = messageClient;    }    @Override    public void sendEmail() {        long tenantId = 0L;        String serverCode = "HZERO";        String messageTemplateCode = "HWFP.REMIND";        Receiver receiver = new Receiver().setEmail("[email protected]");        Map<String, String> args = new HashMap<>(16);        args.put("processName", "测试消息");        args.put("processDescription", "测试消息");        // 同步发送站内消息        messageClient.sendEmail(tenantId, serverCode, messageTemplateCode, Collections.singletonList(receiver), args);        // 异步发送站内消息        messageClient.async().sendEmail(tenantId, serverCode, messageTemplateCode, Collections.singletonList(receiver), args);    }}

 

In short, the message management component is a commonly used component in the project, through which we can simply configure the following functions:

  • The function of message sending;

  • Message monitoring function to monitor the success and failure of message sending;

  • Retry of failed messages;

  • Message mode customization, through program expansion, to achieve the effect of dynamic display.

 

contact us

Please log in to the open platform for product trial . Please open it on PC:

https://open.hand-china.com/market-home/trial-center/

For product details , please log in to the open platform:

https://open.hand-china.com/document-center/

If you have any questions, log in to the open platform for B/L feedback :

https://open.hand-china.com/

picture

picture

▲ For more exciting content, scan the code to follow  the  public account of "Sihai Hande"

 

 

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4580203/blog/5577455