1. 程式人生 > 其它 >微信小程式分享設定

微信小程式分享設定

開啟轉發

    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) } } }) } } }) } }