Skip to content

Instantly share code, notes, and snippets.

@meigesir
Created February 24, 2014 06:40
Show Gist options
  • Select an option

  • Save meigesir/9182979 to your computer and use it in GitHub Desktop.

Select an option

Save meigesir/9182979 to your computer and use it in GitHub Desktop.
微信接口内置浏览器组件自定义分享js
var dataForWeixin = {
appId:"xxxxxxxxxxxxxxxxx",
MsgImg: "",
TLImg: "",
url: "",
title: "",
amdesc: "",
tldesc: "",
fakeid: "",
weibodesc: "",
callback: function() { }
};
function SetupWeiXinShareInfo(url, title, amdesc, tldesc, weibodesc, msgimg) {
dataForWeixin.url = url;
dataForWeixin.title = title;
dataForWeixin.amdesc = amdesc;
dataForWeixin.tldesc = tldesc;
dataForWeixin.weibodesc = weibodesc;
if (msgimg != '') {
dataForWeixin.MsgImg = msgimg;
}
}
(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": shareLink,
"desc": dataForWeixin.amdesc,
"title": dataForWeixin.title
}, function (res) { (dataForWeixin.callback)(); });
});
WeixinJSBridge.on('menu:share:timeline', function (argv) {
(dataForWeixin.callback)();
WeixinJSBridge.invoke('shareTimeline', {
"img_url": dataForWeixin.MsgImg,
"img_width": "120",
"img_height": "120",
"link": shareLink,
"desc": dataForWeixin.tldesc,
"title": dataForWeixin.title
}, function (res) { (dataForWeixin.callback)(); });
});
WeixinJSBridge.on('menu:share:weibo', function (argv) {
WeixinJSBridge.invoke('shareWeibo', {
"content": dataForWeixin.weibodesc,
"url": shareLink
}, function (res) { (dataForWeixin.callback)(); });
});
WeixinJSBridge.on('menu:share:facebook', function (argv) {
WeixinJSBridge.invoke('shareFB', {
"img_url": dataForWeixin.MsgImg,
"img_width": "120",
"img_height": "120",
"link": shareLink,
"desc": dataForWeixin.tldesc,
"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);
}
})();
var shareLink = window.location.href;
dataForWeixin.callback = function () {}
SetupWeiXinShareInfo(shareLink, document.title, "","","","");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment