WeChat mini game forwarding and sharing

WeChat mini game forwarding and sharing

Please follow me on Weibo: @NormanLin_BadPixel Bad Pixel


The official tutorial on forwarding . (The official tutorial is still very detailed. After the author wrote it, he found that the official had already said everything I could.)


Here is the simplest forwarding and sharing function. Complex sharing also distinguishes between sharing to individuals, sharing to groups, and returning a bunch of information.

Click the button to share

Share : function(){
    //share 
    wx.shareAppMessage({
        title:'这游戏可得劲儿了,快来玩吧!",
        success:function(res){
            //成功
        },
        fail:function(res){
            //失败
        }
    });
},

Then just call this method on the button's click event.
Here is the official API , you can refer to the API to customize the sharing content, such as adding pictures.

top right button share

onLoad () {
    wx.showShareMenu();
    wx.onShareAppMessage(
        function(){
            return {
                title : "我的游戏",
            }
        }
    );
},

Many people say that they have set onShareAppMessage but it has no effect. In fact, it is because wx.showShareMenu() is not called. Wechat hides the share menu bar by default, and we have to show it.

Here is the official tutorial on forwarding , which talks about how to display the content of Canvas when forwarding , so I stole it and posted it for everyone to see.

wx.onShareAppMessage(function () {
  return {
    title: '转发标题',
    imageUrl: canvas.toTempFilePathSync({
      destWidth: 500,
      destHeight: 400
    })
  }
})

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325815420&siteId=291194637