var dataForWeixin = {
appId: "xxxxxx",
MsgImg: "素材图片地址",
TLImg: "素材图片地址",
url: location.href,
title: '关注有奖,万元购物卡免费送 ',
desc: '通过“xxx”微信服务号即可参与抽奖',
fakeid: "",
callback: function () {
// window.location.href="test.json";
}
};
(function () {
var onBridgeReady = function () {
// 发送给好友;
WeixinJSBridge.on('menu:share:appmessage', function (argv) {
WeixinJSBridge.invoke('sendAppMessage', {
"appid": dataForWeixin.appId,
"img_url": dataForWeixin.MsgImg,
"img_width": "120",
"img_height": "120",
"link": dataForWeixin.url,
"desc": dataForWeixin.desc,
"title": dataForWeixin.title
}, function (res) { _czc.push(['_trackEvent', '分享', '发送给好友', '2048']); });
});
// 分享到朋友圈;
WeixinJSBridge.on('menu:share:timeline', function (argv) {
(dataForWeixin.callback)();
WeixinJSBridge.invoke('shareTimeline', {
"img_url": dataForWeixin.TLImg,
"img_width": "120",
"img_height": "120",
"link": dataForWeixin.url,
"desc": dataForWeixin.desc,
"title": dataForWeixin.title
}, function (res) { _czc.push(['_trackEvent', '分享', '分享到朋友圈', '2048']); });
});
// 分享到微博;
WeixinJSBridge.on('menu:share:weibo', function (argv) {
WeixinJSBridge.invoke('shareWeibo', {
"content": dataForWeixin.title,
"url": dataForWeixin.url
}, function (res) { _czc.push(['_trackEvent', '分享', '分享到微博', '2048']); });
});
};
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
})();