wx.config({ debug: false, appId: 'wx0ff3078907c6263c', timestamp:6368696403 , nonceStr:'asjh121341xc', signature:'84a375bdf31525b822bab065547b77e4e53b8dcc', jsApiList: [ 'checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'hideMenuItems', 'showMenuItems', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem', 'translateVoice', 'startRecord', 'stopRecord', 'onRecordEnd', 'playVoice', 'pauseVoice', 'stopVoice', 'uploadVoice', 'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'getNetworkType', 'openLocation', 'getLocation', 'hideOptionMenu', 'showOptionMenu', 'closeWindow', 'scanQRCode', 'chooseWXPay', 'openProductSpecificView', 'addCard', 'chooseCard', 'openCard'] }); $(document).ready(function () { var context = $('#wechatShareContext').val(); var imageUrl = $('#wechatShareImageUrl').val(); var shareTitle = $('#wechatShareTitle').val(); var linelink = $('#wechatShareLink').val(); window.shareData = { context: context, imageUrl: imageUrl, shareTitle: shareTitle }; /** * 默认分享出去的数据 * */ function getShareImageUrl() { var share_imgurl = ""; if ("" == share_imgurl) { var shareImgObj = document.getElementsByTagName("img")[0]; if ('undefined' != typeof (shareImgObj)) { share_imgurl = shareImgObj.src; } } return window.shareData.imageUrl || share_imgurl; } wx.ready(function(){ //分享到朋友圈 wx.onMenuShareTimeline({ title: window.shareData.shareTitle || $('#wechatShareTitle').val(), // 分享标题 link: $('#wechatShareLink').val() || window.location.href, // 分享链接 imgUrl: getShareImageUrl(), // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); //分享给好友 wx.onMenuShareAppMessage({ title: window.shareData.shareTitle || $('#wechatShareTitle').val(), // 分享标题 desc: window.shareData.context || $('#wechatShareContext').val(), // 分享描述 link: $('#wechatShareLink').val() || window.location.href, // 分享链接 imgUrl: getShareImageUrl(), // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); //分享到QQ wx.onMenuShareQQ({ title: window.shareData.shareTitle || $('#wechatShareTitle').val(), // 分享标题 desc: window.shareData.context || $('#wechatShareContext').val(), // 分享描述 link: $('#wechatShareLink').val() || window.location.href, // 分享链接 imgUrl: getShareImageUrl(), // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); //分享到腾讯微博 wx.onMenuShareWeibo({ title: window.shareData.shareTitle || $('#wechatShareTitle').val(), // 分享标题 desc: window.shareData.context || $('#wechatShareContext').val(), // 分享描述 link: $('#wechatShareLink').val() || window.location.href, // 分享链接 imgUrl: getShareImageUrl(), // 分享图标 success: function () { // 用户确认分享后执行的回调函数 }, cancel: function () { // 用户取消分享后执行的回调函数 } }); }); document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() { // 发送给好友 WeixinJSBridge.on('menu:share:appmessage', function (argv) { WeixinJSBridge.invoke('sendAppMessage', { "img_url": getShareImageUrl(), "img_width": "640", "img_height": "640", "link": $('#wechatShareLink').val() || window.location.href, "desc": window.shareData.context || $('#wechatShareContext').val(), "title": window.shareData.shareTitle || $('#wechatShareTitle').val() }, function (res) { if ('send_app_msg:cancel' != res.err_msg) { weimobAfterShare("", window.shareData.sendFriendLink, 'appmessage'); } _report('send_msg', res.err_msg); }) }); // 分享到朋友圈 WeixinJSBridge.on('menu:share:timeline', function (argv) { WeixinJSBridge.invoke('shareTimeline', { "img_url": getShareImageUrl(), "img_width": "640", "img_height": "640", "link":$('#wechatShareLink').val() || window.location.href, "desc": window.shareData.context || $('#wechatShareContext').val(), "title": window.shareData.context || $('#wechatShareContext').val() }, function (res) { if ('share_timeline:cancel' != res.err_msg) { //如果用户没有取消 weimobAfterShare("", window.shareData.timeLineLink, 'timeline'); } _report('timeline', res.err_msg); }); }); // 分享到微博 WeixinJSBridge.on('menu:share:weibo', function (argv) { WeixinJSBridge.invoke('shareWeibo', { "img_url": getShareImageUrl(), "content": window.shareData.context || $('#wechatShareContext').val(), "url": $('#wechatShareLink').val() || window.location.href, "title": window.shareData.shareTitle || $('#wechatShareTitle').val() }, function (res) { if ('share_weibo:cancel' != res.err_msg) { weimobAfterShare("", window.shareData.weiboLink, 'weibo'); } _report('weibo', res.err_msg); }); }); }, false); });