开启转发
wx.showShareMenu({ withShareTicket: true, //shareAppMessage 发送朋友 shareTimeline发送朋友圈 menus: ['shareAppMessage', 'shareTimeline'] })
自定义转发内容
onShareAppMessage: function () { return { title: '自定义转发标题', path: 'index/index?id=123',
imageUrl:''
} }
解密转发内容
onLaunch: function (iv) { console.log(iv) //判断是否为转发 if (iv.shareTicket) { //获取转发内容 wx.getShareInfo({ shareTicket: iv.shareTicket, success: function (sha) { if (sha.encryptedData) { console.log(sha) //获取code换session_key wx.login({ success(log) { if (log.code) { wx.request({ url: 'http://dpuw.dev.com/uapi/wxAuto/wxMiniProgramOauth', data: { code: log.code, from: 'miniprogram' }, success(suc) { console.log(suc.data) if (suc.data.result.data.session_key) { //解密转发消息 wx.request({ url: 'http://dpuw.dev.com/uapi/wxAuto/getEncryptedData', data: { iv: sha.iv, encryptedData: sha.encryptedData, sessionKey: suc.data.result.data.session_key }, success(shadata) { //转发消息 console.log(shadata.data) } }) } } }) } else { console.log('登录失败!' + log.errMsg) } } }) } } }) } }