function onBridgeReady() {
var mainTitle="分享啦!",
mainDesc="分享说明",
mainURL="http://www.baidu.com",//url的绝对地址
mainImgUrl= "http://www.baidu.com/1417171328201678646.jpg";//图片的绝对地址
//转发朋友圈
WeixinJSBridge.on("menu:share:timeline", function(e) {
var data = {
img_url:mainImgUrl,
img_width: "120",
img_height: "120",
link: mainURL,
//desc这个属性要加上,虽然不会显示,但是不加暂时会导致无法转发至朋友圈,
desc: mainDesc,
title: mainTitle
};
WeixinJSBridge.invoke("shareTimeline", data, function(res) {
WeixinJSBridge.log(res.err_msg)
});
});
//同步到微博
WeixinJSBridge.on("menu:share:weibo", function() {
WeixinJSBridge.invoke("shareWeibo", {
"content": mainDesc,
"url": mainURL
}, function(res) {
WeixinJSBridge.log(res.err_msg);
});
});
//分享给朋友
WeixinJSBridge.on('menu:share:appmessage', function(argv) {
WeixinJSBridge.invoke("sendAppMessage", {
img_url: mainImgUrl,
img_width: "120",
img_height: "120",
link: mainURL,
desc: mainDesc,
title: mainTitle
}, function(res) {
WeixinJSBridge.log(res.err_msg)
});
});
};
//执行
document.addEventListener('WeixinJSBridgeReady', function() {
onBridgeReady();
});