preface

Only a bald head can be strong.

Star: github.com/ZhongFuChen…

If you have read my article recently, you will know that I have been working on a push system in my company. Push systems, also known as message management platforms in my office, are easy to understand: to provide a system that supports sending messages through multiple channels.

Some time ago, wechat announced that the small program template message interface will be offline on January 10, 2020, and developers can use the subscription message function.

You know what changes in the underlying interface mean to programmers.

When men sit at home, ban comes from heaven

This article mainly to talk about my side is how to send small program message, as well as a simple introduction after the revision, I hope to help you.

  • This article does not involve any advanced knowledge, rest assured to watch.

First, pre-knowledge

It is actually very simple to send small program messages. Wechat provides wechat official documents for us developers to consult relevant basic knowledge, and provides HTTP interfaces for us to call easily:

For developers, sending applets can be summed up in three steps:

  • Create templates in wechat background
  • Obtain the delivery permission
  • Call the send interface to send a message

The steps are the same for both the previous template message and now the new subscription message.

The difference between template and subscription messages

Why does wechat take the template message offline and subscribe to it online? From the point of view of the step of sending a small program, only “get the permission to deliver” is movable, and the other two steps are the same.

We developers want to use wechat platform to send messages to users, need a reason (send permission). Because wechat is still focused on user experience.

2.1 Template Messages

The reason for sending a template message is that the user has recently been active in the applet and has had interactive behavior (such as form submission). Developers can then collect formids from these interactions.

A formId is kept for 7 days, and we need to consume a formId when we call the send interface. If the user does not have a formId, we will fail to send it

  • Key points: sendTemplate messageBe sure to carryformId

In plain English, the formId is a credential for the user to interact with the applet. Wechat believes that you can only send a message to a user if he or she has recently used your mini program.

2.2 Subscription Message

From the reasons for sending template messages, we can find that the right to send template messages is in the hands of developers. As long as we collect a large number of formids through users’ various behaviors, we can send multiple messages to users within 7 days.

The reason for subscribing to a message is to give the user the right to push the message. The user decides whether to receive the push or not, which is simply:

  • Pop-ups are given to the user when certain scenarios are triggered, allowing the user to decide whether or not to receive a push (and only once)

2.3 Let users receive the messages they want

When you first started using wechat, you might get some small program notifications for marketing, but you probably won’t get them anytime soon.

  1. Do not induce malicious users to trigger operations so that templates can be delivered to users
  2. Malicious harassment is not allowed, and templates that cause harassment to users are delivered
  3. Malicious marketing is not allowed and the marketing purpose template is delivered

The title shall not involve marketing related content, including but not limited to: consumer incentives, shopping rebates, commodity updates, coupons, vouchers, red envelopes, membership cards, points, activities and other marketing trends notice

Wechat will check if there are any problems with your template and delete your template if there are any problems (of course, it will not let you create templates that may be marketing). Without templates, consumption can’t be sent out.

In summary: wechat will restrict your messages in various ways in order to let users receive the messages they want. This time, by changing the template message to a subscription message, the user is given the right to deliver the message.

Whether it’s a good thing or a bad thing. Different people have different views on it.

Some people will feel: let the user choose whether to receive the message, the user needs more operations, pop-ups are also a kind of bother to the user. If the user is unfamiliar with the subscription message or simply clicks “cancel,” the mini program can’t notify the user, and the user may miss out on the service, which is a loss for both the merchant and the user.

Some people also think that putting the right to push messages in the hands of users can largely avoid malicious harassment from merchants

Let us know what you think of this change in the comments section below

Three, how did we do it?

Here I will briefly say how I access to push small program message, I hope to access the small program message of the students have certain help.

First of all, for the templates created in the wechat background, we first pull the templates from the wechat background to our own database and save them, and then make a management page to manage the templates.

If a message uses the template, we also associate it (because it’s easy to see which messages use the template)

  • Because of this feature, it is very easy to sort out which templates are still in use and which scenarios are being used. Then you simply change the template ID of the message to the template ID of the subscription message.

Like my division not only a small program, so to the small program classification, here is no longer described. In fact, it encapsulates a layer. For example, the logo of Mogujie women’s wear is 88, and the logo of Mogujie live shopping station is 99

Design and write code with subsequent extensibility in mind

In the template message, the front end will type formId dot, I will Storm MQ data cleansing into Redis. And then I’m going to determine if the user has a formId before I send it.

Now wechat has changed the template message to subscription message, and the operation of collecting formId to my Storm to parse into Redis is not needed. Wechat also doesn’t seem to provide an interface for me to determine whether a user is authorized. Therefore, I can only determine whether the user is authorized based on the return value when I call the delivery interface.

If you are newly connected to the wechat mini program message, the whole process will be much simpler.

  • The front end of the students as long as the necessary scenarios popup, so that the user authorization
  • The classmate of the backend directly delivers the information to the user and determines the delivery situation according to the returned value.

Therefore, there are two main steps for me to send a message:

  1. Create a message in the push background (select wechat template, basic information of message creator, message-related rule processing (whether to delete duplicate, etc.)
  2. The business side calls the interface I expose

The business side calls my exposed interface, and I mainly do the following:

  1. The incoming parameters of the business side are simply validated to concatenate into a complete template message content
  2. If the business incoming isuserIdMy side needs to convertopenId
  3. To limit the message speed, call the delivery interface of wechat

In addition to the message delivery, we will also consider whether the message delivery is successful and the effect (whether there is real-time data for viewing, whether there is offline report analysis), so I do as follows:

  • Key links are deployed
    • The business side called my interface and I have confirmed receiving the message
    • This message was filtered out for business reasons (possibly userId to openId failed)
    • It may be delivered because the template /token/ user is not authorized
  • The data is written to Kafka, cleaned by Storm, queried into Redis in real time, and dumped into Hive tables offline

Here the dot is actually we type log

For example, here is my real-time push, according to the userId query push situation:

The last

In general, it is not difficult for applets to push messages, and it is just a few interfaces. Now that it’s a subscription message, it’s much easier to access. In a month or so, you’ll probably get pop-ups telling you whether or not to authorize the XXX template message when you use the applet.

I don’t know what you think of this post, feel free to leave a comment in the comments section. I will often share my problems in work and carefully arranged notes after study, hoping to be helpful to you. If you think there is something in my article, you might as well pay attention to me!

This has been included in my GitHub featured articles, welcome to Star: github.com/ZhongFuChen…

Happy to export dry Java technology public number: Java3y. The public account has more than 300 original technical articles, massive video resources, beautiful brain map, attention can be obtained!

Thank you very much talent can see here, if this article is written well, feel “three crooked” I have something to ask for praise for attention ️ to share 👥 to leave a message 💬 for warm male I really very useful!!

Creation is not easy, your support and recognition, is the biggest motivation for my creation, we will see you in the next article!