看到小程序在测试分享到朋友圈功能,于是尝试了下,给小程序更新个分享到朋友圈功能。
+ V- c' T2 `- {* B4 a' s/ l/ l
/ `: m1 ?, j- Z& X 根据小程序官方文档,需要有onShareAppMessage()和onShareTimeline()这2个才能实现,而且目前只支持开发者用安卓机分享,后续应该会慢慢增加优化,参考代码:
2 |* E* D/ N3 z& s4 U( b5 K5 ?写法一
; o; Q; t' z7 U ^
2 \# N( ^) h4 s7 T1 t2 J+ {5 z/**分享到朋友圈一*/
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
}
} 写法二& A5 b: ^7 i" @9 }/ P7 { m
/**分享到朋友圈二*/
onShareTimeline(res){
console.log(res)
return {
title: '测试小程序分享至朋友圈',
path: '../test/test',
imageUrl:'https://cdn.u1.huluxia.com/g4/M01/AB/6C/rBAAdmARRRGAITfTAADK-6nPHMA588.jpg'
}
},
|