微信设置自定义分享

微信设置自定义分享

首先要拿到签名,这是必须的

function wxInit(wxconf, shareInfo) {
    wxconf.debug = false; //是否开启调试模式
    wxconf.jsApiList = ['onMenuShareAppMessage', 'onMenuShareTimeline',
      'onMenuShareQQ', 'showMenuItems', 'hideAllNonBaseMenuItem',
      'checkJsApi'
    ];
    wx.config(wxconf);
    wx.ready(function () {
      //注意这个hideAllNonBaseMenuItem,showMenuItems都要配置到上面的 wxconf.jsApiList中
      wx.hideAllNonBaseMenuItem(); //隐藏所有分享菜单
      wx.showMenuItems({    //设置自己想要的菜单
        menuList: ['menuItem:share:appMessage', 'menuItem:share:timeline', 'menuItem:favorite']
      });
      //微信好友
      wx.onMenuShareAppMessage({
        title: shareInfo.title,
        desc: shareInfo.brief,
        link: shareInfo.url,
        imgUrl: shareInfo.image,
        success: function () {
          console.log('share weixin success');
        },
        cancel: function () {
          console.log('share weixin cancel');
        }
      });
      //微信朋友圈
      wx.onMenuShareTimeline({
        title: shareInfo.title,
        desc: shareInfo.brief,
        link: shareInfo.url,
        imgUrl: shareInfo.image,
        success: function () {
          console.log('share timeline success');
        },
        cancel: function () {
          console.log('share timeline cancel');
        }
      });
      wx.error(function (res) {
        console.log(res);
      });
    });
  }
//签名信息
let wxconf = {
   appId: **,
   timestamp: **,
   nonceStr: **,
   signature: **
}
let shareInfo = {
    title: '',//分享出去的标题
    url: '', //可自定义链接,这个链接必须要在你同域名下
    brief: '123456',//分享出去后的介绍
    image: ''//分享出去的标题图片 这个图片必须要在你同域名下
}
//调用
wxInit(wxconf, shareInfo);

猜你喜欢

转载自blog.csdn.net/qq_38880700/article/details/89188758