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 does WeChat Mini Programs get the sharing link

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

The editor would like to share with you how WeChat Mini Programs gets the sharing link. I hope you will get something after reading this article. Let's discuss it together.

OnShareAppMessage at API level

If Mini Program wants to share, you must define an onShareAppMessage function in page to configure the page to share and forward relevant information.

Only if this event handler is defined, the forward button will be displayed in the upper right-hand menu.

Called when the user clicks the forward button

This event requires an Object for return to customize the forwarded content

There may be multiple shares on a page, and the inserted parameter options can be used to determine which location to share, thus making different logical judgments.

The return function of return object:

If the event is defined and you do not want to forward it through the page menu, you can hide it through hideShareMenu.

Note:

If imageUrl is not added after forwarding, the screenshot will be used as the default image for forwarding.

The from field can perform different operations on menu and button by calling success and complete after the forwarding is successful.

If the shareTicket value is carried, it will be generated in the success callback. The returned result is an array in the shareTickets field, which can be processed.

Wx.showShareMenu

It is generally used to configure related parameters, such as withShareTicket, which is used to obtain group information and group-related tags.

Wx.showShareMenu ({withShareTicket: true}) copy the code wx.hideShareMenu

The forwarding function at the menu level is hidden, but there is also forwarding in button.

If you first set showShareMenu and configure withShareTicket, and then use the hideShareMenu method and forward it through the button, you can still get shareTicket, as shown below:

Wx.showShareMenu ({withShareTicket: true}) wx.hideShareMenu ({}) copy code wx.updateShareMenu

To update shareMenu information, you need to use update operation. Note here that the withShareTicket attribute is usually updated.

Wx.getShareInfo

After getting the shareTicket information, you can get the forwarding details from this API.

Wx.getShareInfo ({shareTicket: res.shareTickets [0], success:... Fail:.}) copy the code

Parameters of the relevant callback

{errMsg: "getShareInfo:ok", iv: "gRHeFU+Nhr36RmladCXnRQ==", encryptedData: "IQ/RwZLeQFUGuxv0bBfOrL/KLnXO+bxcyCBru5lB92FkHIg8ae... 7TnHwUzzrqgerFKvpvS5JbFyhhammer 9liUqyb2bk6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Decrypted by iv and encryptedData, you can get the value of openGId. Is the unique value of the current group to the current Mini Program. In addition, you can get more open data, such as group names.

Button forwarding

When you need to forward within the page, you need to set the open-type= "share" to the button component and determine the source where it is triggered.

Get the process of sharing links

In Mini Program, there are two main ways to obtain openGId, and sharing-related development generally revolves around two ways:

When the user opens the withShareTicket card, the encrypted information can be obtained in onLauch or getShareInfo and passed to the server to get openGId.

When the user shares successfully, he will receive a shareTicket in the callback, and then use getShareInfo to get the encrypted information and get the openGId.

After reading this article, I believe you have a certain understanding of "how WeChat Mini Programs gets the sharing link". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

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