The implementation of the applet forwarding function and the applet forwarding
Implementation of the mini-program forwarding function
1. After you forward the applet to any group chat, you can get the shareTicket
2. When this forwarding card is opened by another user in the group chat, you can get another shareTicket in App. onLaunch () or App. onShow.
3. The shareTicket obtained in two steps can obtain the same forwarding information through the wx. getaskinfo () interface.
The onsellappmessage (options) function sets the forwarding information for this page.
Options parameter description:
From: forwards event sources. Button: The forward button in the page; menu: The forward menu in the upper right corner;
Target: If the from value is a button, target is the button that triggers this forwarding event; otherwise, it is undefined.
Custom field:
Return {title: 'forward', // forwarding title (default: Current applet name) path: '/pages/index/Index ', // The forwarding path (path of the current page), which must start with "success (e)" {// specify appmessage: OK, // shareTickets array. each item is a shareTicket, corresponding to a forwarding object // the wx interface must be implemented in the onLoad () event of the page. showShareMenu ({// requires the applet to return the shared object information withShareTicket: true}) ;}, fail (e) {// specify appmessage: fail cancel // specify appmessage: fail (detail message)}, complete (){}}
Wx. showShareMenu (OBJECT) with shareTicket forwarding.
1. During SDK and real machine debugging, you must set withShareTicket to true,
2. Otherwise, no shareTicket will be returned even if the forwarded group chat is selected during the debugging of the real machine.
onLoad(e) { wx.showShareMenu({ withShareTicket: true }) }, onShow(e) { wx.showShareMenu({ withShareTicket: true }) },
Wx. getdomaininfo (OBJECT) Get forwarding details
If (res. shareTickets) {// get detailed forwarding information wx. getaskinfo ({shareTicket: res. shareTickets [0], success (res) {res. errMsg; // error message res. encryptedData; // the decrypted data is a JSON structure (the unique ID of the openGId group for the current applet) res. iv; // initial vector of the encryption algorithm}, fail () {}, complete (){}});}
After the applet is opened in the group, it gets the scene value and shareTicket
//app.jsApp({ onLaunch: function (ops) { if (ops.scene == 1044) { console.log(ops.shareTicket) } }})
Bug & Tip
1. Parameters passing between pages must be received in the onLoad () function, but not in the onShow () function.
2. Get the shareTicket of the applet opened in the group chat, which must be in App. onLaunch () or App. onShow (). Page lifecycle functions cannot be obtained.
3. shareTicket cannot be obtained when forwarding content to a single user.
The above is the implementation of the mini-program forwarding function. If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article and hope to help you. Thank you for your support for this site!