分享

微信二次分享

 印度阿三17 2019-06-29

1.wx_share.js

(1)导出二次分享方法:export const wechatShare = async (option = {}, successCB = () => {}) => {

   const shareOption = {

           link: location.href,

          title: 'aaa',

          desc:'bbb',

          imgUrl: '',

         ...option

};

wx_config();

wx_share(shareOption, successCB);

};

(2)配置微信分享信息

export const wx_config= () => {

   axios.get(‘url’).then(res => {  // 通过url可以得到相关配置信息,这个url一般后台给

       let configs = res.data.data.signMap;

      wx.config({

             debug: false,

            appId: configs.appId,

            nonceStr: configs.nonceStr,

            timestamp: configs.timestamp,

            signature: configs.signature,

             jsApiList: [

                      'hideMenuItems',

                      'previewImage',

                      'checkJsApi',

                     'chooseWXPay',

                     'onMenuShareTimeline',

                    'onMenuShareAppMessage',

                    'onMenuShareQQ',

                   'onMenuShareWeibo',

                  'onMenuShareQZone',

                 'getLocation',

                'openLocation',

                  'translateVoice'

          ]

      });

   });

};

(3)分享

export const wx_share = (option = {}, successCB = () => {}) => {

    wx.ready(() => {

          wx.onMenuShareAppMessage({   // 分享给朋友

                title: option.title,

               desc: option.desc,

               link: option.link,

              imgUrl: option.imgUrl,

              success: function(res) {

                     successCB(res);  // 用户确认分享后执行的回调函数

               },

              cancel: function() {  // 用户取消分享后执行的回调函数

            }

   });

  wx.onMenuShareTimeline({   // 分享到朋友圈

          title: option.friendtitle || option.title, // 标题

          desc: option.desc,

          link: option.link, // 链接

          imgUrl: option.imgUrl, // 分享图标

        success: function(res) {

     successCB(res);

  },

  cancel: function() {  // 用户取消分享后执行的回调函数

 }

});

});

};

 

2.页面引用

wechatShare(

{

title: 'cccc',

desc: 'ddddd',

imgUrl: ""

},

() => {

console.log("success...");

}

);

 

 

来源:https://www./content-4-280751.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多