看到小程序在测试分享到朋友圈功能,于是尝试了下,给小程序更新个分享到朋友圈功能。
1 i& j: V1 |8 A1 R7 f2 \$ K% C+ C
3 r" c7 r O' q3 X4 y
根据小程序官方文档,需要有onShareAppMessage()和onShareTimeline()这2个才能实现,而且目前只支持开发者用安卓机分享,后续应该会慢慢增加优化,参考代码:
( f/ V: V" ^+ ?" I写法一
4 d% g! k p1 H9 S9 u9 | p) C; B. C' B; C- L9 W7 g
/**分享到朋友圈一*/
onShareTimeline: function () {
var that = this;
var id= wx.getStorageSync('id')
return {
title: that.data.noticedetail[0].title,
query: 'id= ' + id, //这里是query,只需要传参就行,不用写路径
imageUrl: that.data.noticedetail[0].thumb
}
} 写法二9 c) c( C8 M0 `! h; w! I
/**分享到朋友圈二*/
onShareTimeline(res){
console.log(res)
return {
title: '测试小程序分享至朋友圈',
path: '../test/test',
imageUrl:'https://cdn.u1.huluxia.com/g4/M01/AB/6C/rBAAdmARRRGAITfTAADK-6nPHMA588.jpg'
}
},
|