首页 > 代码库 > 微信分享代码
微信分享代码
var dataForWeixin={
appId: "",
img: "http://2014.chinayq.com/images/wxfx.jpg", // get_post_weixin_thumb 为微信机器人高级版中的函数
url: location.href,
title: "乐器品牌盛会,助力企业发展,邀您震撼见证!",
desc: "为您的和您支持的乐器品牌加油吧!",
fakeid: "",
};
(function(){
var onBridgeReady=function(){
// 发送给好友;
WeixinJSBridge.on(‘menu:share:appmessage‘, function(argv){
WeixinJSBridge.invoke(‘sendAppMessage‘,{
"appid": dataForWeixin.appId,
"img_url": dataForWeixin.img,
"img_width": "200",
"img_height": "200",
"link": dataForWeixin.url,
"desc": dataForWeixin.desc,
"title": dataForWeixin.title
}, function(res){
report(link, fakeid, 1);
});
});
// 分享到朋友圈;
WeixinJSBridge.on(‘menu:share:timeline‘, function(argv){
WeixinJSBridge.invoke(‘shareTimeline‘,{
"img_url":dataForWeixin.img,
"img_width":"200",
"img_height":"200",
"link":dataForWeixin.url,
"desc":dataForWeixin.desc,
"title":dataForWeixin.title
}, function(res){
});
});
// 分享到微博;
WeixinJSBridge.on(‘menu:share:weibo‘, function(argv){
WeixinJSBridge.invoke(‘shareWeibo‘,{
"content":dataForWeixin.title+‘ ‘+dataForWeixin.url,
"url":dataForWeixin.url
}, function(res){
report(link, fakeid, 3);
});
});
// 分享到Facebook
WeixinJSBridge.on(‘menu:share:facebook‘, function(argv){
WeixinJSBridge.invoke(‘shareFB‘,{
"img_url":dataForWeixin.img,
"img_width":"200",
"img_height":"200",
"link":dataForWeixin.url,
"desc":dataForWeixin.desc,
"title":dataForWeixin.title
}, function(res){
});
});
};
if(document.addEventListener){
document.addEventListener(‘WeixinJSBridgeReady‘, onBridgeReady, false);
}else if(document.attachEvent){
document.attachEvent(‘WeixinJSBridgeReady‘ , onBridgeReady);
document.attachEvent(‘onWeixinJSBridgeReady‘ , onBridgeReady);
}
})();
需要引用jquery库
效果:
微信分享代码