The implementation of the WeChat applet forwarding function and the WeChat applet forwarding function

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.