In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 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 WeChat Mini Programs realizes the forwarding function. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how WeChat Mini Programs realizes the forwarding function"! Next, please follow the editor to study!
The realization of WeChat Mini Programs's forwarding function
1. When users forward Mini Program to any group chat, they can get the shareTicket of this forwarding.
two。 When this forwarding card is opened by other users in a group chat, you can get another shareTicket in App.onLaunch () or App.onShow.
3. The same forwarding information can be obtained through the wx.getShareInfo () API for the shareTicket obtained in both steps.
The onShareAppMessage (options) function sets the forwarding information for the page.
Options parameter description:
From: the source of the forwarding event. Button: forwarding button on the page; menu: forwarding menu in the upper right corner
Target: if the from value is button, target is the button that triggered this forwarding event, otherwise it is undefined
Custom fields:
Return {title: 'forwarding', / / forwarding title (default: current Mini Program name) path:'/ pages/index/index', / / forwarding path (current page path), must be the full path starting with / success (e) {/ / shareAppMessage: ok, / / shareTickets array, each entry is a shareTicket Corresponding to a forwarding object / / you need to implement the interface wx.showShareMenu in the page onLoad () event ({/ / request Mini Program to return the sharing target information withShareTicket: true}) }, fail (e) {/ / shareAppMessage:fail cancel / / shareAppMessage:fail (detail message)}, complete () {}}
Wx.showShareMenu (OBJECT) forwarding with shareTicket.
1. In the process of debugging both SDK and real machine, it is necessary to set withShareTicket to true
two。 Otherwise, during the debugging of the real machine, even if the forwarded group chat is selected, shareTicket will not be returned.
OnLoad (e) {wx.showShareMenu ({withShareTicket: true})}, onShow (e) {wx.showShareMenu ({withShareTicket: true})}
Wx.getShareInfo (OBJECT) gets forwarding details
If (res.shareTickets) {/ / get forwarding details wx.getShareInfo ({shareTicket: res.shareTickets [0], success (res) {res.errMsg; / / error message res.encryptedData; / / decrypted to a JSON structure (the only ID of the openGId group to the current Mini Program) res.iv; / / initial vector of the encryption algorithm}, fail () {}, complete () {}});}
After Mini Program is opened in the group, get the situation value and shareTicket
/ / app.jsApp ({onLaunch: function (ops) {if (ops.scene = = 1044) {console.log (ops.shareTicket)})
Bug & Tip
1. The parameters passed between pages need to be received in the onLoad () function, but not in the onShow () function.
two。 To get the shareTicket of the Mini Program opened in the group chat, you need to go to App.onLaunch () or App.onShow (). It is not available in the life cycle function of the page.
3. When forwarding content to a single user, the shareTicket is not available.
At this point, the study on "how to achieve the forwarding function of WeChat Mini Programs" is over. I hope to be able to solve your 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.