微信分享,二次分享无法正确获取配置信息问题

 

  

url:https://m129.baojinjinfu.com/activity/share/index.html?id=538&from=singlemessage&isappinstalled=0

 

 

朋友圈   from=timeline&isappinstalled=0
微信群   from=groupmessage&isappinstalled=0
好友分享 from=singlemessage&isappinstalled=0

 

在连接后加上?&再进行分享,分享成功

url中红色链接内容,是微信自动为分享链接添加的内容,目的是为了记录分享来源

//js获取url中参数值的方法
function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } //二次分享时,微信会自动在url后加上&from=singlemessage&isappinstalled=0 var from = getQueryString('from'); var appinstall = getQueryString('appinstall'); var sec = getQueryString('sec'); var timekey = getQueryString('timekey'); if(from || appinstall || sec || timekey) { var tender_id = getQueryString('id'); window.location.href = "/activity/share/index.html?id="+tender_id; } function goAppShare() { if (userId === null || isApp === null) return; var callBackUrl="/activity/share/"+userId; $.ajax({ url: callBackUrl, type: 'GET', success: function(data){} }); } function goWXActivityShare() { //二次分享时,微信会自动在url后加上&from=singlemessage&isappinstalled=0 var from = getQueryString('from'); if(!from){ var acturl = '/activity/share/index.html?id=' + tender_id; }else{ var acturl = window.location.href; } var wechatUrl = "/wechat/jssdk/config"; var callBackUrl="/activity/share/success/"+tender_id; $.ajax({ url: wechatUrl, type: "POST", data: {acturl: encodeURI(acturl)}, cache: false, success: function (msg) { if (msg.code == '200') { wx.config({ debug: false, appId: msg.data.appId, timestamp: msg.data.timestamp, nonceStr: msg.data.nonceStr, signature: msg.data.signature, jsApiList: [ // 所有要调用的 API 都要加到这个列表中 'onMenuShareTimeline', 'onMenuShareAppMessage' ] }); wx.ready(function () { wx.onMenuShareTimeline({ title: wxShare.title, // 分享标题 desc: wxShare.msg, // 分享说明 link: wxShare.url, // 分享链接 imgUrl: wxShare.icon, // 分享图标 success: function (msg) { $.ajax({ url: callBackUrl, type: "get", data: {}, cache: false, success: function (data) { $('.guide-mask').hide(); $('.share-guide').hide(); window.location.href = "/activity/share/index.html?id="+tender_id; window.location.reload(); } }); console.log('@--------------'); console.log(msg); console.log('@--------------'); } }); wx.onMenuShareAppMessage({ title: wxShare.title, // 分享标题 desc: wxShare.msg, // 分享说明 link: wxShare.url, // 分享链接 imgUrl: wxShare.icon, // 分享图标 type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 success: function (msg) { $.ajax({ url: callBackUrl, type: "get", data: {}, cache: false, success: function (data) { $('.guide-mask').hide(); $('.share-guide').hide(); window.location.href = "/activity/share/index.html?id="+tender_id; window.location.reload(); } }); console.log('#--------------'); console.log(msg); console.log('#--------------'); } }); }); } } }); }

  

posted on 2017-05-05 14:28  jeanneze  阅读(9326)  评论(2编辑  收藏  举报

导航