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 forward Mini Program

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Today, Xiaobian will share with you the relevant knowledge points on how to realize forwarding of Mini programs. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you will gain something after reading this article. Let's find out together.

Meaning of forwarding

Forwarding is sharing, sharing drives things to be decentralized, networked, and ultimately cloud processed.

Through WeChat platform, forwarding is chat

In the era of traffic, forwarding is drainage

Official forwarding example

onShareAppMessage(Object)

Monitor the behavior of users clicking the forward button (component open-type="share") in the page or the "forward" button in the upper right corner menu, and customize the forwarding content. Note: Only if this event handler is defined will the Forward button appear in the upper right menu

Object Parameter Description:

This event needs to return an Object, which is used to customize the forwarding content. The returned content is as follows:

Custom forwarding content

Page({ onShareAppMessage(res) { if (res.from === 'button') { //From the forward button within the page console.log(res.target) } return { title: 'Custom forwarding title', path: '/page/user? id=123' } }})

General forwarding, just the example above

Define forwarding content and necessary parameters in onShareAppMessage, such as? id=123

You can get it in onLoad(Object query) on the corresponding page.

Distinguish according to scene value

For Mini programs, scene values can be obtained in the App's onLaunch and onShow, or wx.getLaunchOptionsSync

Because onLaunch is triggered only once globally and because of warm start, it is reasonable to obtain and set relevant parameters in onShow, especially forwarding. From WeChat messages, onShow will inevitably be triggered.

Get scene values via app.onShow callback

App({ onShow(res) { console.log ('app---onShow'); console.log(res.scene); //1044 is Group chats, 1007 is Private}})

wx.onAppShow(function callback)

Basic library 2.1.2 is supported, lower versions need compatibility processing

Listen for Mini programs to switch to foreground events. This event is consistent with App.onShow's callback parameters

Object res

Structure of referrerInfo

Scenes that return valid referrerInfo

note

Some versions will return undefined when there is no referrerInfo. It is recommended to use options.referrerInfo & options.referrerInfo.appId to judge.

Mini programs shareTickets

Mini programs that developers usually want to forward can obtain some information when they are opened twice, such as the group identification. Now by calling wx.showShareMenu and setting withShareTicket to true, when a user forwards Mini programs to any of the Group chats and the forwarded card is opened by other users in the Group chats, you can get a shareTicket in App.onLaunch or App.onShow. The forwarding information can be obtained by calling the wx.getShareInfo() interface and passing this shareTicket.

Like scene value, shareTicket is also reasonably obtained in App.onShow.

The wx.showShareMenu method must be called before sharing, otherwise there will be no share ticket

//share before share.jsPage({ onLoad: function () { wx.showShareMenu({ withShareTicket: true }) }})//app.jsApp({ onShow(res) { console.log('app---onShow'); console.log(res.shareTicket); }})

shareTicket has value only if shared with any Group chats, otherwise undefined

shareTicket can also be used to distinguish between scenarios where messages are forwarded

shareTicket is mainly used to obtain forwarding details. Pass it into wx.getShareInfo() to obtain encrypted data. Backend cooperation is required. Decrypted data is returned.

Attention: Attention

In view of the adjustment of the official "sharing monitoring" ability, 90% of the lagging codes on the Internet are misleading children. Here, we must give ourselves a small requirement to repeat our own articles regularly, improve the quality of articles according to the ability level at that time, correct errors and lagging information (spit out that the mother is dead, no one hit me? Hit me and delete)

Similar to the following code, callback is no longer supported

This adjustment may affect the usage of three sharing functions

The first type: judge whether the user shares successfully, and then reward the user.

For example: Mini programs prompt users to "share to 5 groups, you can get a 20 yuan coupon."

This kind of behavior that induces users to share is not advocated by our platform, and there will be no way to realize it later.

The second type: change the current page status after sharing is completed

For example, in the gift scene, the user clicks the "Gift" button to share the gift. After successful sharing, the interface displays "Waiting for Collection."

In this kind of scenario, we suggest that the interaction scheme can be adjusted appropriately. For example, after sharing, keep the "gift" button, but prompt the user on the page that a gift can only be received by one person, and repeated gifts are invalid.

The third method is to obtain the group unique identifier openGId through the shareTicket after the user shares, so as to display the related information of the corresponding group.

For example, by sharing Mini programs into a group, you can view the leaderboard of members in that group.

After this adjustment, the leaderboard information of the group cannot be displayed immediately after the user shares, but the leaderboard information of the group can still be displayed when the user clicks into Mini programs from the group message.

For details, please see Share Monitoring Ability Adjustment

Forward dynamic messages

Starting with base library 2.4.0, forwarding dynamic messages is supported. Compared with ordinary messages, dynamic messages have the following characteristics:

After the message is sent, developers can modify part of the message content through the background interface.

The message has a corresponding reminder button. Users can subscribe to the reminder by clicking the reminder button. Developers can modify the message status through the background and push a reminder message to the user who subscribed to the reminder.

The brief steps are as follows

(Backend call) Each dynamic message can be understood as an activity. Before the activity is initiated, an activity_id needs to be created through the createActivityId interface. This activity_id needs to be passed in for subsequent forwarding and updating of dynamic messages.

By calling the wx.updateShareMenu interface, parameters such as isUpdatableMessage: true are passed

(Backend call) After dynamic message is sent, message content can be modified by setUpdatableMsg

For activities like group fighting, we can consider optimizing them into dynamic messages, which need back-end cooperation and can be supplemented in actual combat.

The above is all the contents of this article "How to realize forwarding of Mini programs." Thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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