這裏用的是jweixin-1.3.2.js trigger: function (res) { //判斷分享的狀態,好友、朋友圈 localStorage.setItem("share_type",1); }, //單獨頁面微信分享功能 var methods={ wxShare: function (shareImg, shareTitle, shareDesc, shareUrl,callBack,tipsCon) { var url = window.location.href; var wcConfig; methods.ajax("/index.php/Wechat/GetJssdk/getJssdkConfig", { url: url }, function (res) { wcConfig = res; setConfig(); }); function setConfig() { wx.config({ debug: false, appId: wcConfig.data.appId, timestamp: wcConfig.data.timestamp, nonceStr: wcConfig.data.nonceStr, signature: wcConfig.data.signature, jsApiList: [ 'onMenuShareQQ', 'uploadImage', 'chooseImage', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'startRecord', 'stopRecord', 'translateVoice', 'chooseCard', 'openCard', 'addCard' ] }); var wxData = { url: shareUrl ? location.protocol + "//" + location.host + shareUrl : url, imgurl: location.protocol + "//" + location.host + (shareImg ? shareImg : "/shop-m/public/images/share_icon.jpg"), title: shareTitle ? shareTitle : "默認標題", desc: shareDesc ? shareDesc : "默認描述" } //分享好友 var weixinShare = { title: wxData.title, desc: wxData.desc, link: wxData.url, imgUrl: wxData.imgurl, type: '', trigger: function (res) { // console.log('用戶點擊發送給朋友'); localStorage.setItem("share_type",2); }, success: function(res) { if(callBack){ if(tipsCon){ methods.confirm(tipsCon); }else{ methods.prompt("分享成功"); } callBack(); }; }, }; var qqShare = { title: wxData.title, desc: wxData.desc, link: url, imgUrl: wxData.imgurl, success: function() { if(callBack){ if(tipsCon){ methods.confirm(tipsCon); }else{ methods.prompt("分享成功"); } callBack(); }; }, }; //分享朋友圈 var friendShare = { title: wxData.title, link: wxData.url, imgUrl: wxData.imgurl, trigger: function (res) { console.log('用戶點擊分享到朋友圈'); localStorage.setItem("share_type",1); }, success: function(res) { if(callBack){ if(tipsCon){ methods.confirm(tipsCon); }else{ methods.prompt("分享成功"); } callBack(); }; }, }; wx.ready(function () { wx.onMenuShareTimeline(friendShare); wx.onMenuShareAppMessage(weixinShare); wx.onMenuShareQQ(qqShare); }); } } } //調用方法 //微信分享,先判斷是否是微信,設置分享內容shareImg, shareTitle, shareDesc, shareUrl,callBack分享成功後回調函數,tipsCon提示語 var userAgentInfo = navigator.userAgent.toLowerCase(); if (userAgentInfo.match(/MicroMessenger/i) == 'micromessenger') { methods.wxShare("/shop-m/page/activity/2019-0520/images/share_icon.jpg", "幫他助力", "有你的助力會更有信心哦!", "/shop-m/page/activity/2019-0720/buy-new-car/helpAssistance.html?fromOpenid="+fromOpenid+"&"+"fromUserid="+fromUserid, function(){ console.log('分享成功') }) }