Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize WeChat Mini Programs's forwarding function

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to realize the forwarding function of WeChat Mini Programs". In the daily operation, I believe that many people have doubts about how to realize the forwarding function of WeChat Mini Programs. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about how to realize the forwarding function of WeChat Mini Programs! Next, please follow the editor to study!

Mini Program forwarding function is the most basic function of Mini Program, and there are four ways to achieve this effect.

1. Page.onShareAppMessage ({})

Set the "forwarding" configuration in the upper right corner, and the callback function returns shareTicket ticket after forwarding.

2. Wx.showSahreMenu ()

When the user clicks the upper right corner, the forward button is displayed.

3. Wx.hideShareMenu ()

Hide the forward button, ignoring Page.onShareAppMessage ({})

4. Wx.getShareInfo ({})

Obtain encrypted group information according to shareTicket

Split the forwarding process: configure before forwarding-> when forwarding-> open after forwarding to the group-> second forwarding

Forwarding flowchart:

Write the picture description here.

U1: user

T1Magol T2 T3: indicates forwarded ticket, i.e. shareTicket

G1Magol G2G3: group

1. Pre-forwarding configuration

Add in the page onLoad method

1 wx.showShareMenu ({

2 withShareTicket: true

3})

If withShareTicket is true, it indicates whether shareTicket is carried when forwarding is allowed.

ShareTicket is a ticket for obtaining and forwarding target group information. Only if you have a shareTicket can you get the group information. Users will generate a unique shareTicket for each forwarding.

ShareTicket has two uses:

After being forwarded actively, the user obtains the information of forwarding to the target group, which corresponds to the UI in the figure above.

Users open Mini Program in the group to get group information, corresponding to the users in the G1 group in the picture above.

two。 Get group information when forwarding

When a Mini Program is forwarded to the group, the developer wants to get the forwarding target group information and make a binding relationship between the user and the group (openId + openGid).

1 onShareAppMessage: function () {

2 return {

3 title: 'custom forwarding header'

4 path:'/ page/user?id=123'

5 success: function (res) {

6 var shareTickets = res.shareTickets

7 if (shareTickets.length = = 0) {

8 return false

9}

10 wx.getShareInfo ({

11 shareTicket: shareTickets [0]

12 success: function (res) {

13 var encryptedData = res.encryptedData

14 var iv = res.iv

15}

16})

17}

18 fail: function (res) {

19 / / forwarding failed

20}

21}

22}

ShareTickets is an array, each item is a shareTicket, corresponding to a forwarding object, forwarded to the user will not contain shareTicket.

After getting the shareTicket, use the wx.getShareInfo ({}) method to pass in the shareTicket parameter. The callback function in wx.getShareInfo ({}) contains the encrypted group information and vector IV.

3. Open after forwarding to the group

After users forward Mini Program to Wechat group, group members open Mini Program, and through shareTicket, developers can bind group members to group members (openId + openGid). Based on group relationships, Mini Program has more application scenarios, such as Arena of Valor Group ranking, mobike.

1 Page ({

2 onLoad: function (opt) {

3 / * * determine the scenario value. 1044 is a forwarding scenario, including the shareTicket parameter * /

4 if (opt.scene = = 1044) {

5 wx.getShareInfo ({

6 shareTicket: opt.shareTicket

7 success: function (res) {

8 var encryptedData = res.encryptedData

9 var iv = res.iv

10}

11})

12}

13}

14})

When you open Mini Program in a group, the page onLoad or onShow method contains scene and shareTicket. You need to determine whether the scene is 1044. If not, the shareTicket parameter in opt is not included.

4. Secondary forwarding

The second forwarding repeats the first three steps, there is nothing to say, but there is a direction worth discussing, whether the Mini Program forwarding path can be compared to a forwarding chain, and then generate a forwarding tree. use data structure methods (tree, Markov chain) to find the subtle relationship between group and group, group and member.

As in the picture at the beginning, we can easily see the forwarding chain and the forwarding tree.

Forwarding chain: U1 > G1 > G2

Forwarding tree: U1 > G1 > G2 & G3

At this point, the study on "how to achieve WeChat Mini Programs forwarding function" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report