微信小程序分享到朋友圈

目前分享朋友圈只支持安卓8以上平台,官方文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
成功或失败的回调根据自己的需求和官方文档写

onShow() {
    
    
	// 在右上角菜单 "...”中显示分享,menus可以单写转发shareAppMessage,分享朋友圈必须写shareAppMessage和shareTimeline
	wx.showShareMenu({
    
    
	  	withShareTicket: true,
	  	menus: ['shareAppMessage', 'shareTimeline']
	});
},
// 转发
onShareAppMessage: function () {
    
    
		return {
    
    
		 	title: '名称',
			path: '/pages/main/main', // 点击访问的页面
			imageUrl: '',     //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。
	  	}
},
// 分享朋友圈,前提是必须有转发onShareAppMessage
onShareTimeline:function(){
    
    
      return{
    
    
  		title:'名称',
		path: '/pages/main/main', // 点击访问的页面
		query:'' //页面参数 如: ?title='123'
     }
}

猜你喜欢

转载自blog.csdn.net/qq_42783654/article/details/107956409