WeChat applet sharing with invitation code parameters

Example scenario:
User a shares an interface of user b. This interface includes the invitation code. When user b clicks, the invitation code in the interface shared by a will be obtained. At this time, user a will display a list of friends who have successfully shared .

Insert picture description here
Join on the share button open-type="share"
Insert picture description here
Write events in the js page

onShareAppMessage: function () {
    
    
  return {
    
    
    title: '',   // 图片标题
    path: '/pages/my/my?code=' + code,  //分享路径 ,code可以是邀请码,也可以是分享某个具体商品的id,如果是邀请码就是后端给你的
    imageUrl: "",  //图片地址,也可以不设置,就会默认当前缩略图作为分享封面男
    success: (res) => {
    
    
    
    }
  }
},

When user b clicks on the page shared by a, he only needs to get the invitation code
in the link of a on the shared page and get it on onLoad

  onLoad:function(options){
    
    
  //如果邀请码是123, 是以这种形式/pages/my/my?code=123
    console.log(decodeURIComponent(options.code))
 //可以打印出来,打印出来就是123
  },

If you have any questions, you can ask, this article is your own project notes

Guess you like

Origin blog.csdn.net/qq_45432996/article/details/106942424