微信小程序之API 轉發給好友 (Page.onShareAppMessage)


wxml部分

轉發事件一定是綁在 button 組件上面.給button組件設置屬性:open-type="share"
點擊按鈕直接就會觸發轉發的方法,可以轉發給指定的微信好友.
但是這個需求還不夠,用戶那邊收到的是 轉發的那個頁面,點進去以后也是那個頁面

 <button class='weixin' open-type="share">
     <view class='wechatImg'>
         <image class='wechatIcon' src='../../images/wechat.png'></image>
     </view>
     <view class='sentFriend'>發送給好友</view>
</button>
js部分
/**
   * 用戶點擊右上角分享
   */
  onShareAppMessage: function(res) {
    let that = this;
    // console.log('主圖------------->',that.data.goodsObj.MainImages)
    return {
      title: "發送給好友",
      imageUrl: that.data.goodsObj.MainImages,
      success: function(res) {
        console.log(res, "轉發成功")
      },
      fail: function(res) {
        console.log(res, "轉發失敗")
      }
    }

  },

如果只保留頁面按鈕的轉發,關閉微信右上角的轉發 則可:
1.在onload關閉

 onLoad: function(options) {

    // 隱藏右上角分享
    wx.hideShareMenu()
}
/**
   * 用戶點擊右上角分享
   */
  onShareAppMessage: function(res) {
    if (res.from === "button") {
      console.log(res)
      let that = this;
      let v = that.data.OrderNumber;
      that.setData({
        flag: false,
        v: v
      })
      console.log(v, 'v===========')
      return {
        title: that.data.BrandName,
        path: 'pages/index/index?t=' + 50 + '&v=' + v,
        success: function(res) {
          console.log(res, "轉發成功")

        },
        fail: function(res) {
          console.log(res, "轉發失敗")
        }
      }
    } else {
      console.log(res)
    }
  },


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM