WeChat Open Platform

Mini Programs Documentation

Forwarding

onShareAppMessage

Defines onShareAppMessage function on a page and sets forwarding information on this page.

  • The menu in the top right corner will only display the Forward button if the processing function for this event has been defined.
  • It will be called when a user clicks on the Forward button.
  • This event needs to return an object, the user can customize the content to be forwarded.

Custom forwarding fields

Field Description Default value Minimum version
title Forwarding title Current Mini Program name
path Forwarding path Current page path, must be a full path with a / at the beginning
success Forwarding successful callback
fail Forwarding failed callback
complete Forwarding completed callback (will be executed if forwarding succeeds or fails)

Callback results:

Callback type errMsg Description
success shareAppMessage:ok Forwarding successful
fail shareAppMessage:fail cancel User canceled forwarding
fail shareAppMessage:fail (detail message) Forwarding failed, wherein detail message is detailed failure information

success callback parameter descriptions:

Parameter Type Description Minimum version
shareTickets Array String shareTicket array, each item is a shareTicket, the corresponding forwarding object

Sample code:

Page({
  onShareAppMessage: function () {
    return {
      title: 'Custom forwarding title',
      path: '/page/user?id=123',
      success: function(res) {
        // Forwarding successful
      },
      fail: function(res) {
        // Forwarding failed
      }
    }
  }
})

wx.showShareMenu(OBJECT)

Displays Forward button on current page

OBJECT parameter descriptions:

Parameter Type Required Description
withShareTicket Boolean No Whether using forwarding with shareTicket Details
success Function No Callback function for successful interface call
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

Sample code:

wx.showShareMenu({
  withShareTicket: true
})

wx.hideShareMenu(OBJECT)

Hides Forward button

OBJECT parameter descriptions:

Parameter Type Required Description
success Function No Callback function for successful interface call
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

Sample code:

wx.hideShareMenu()

wx.getShareInfo(OBJECT)

Get detailed information on forwarding

OBJECT parameter descriptions:

Parameter Type Required Description
shareTicket String Yes shareTicket
success Function No Callback function for successful interface call
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

CALLBACK parameter descriptions:

Parameter Type Description
errMsg String Error message
rawData String Raw data strings that do not contain sensitive information, used to calculate signatures
signature String Strings obtained using sha1( rawData + sessionkey ), used to verify forwarded information, refer to signature.
encryptedData String Complete encrypted forwarded information data including sensitive data, refer to Decryption Algorithms for Encrypted Data for more details
iv String The encryption algorithm's initialization vector, refer to Decryption Algorithms for Encrypted Data for more details

The encryptedData is a JSON structure after being decrypted. It contains the following fields:

Field Description
openGId The group's unique ID for the current Mini Program

Get more forwarding information

Developers usually want to be able to get some information the second time the Mini Program they have shared is opened, such as the group identity. By calling wx.showShareMenu and setting withShareTicket as true, after a user shares a Mini Program with any group chat, they can now get the shareTicket forwarded this time. When this forwarded card is opened by another user in the group chat, they can get another shareTicket in App.onLaunch(). The same forwarding information can be obtained from both of the shareTickets obtained in these two steps using the wx.getShareInfo() interface.

Bugs & Tips
  1. tip: Forwarding images cannot be customized. Images taken from the current page with a height of 80% of the screen width will be used as images for forwarding.
  2. tip: Please see Ordinary Forwarding Debugging Support and Forwarding With shareTickets for details on forwarding debugging support.
  3. tip: If shareTickets return values can only be obtained when shared with a group chat and opened, a single chat will not have shareTickets.
  4. tip: shareTickets are only valid during the current Mini Program lifecycle.
  5. tip: Developers may first use the group ID in the wx.getShareInfo interface to perform feature development due to strategy changes or adjustments to the capabilities related to Mini Program groups.