微信端分享、手机QQ好友分享

2018-9-9    分类: 前端资源

微信为我们提供了从微信分享到到朋友圈、微信好友、qq好友、qq空间时,所显示不同的分享文案。(接口是收费的)

 

微信分享 (收费)

官方文档地址为:
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115

找到已有公众号的appid,根据这个appid和url向后端发起请求,拿到配置所需要的参数:timestamp、noncestr和signature。

添加

<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js" type="text/javascript"></script>

var wxTitle = '标题'; 
var wxDesc = "摘要"; 
var wxLogo = "http://xx/1.png"  //缩略图 
var wxLink = "http://xx.com/";  //分享点击要跳转的页面 

//配置信息 
wx.config({ 
"debug":false, 
"beta":true, 
"appId":"wx48d79203b4f0c482", 
"nonceStr":"rand_5b94f14f204b0", 
"timestamp":1536487759, 
"url":"https:\/\/m.weiclicai.com\/activity\/third-yearend-act\/thirdbill", 
"signature":"4e3c1ff25ee8daa742322278aaaeaf1af91f3d5c", 
"jsApiList":[
 "hideMenuItems",
 "onMenuShareAppMessage",
 "onMenuShareTimeline",
 "onMenuShareQQ"] 
});


wx.ready(function () {
  wx.hideMenuItems({
    menuList: [ //限制分享到到的平台
     "menuItem:share:weiboApp",
     "menuItem:share:facebook",
     "menuItem:share:QZone",
     "menuItem:originPage",
     "menuItem:readMode",
     "menuItem:openWithQQBrowser",
     "menuItem:openWithSafari",
     "menuItem:share:email"
   ]
  });

  wx.onMenuShareTimeline({
    title: wxDesc,
    desc: wxDesc,
    link: wxLink,
    imgUrl: wxLogo,
    success: function () {
     //分享微信朋友圈
 
    },
    cancel: function () {

    }
  });

  wx.onMenuShareAppMessage({
    title: wxTitle,
    desc: wxDesc,
    link: wxLink,
    imgUrl: wxLogo,
    success: function () {
    //分享微信朋友
 
    },
    cancel: function () {

    }
  });

  wx.onMenuShareQQ({
    title: wxTitle,
    desc: wxDesc,
    link: wxLink,
    imgUrl:wxLogo,
    success: function () {
    //分享qq朋友
 
    },
    cancel: function () {

    }
  });
});

https://segmentfault.com/a/1190000016199418

 

 

QQ分享好友 (免费)

 <script type="text/javascript" src="https://qzonestyle.gtimg.cn/qzone/qzact/common/share/share.js"></script>
 <script type="text/javascript">
 var title = "维C物权3周年红包,手慢无";
 var summary = "我在维C物权的收益超过0%用户,赶紧来较量一下吧~";
 var sharepic = 'https://dn-weiclicai.qbox.me/5b725146ce0af.png'; //这里要写当前域名的图片
 var shareurl = "https://m.weiclicai.com/activity/third-yearend-act/thirdbill";//这里要写当前域名的图片
 
 setShareInfo({
   title: title,
   summary: summary,
   pic: sharepic,
   url: shareurl
 });
 </script>