// 分享模块 var shareCls = { getWxCofing (shareBaseUrl){ var url = location.href.split('#')[0]; console.log(url) // 分享内容 var shareObj = { title: "开业钜惠", // 分享标题 desc: '网罗海量优质养车项目,超值套餐应有尽有', // 分享描述 link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: 'http://static.chelingzhu.com/active/shareThumb.png', // 分享图标 success : function() { // 用户确认分享后执行的回调函数 console.log("用户确认分享后执行的回调函数") } }; //二次分享处理函数调用 this.shareAgainFn(shareObj.link); $.ajax({ url: "https://shop.zy-yc.cn/wechat_access/api/v1/wechatCommon/noauth/getWechatShareData", type:'POST', dataType:'json', data: { url: url }, success:function(res){ console.log(res) var wxData = res.wxData wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: wxData.appid, // 必填,公众号的唯一标识 timestamp: wxData.timestamp, // 必填,生成签名的时间戳 nonceStr: wxData.nonceStr, // 必填,生成签名的随机串 signature: wxData.signature,// 必填,签名 jsApiList: [ 'checkJsApi', 'onMenuShareAppMessage', 'onMenuShareTimeline', 'updateAppMessageShareData', 'updateTimelineShareData', 'getLocation', 'openLocation' ] // 必填,需要使用的JS接口列表 }); // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。 wx.error(function(res){ console.log(res,'wx error') }); //需在用户可能点击分享按钮前就先调用 wx.ready(function () { if(wx.onMenuShareAppMessage){ //分享给朋友 wx.onMenuShareAppMessage(shareObj); } if(wx.onMenuShareTimeline){ // 分享到朋友圈 wx.onMenuShareTimeline(shareObj); } if(wx.updateAppMessageShareData){ // 自定义“分享给朋友”及“分享到QQ”按钮的分享内容 wx.updateAppMessageShareData(shareObj) } if(wx.updateTimelineShareData){ // 自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容 wx.updateTimelineShareData(shareObj) } if(location.href.indexOf("store.html")>0){ wx.getLocation({ type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' success: function (res) { console.log(res, '地理位置') vm.lng = res.longitude vm.lat = res.latitude vm.getData() }, cancel: function (res) { vm.getData() }, fail: function (res) { vm.getData() } }); } }); } }) }, getQueryString(name){ let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); let r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }, shareAgainFn(url){ let from = this.getQueryString('from'); let appinstall = this.getQueryString('appinstall'); let sec = this.getQueryString('sec'); let timekey = this.getQueryString('timekey'); if (from || appinstall || sec || timekey) { window.location.href = url; } } }