看到小程序在测试分享到朋友圈功能,于是尝试了下,给小程序更新个分享到朋友圈功能。1 _3 t% `0 e5 s% z t4 @
0 R) n# O1 W5 U0 C9 b7 W 根据小程序官方文档,需要有onShareAppMessage()和onShareTimeline()这2个才能实现,而且目前只支持开发者用安卓机分享,后续应该会慢慢增加优化,参考代码:5 G4 ]9 g+ C9 J7 N3 ?' R' h
写法一 Y9 R0 s2 c9 v. T* ~4 T3 X
- e9 k4 q+ m. x+ S' i# o/**分享到朋友圈一*/
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
}
} 写法二( F Q/ Z' p- {( C0 A. X6 d4 a( L
/**分享到朋友圈二*/
onShareTimeline(res){
console.log(res)
return {
title: '测试小程序分享至朋友圈',
path: '../test/test',
imageUrl:'https://cdn.u1.huluxia.com/g4/M01/AB/6C/rBAAdmARRRGAITfTAADK-6nPHMA588.jpg'
}
},
|