The applet shares and carries parameters, which is convenient for distribution, group grouping, commission rebate and other functions

Recently, we are doing community group buying and grouping functions. We need to share with friends through small programs and let friends help. When sharing, we need to carry parameters, so by the way, we will study the sharing of small programs and carry parameters. . In fact, the code is very simple, but it is a little troublesome when testing.

Preliminary preparation

1. There must be two WeChats
. 2. Both WeChats need to be the developers of this applet.
3. Both WeChats must scan the QR code to preview the QR code during testing.

1. Prepare to test WeChat

There is no need to say this. If you want to test and share, you must have at least two WeChat IDs.

2. Grant developer permission to test WeChat

In fact, adding developer permissions is very simple, but only the administrator of the applet can add it.

Three, code development

I have two pages here share and home
share is the page used for sharing
home is the page used to accept sharing parameters

3-1, share.js code is as follows


The code is actually very simple, just rewrite the onShareAppMessage method, then set the share title, set the path, and then splice the parameters in the path. This kind of splicing is not destined to carry a large amount of data, so if you want to share a large amount of data, you'd better think of another way.

3-2, home.js accepts shared parameters

Then home.js does one thing, gets the parameters carried by the share, and prints them on the page.

After getting the parameters, you can do whatever you want, but here I print the parameters for the convenience of everyone to learn. on the page.
The following

renderings

Fourth, how to test

Next is the main event, the code is written, how to test it?

4-1, generate preview QR code

It is important to remember that it must be experienced on the phone through the preview. Emulators don't work.

4-2, both the sharer and the shared person must scan the code

Both the person sharing and the person being shared must scan the preview QR code above. In fact, there will be a prompt like the following when you share.

4-3, after scanning, you can start sharing

For example, wechat programming small stone to share with Wechat Qiu Shi

Share to Wechat Qiu Shi

After Qiu Shi receives it,

click on the development and share card, and you can see the parameters carried by the share on the page.

In this way, you can use this parameter to happily do what you want to do later.

Guess you like

Origin blog.csdn.net/qiushi_1990/article/details/115182621