使用到的接口:
1. 分享到QQ空间接口
https://sns./cgi-bin/qzshare/cgi_qzshare_onekey?url=你的网址&sharesource=qzone&title=你的分享标题&pics=你的分享图片&summary=你的分享描述信息
2. 分享给QQ好友接口
/widget/shareqq/index.html?url=你的分享网址&sharesource=qzone&title=你的分享标题&pics=你的分享图片地址&summary=你的分享描述&desc=你的分享简述
3.分享到新浪微博接口
/share/share.php?url=你的分享网址&sharesource=weibo&title=你的分享标题&pic=你的分享图片&appkey=你的key
注意:appkey 需要在新浪微博开放平台中申请 (/connect)
参考代码
html
<div class="shareBox"><span class="">分享到:</span><span @click="shareDo('qzone','MVC前端网(menVScode)','/upload/41464238946737386.png')"><img src="/static/images/qqzoneshare.png" width="30"> </span> <span @click="shareDo('qq','MVC前端网(menVScode)','/upload/41464238946737386.png')"><img src="/static/images/qqshare.png" width="32"> </span> <span @click="shareDo('sina','MVC前端网(menVScode)','/upload/41464238946737386.png')"><img src="/static/images/sinaweiboshare.png" width="36"> </span> <span @click="shareDo('wechat','MVC前端网(menVScode)','/upload/41464238946737386.png')"><img src="/static/images/wechatshare.png" width="32"> </span></div>
js
function shareTo(stype,title,url) {let shareTitle = title //标题let imgUrl = url //图片//qq空间接口的传参if(stype=='qzone'){window.open('https://sns./cgi-bin/qzshare/cgi_qzshare_onekey?url='+document.location.href+'?sharesource=qzone&title='+shareTitle+'&pics='+imgUrl+'&summary='+document.querySelector('meta[name="description"]').getAttribute('content'));}//新浪微博接口的传参if(stype=='sina'){window.open('/share/share.php?url='+document.location.href+'?sharesource=weibo&title='+shareTitle+'&pic='+imgUrl+'&appkey=70876773');}//qq好友接口的传参if(stype == 'qq'){window.open('/widget/shareqq/index.html?url='+document.location.href+'?sharesource=qzone&title='+shareTitle+'&pics='+imgUrl+'&summary='+document.querySelector('meta[name="description"]').getAttribute('content')+'&desc='+shareTitle);}//生成二维码给微信扫描分享,php生成,也可以用jquery.qrcode.js插件实现二维码生成if(stype == 'wechat'){window.open('/inc/qrcode_img.php?url=/article-1.html');}}export default shareTo