微信分享接口
看着微信分享的 demo 好纠结啊。。。不知道怎么去触发他。哪位大神可以指点一下。。。点击按钮弹出分享 js不太懂。。搞了半天也没搞出来。。请教大家。 wx.ready(function () { wx.onMenuShareTimeline({ title: window.shareData.tTitle, link: window.shareData.timeLineLink, imgUrl: window.shareData.imgUrl, desc: window.shareData.tContent, trigger: function (res) { // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回 alert('用户点击发送给朋友'); }, success: function (res) { alert('已分享'); }, ancel: function (res) { alert('已取消'); }, fail: function (res) { alert('错误'); } }); });
http://www.360doc.com/content/14/1118/21/15077656_426245574.shtml
function onBridgeReady(){ //WeixinJSBridge.call('hideOptionMenu'); $("#share").click(function(){ WeixinJSBridge.call('onMenuShareTimeline'); }); } if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } }else{ onBridgeReady(); } /* var lineLink = 'http://../....'; // 要分享的页面的URL var imgUrl = 'http://.../...'; // 显示在微信里的缩略图 var shareTitle = '页面标题'; // 页面标题 var descContent = "页面内容简介"; // 内容简介 var appid = ''; // APP ID, 可以为空 function wx_shareFriend() { WeixinJSBridge.invoke('sendAppMessage',{ "appid": appid, "img_url": imgUrl, "img_width": "640", "img_height": "640", "link": lineLink, "desc": descContent, "title": shareTitle }, function(res) { //alert(res.err_msg); }) } function wx_shareTimeline() { WeixinJSBridge.invoke('shareTimeline',{ "img_url": imgUrl, "img_width": "640", "img_height": "640", "link": lineLink, "desc": descContent, "title": shareTitle }, function(res) { //alert(res.err_msg); }); } function wx_shareWeibo() { WeixinJSBridge.invoke('shareWeibo',{ "content": descContent, "url": lineLink, }, function(res) { //alert(res.err_msg); }); } function onBridgeReady(){ WeixinJSBridge.on('menu:share:appmessage', wx_shareFriend); // 发送给朋友 WeixinJSBridge.on('menu:share:timeline', wx_shareTimeline); // 分享到朋友圈 WeixinJSBridge.on('menu:share:weibo', wx_shareWeibo); // 分享到微博 } if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } }else{ onBridgeReady(); } function onBridgeReady(){ WeixinJSBridge.on('menu:share:appmessage', wx_shareFriend); WeixinJSBridge.on('menu:share:timeline', wx_shareTimeline); WeixinJSBridge.on('menu:share:weibo', wx_shareWeibo); } if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); }else if (document.attachEvent){ document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } }else{ onBridgeReady(); } WeixinJSBridge.call('hideOptionMenu'); WeixinJSBridge.call('hideToolbar'); WeixinJSBridge.invoke('closeWindow',{},function(res){ alert(res.err_msg); }); WeixinJSBridge.invoke('getNetworkType',{},function(e){ WeixinJSBridge.log(e.err_msg); }); */