onLoad: function (options) {
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline'],
success: function (e) {
//console.log(e);
}
})
}
这段代码是微信小程序中用于配置分享功能的API调用,具体含义如下:
1. 核心功能
wx.showShareMenu():启用微信小程序的分享功能13。
withShareTicket: true:开启带shareTicket的转发,用于获取群聊标识(可识别用户是否来自同一微信群)13。
menus: ['shareAppMessage', 'shareTimeline']:同时启用两种分享方式:
shareAppMessage:分享给好友或群聊23。
shareTimeline:分享到朋友圈(仅Android支持)3。设置右上角点开的详情界面中的分享按钮是否可用
https://developers.weixin.qq.com/miniprogram/dev/api/share/wx.showShareMenu.html
onShareAppMessage() {
return {
title: '分享标题',
path: '/pages/detail/detail?promoId=12345&articleId=67890',
imageUrl: '/images/share.jpg',
success: function (res) {
// 转发成功
console.log(res);
},
fail: function (res) {
console.log(res);
// 转发失败
}
}
}
获取推广id 和 文章id
Page({
onLoad(options) {
if (options.promoId && options.articleId) {
console.log('推广ID:', options.promoId);
console.log('文章ID:', options.articleId);
// 存储或使用参数
wx.setStorageSync('promoId', options.promoId);
wx.setStorageSync('articleId', options.articleId);
}
}
})
<button open-type="share" >发给朋友</button>
这个type 会调用我们的分享 聊天窗口方法 onShareAppMessage()
onShareAppMessage() {
var title = this.data.blog.title
var path = '/pages/blog_view/blog_view?id='+this.data.blog.id+'&tuiId=67890';
var imageUrl = 'http://p24f838c.natappfree.cc/static/upload_image/blog_cover/20250624/20250624004044.jpg';
return {
title: 'ct:'+title, //好友聊天窗口的标题
path:path,
imageUrl:imageUrl
}
} onShareTimeline: function (res) {
let imageUrl = this.data.baseURL + this.data.goods_obj.imageUrl;
let title = this.data.goods_obj.title;
return {
title: title,
query: {
id: this.data.goods_obj.id
},
imageUrl
}
},
站长微信:xiaomao0055
站长QQ:14496453