console.log('当前服务器渲染时注册的分享网址为:http://www.baidu.com'); console.log('当前绑定的公众号名称:自研管控小程序'); if(typeof window.___debugWeixin === "undefined"){ window.___debugWeixin = false; } function getHttpUrl(url){ url += ''; if (url.indexOf("//") === 0) { return 'https:' + url } else { return url.replace("https://", "https://") } } function appOptionsWrapper2(jsOptions) { if (typeof window === "object") { if (navigator.userAgent.toLowerCase().indexOf("android") !== -1) { return JSON.stringify(jsOptions); } } return jsOptions; } function loadScript(url, callback) { if(window.wx){ //如果已加载过wx对象了,再忽略,直接callback callback(); return ; } var script = document.createElement("script"); script.type = "text/javascript"; if (typeof(callback) != "undefined") { if (script.readyState) { script.onreadystatechange = function () { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; callback(); } }; } else { script.onload = function () { callback(); }; } } script.src = url; var head = document.getElementsByTagName("head")[0] || document.documentElement; head.insertBefore(script, head.firstChild); } function __requestJsonP(params) { params = params || {}; params.data = params.data || {}; // jsonp请求  function jsonp(params) { //创建script标签并加入到页面中  var callbackName = params.jsonp; var head = document.getElementsByTagName('head')[0] || document.documentElement; // 设置传递给后台的回调参数名  params.data['callback'] = callbackName; var data = formatParams(params.data); var script = document.createElement('script'); head.appendChild(script); //创建jsonp回调函数  window[callbackName] = function (json) { head.removeChild(script); clearTimeout(script.timer); window[callbackName] = null; params.success && params.success(json); }; //发送请求  script.src = params.url + '?' + data; //为了得知此次请求是否成功,设置超时处理  if (params.time) { script.timer = setTimeout(function () { window[callbackName] = null; head.removeChild(script); params.error && params.error({ message: '超时' }); }, time); } }; //格式化参数  function formatParams(data) { var arr = []; for (var name in data) { arr.push(encodeURIComponent(name) + '=' + encodeURIComponent(data[name])); } ; // 添加一个随机数,防止缓存  arr.push('v=' + random()); return arr.join('&'); } // 获取随机数  function random() { return Math.floor(Math.random() * 10000 + 500); } jsonp(params) } var initPagee__ = function () { //加载,并执行回调函数 //console.log('hello wexin 123!') //console.log('ready init javascript!') //输出JS代码 if (!wx) { console.log(' wx全局对象未定义,请检查是否没有引用 //res2.wx.qq.com/open/js/jweixin-1.6.0.js ') } function getMeta(name, defaultValue) { try { const ele = document.querySelector('meta[name="' + name + '"]'); return ele ? ele.getAttribute('content') : defaultValue; } catch (err) { return defaultValue; } } function httpful(pathname) { if (pathname.indexOf("http") !== -1) { return pathname } else { return document.location.protocol + "//" + document.location.hostname + pathname } } function onShareResultFromGankaoApp(scene, isSuccess) { onShareResult(scene, isSuccess); } window.onShareResultFromGankaoApp = onShareResultFromGankaoApp; function onShareResult(scene, isSuccess) { setTimeout(function () { if (window.__onUserDoShareResult) { window.__onUserDoShareResult(scene, isSuccess === true ? 1 : 0) } }, 10); } function getPageWXShareInfo(fromJS) { //优先取在运行时通过__reconfigWxShareSDK函数注入的分享信息 var info = window.___shareInfo_from___reconfigWxShareSDK||{}; if(info.link=="undefined") info.link=''; if(info.imgurl=="undefined") info.imgurl=''; var ret = { title: info.title || getMeta("wx_share_title", document.title || ""), content: info.content || getMeta("wx_share_content", (document.description || (document.title || ""))), link: httpful(info.link || getMeta("wx_share_link", document.location.href)), imgurl: httpful(info.imgurl || getMeta("wx_share_imgurl", ("https://"+document.location.hostname+"/dynamicshareimage"))) } return fromJS ? ret : JSON.stringify(ret); } window.getPageWXShareInfo = getPageWXShareInfo; var gankao_sharable = getMeta("gankao_sharable", "1") var jsconfig = {"debug":false,"appId":"wxf2ae0c72d4edc88a","timestamp":"1743664239","nonceStr":"wc3qt83ysgd","signature":"0c8d8dfa578912bccbe298069ab671db050cb40d","jsApiList":["chooseImage","uploadImage","downloadImage","startRecord","getLocation","scanQRCode","stopRecord","onVoiceRecordEnd","playVoice","onVoicePlayEnd","pauseVoice","stopVoice","uploadVoice","downloadVoice","getLocalImgData","checkJsApi","updateAppMessageShareData","updateTimelineShareData","onMenuShareTimeline","onMenuShareAppMessage","onMenuShareQQ","onMenuShareWeibo","hideMenuItems","showMenuItems","scanQRCode","clearStorageSync","clearStorage"],"openTagList":["wx-open-launch-weapp"]}; //console.log(JSON.stringify(jsconfig)); window.__onWeixinReady = function () { console.log('window.wx.ready!') //获取暂存在meta中的分享信息 console.log(JSON.stringify(window.getPageWXShareInfo(true))); if(window.___debugWeixin){ alert(JSON.stringify(window.getPageWXShareInfo(true))); } var updateTimelineShareData_option = { title: window.getPageWXShareInfo(true).title, // 分享标题 link: window.getPageWXShareInfo(true).link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: getHttpUrl(window.getPageWXShareInfo(true).imgurl), // 分享图标,微信不支持https,拦截替换为http trigger: function (res) { // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回 console.log('用户点击分享到朋友'); setTimeout(function () { if (window.__onUserWantShareWeixin) { window.__onUserWantShareWeixin('updateTimelineShareData', res) } }, 10); }, success: function () { // 用户确认分享后执行的回调函数 console.log('分享成功!') onShareResult('updateTimelineShareData', true); }, cancel: function () { // 用户取消分享后执行的回调函数 console.log('分享失败!') onShareResult('updateTimelineShareData', false); } } if(window.wx && window.wx.updateTimelineShareData){ window.wx.updateTimelineShareData(updateTimelineShareData_option); } if(window.wx && window.wx.onMenuShareTimeline){ window.wx.onMenuShareTimeline(updateTimelineShareData_option); } if(window.___debugWeixin){ alert("updateTimelineShareData_option: "+ JSON.stringify(updateTimelineShareData_option)); } var updateAppMessageShareData_options = { title: window.getPageWXShareInfo(true).title, // 分享标题 desc: window.getPageWXShareInfo(true).content, // 分享描述 link: window.getPageWXShareInfo(true).link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: getHttpUrl(window.getPageWXShareInfo(true).imgurl), // 分享图标,微信不支持https,拦截替换为http type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 trigger: function (res) { // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回 console.log('用户点击分享到朋友'); setTimeout(function () { if (window.__onUserWantShareWeixin) { window.__onUserWantShareWeixin('updateAppMessageShareData', res) } }, 10); }, success: function () { // 用户确认分享后执行的回调函数 console.log('分享成功!') onShareResult('updateAppMessageShareData', true); }, cancel: function () { // 用户取消分享后执行的回调函数 console.log('分享失败!') onShareResult('updateAppMessageShareData', false); }, fail: function (res) { console.log(JSON.stringify(res, null, 2)); } } if(window.___debugWeixin){ alert("updateAppMessageShareData_options: "+ JSON.stringify(updateAppMessageShareData_options)); } /*分享给朋友*/ window.wx.updateAppMessageShareData(updateAppMessageShareData_options); /*分享给朋友*/ window.wx.onMenuShareAppMessage(updateAppMessageShareData_options); window.wx.onMenuShareQQ({ title: window.getPageWXShareInfo(true).title, // 分享标题 desc: window.getPageWXShareInfo(true).content, // 分享描述 link: window.getPageWXShareInfo(true).link, // 分享链接 imgUrl: getHttpUrl(window.getPageWXShareInfo(true).imgurl), // 分享图标,微信不支持https,拦截替换为http type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 trigger: function (res) { // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回 console.log('用户点击分享到朋友'); setTimeout(function () { if (window.__onUserWantShareWeixin) { window.__onUserWantShareWeixin('onMenuShareQQ', res) } }, 10); }, success: function () { // 用户确认分享后执行的回调函数 console.log('分享成功!') onShareResult('onMenuShareQQ', true); }, cancel: function () { // 用户取消分享后执行的回调函数 console.log('分享失败!') onShareResult('onMenuShareQQ', false); } }); window.wx.onMenuShareWeibo({ title: window.getPageWXShareInfo(true).title, // 分享标题 desc: window.getPageWXShareInfo(true).content, // 分享描述 link: window.getPageWXShareInfo(true).link, // 分享链接 imgUrl: getHttpUrl(window.getPageWXShareInfo(true).imgurl), // 分享图标,微信不支持https,拦截替换为http type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 trigger: function (res) { // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回 console.log('用户点击分享到朋友'); setTimeout(function () { if (window.__onUserWantShareWeixin) { window.__onUserWantShareWeixin('onMenuShareWeibo', res) } }, 10); }, success: function () { // 用户确认分享后执行的回调函数 console.log('分享成功!') onShareResult('onMenuShareWeibo', true); }, cancel: function () { // 用户取消分享后执行的回调函数 console.log('分享失败!') onShareResult('onMenuShareWeibo', false); } }); window.wx.onMenuShareQZone({ title: window.getPageWXShareInfo(true).title, // 分享标题 desc: window.getPageWXShareInfo(true).content, // 分享描述 link: window.getPageWXShareInfo(true).link, // 分享链接 imgUrl: getHttpUrl(window.getPageWXShareInfo(true).imgurl), // 分享图标,微信不支持https,拦截替换为http type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 trigger: function (res) { // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回 console.log('用户点击分享到朋友'); setTimeout(function () { if (window.__onUserWantShareWeixin) { window.__onUserWantShareWeixin('onMenuShareQZone', res) } }, 10); }, success: function () { // 用户确认分享后执行的回调函数 console.log('分享成功!') onShareResult('onMenuShareQZone', true); }, cancel: function () { // 用户取消分享后执行的回调函数 console.log('分享失败!') onShareResult('onMenuShareQZone', false); } }); window.wx.checkJsApi({ jsApiList: ["updateTimelineShareData", "updateAppMessageShareData", "onMenuShareQQ", "onMenuShareWeibo", "onMenuShareQZone", "startRecord", "stopRecord", "onVoiceRecordEnd", "playVoice", "pauseVoice", "stopVoice", "onVoicePlayEnd", "uploadVoice", "downloadVoice", "chooseImage", "previewImage", "uploadImage", "downloadImage", "translateVoice", "getNetworkType", "openLocation", "getLocation", "hideOptionMenu", "showOptionMenu", "hideMenuItems", "showMenuItems", "hideAllNonBaseMenuItem", "showAllNonBaseMenuItem", "closeWindow", "scanQRCode", "chooseWXPay", "openProductSpecificView", "addCard", "chooseCard", "openCard","clearStorageSync","clearStorage"], // 需要检测的JS接口列表,所有JS接口列表见附录2, success: function (res) { //console.log('检测到jsapi') //console.log('可用的分享接口列表') //console.log(JSON.stringify(res, null, 2)) // 以键值对的形式返回,可用的api值true,不可用为false // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"} } }); //微信注册失败时的回调函数 window.wx.error(function (res) { console.log("即将打印 window.wx.error") var msg = JSON.stringify(res); console.error(msg); if(msg.indexOf('invalid url domain')!==-1){ console.error('自定义分享内容设置失败,微信提示,当前访问域名未配置在微信公众号后台的业务域名白名单中,请先配置!'); } }); if (gankao_sharable == "1") { window.wx.showOptionMenu(); } else { window.wx.hideOptionMenu(); } } //微信注册成功时的回调函数 window.wx.ready(window.__onWeixinReady); window.__reconfigWxShareSDK = function(shareInfo) { try{ if(shareInfo){ window.___shareInfo_from___reconfigWxShareSDK = { title:shareInfo.title, content:shareInfo.content, link:shareInfo.link, imgurl:shareInfo.imgurl } }; var inWeixin = (window.navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1); if(!inWeixin){ console.log('Not weixin, window.__reconfigWx ignored! ') return ; } console.log('window.__reconfigWx ...') //如果没有传入jsconfig说明是宿主页面再次发起注册请求的,则动态以jsonP方式重新获取config签名 __requestJsonP({ url: 'https://www.gankao.com/p-wx/wx_config/wxf2ae0c72d4edc88a/callback/__requestJsonP_callback?debug=' + (window.___debugWeixin?"1":"0"), // 请求地址 jsonp: '__requestJsonP_callback', // 采用jsonp请求,且回调函数名为"jsonpCallbak",可以设置为合法的字符串 data: {}, // 传输数据 success: function (jsonResult) { // 请求成功的回调函数 // jsonResult = {signInfo} //向微信注册 console.log("jsonResult.signInfo: ") console.log(jsonResult.signInfo) //有动态传入新的自定义分享内容,则需要向服务器重新签名一次 window.wx.ready(window.__onWeixinReady); window.wx.config(jsonResult.signInfo); console.log('当前更新注册的分享网址为:'+ jsonResult.referpage); }, error: function (jsonResult) { // 请求失败的回调函数 console.error("__requestJsonP error: " + jsonResult.error) console.log('当前更新注册的分享网址为:'+ jsonResult.referpage); } }); if(window.JsBridgeApp && window.JsBridgeApp.setUIOptions) { console.log('window.JsBridgeApp.setUIOptions...') let options = appOptionsWrapper2({ hiddenclosebutton: getMeta("gankao_hiddenclosebutton", "0"),////如需禁用原生页眉左侧的关闭按钮‘X’,则设置为1;meta标签省略或读取失败时,app外壳当作默认=0(即默认可关闭); hiddenbackbutton: getMeta("gankao_hiddenbackbutton", "0"),//如需禁用原生页眉左侧的返回按钮‘X’,则设置为1;meta标签省略或读取失败时,app外壳当作默认=0(即默认可返回); sharable: gankao_sharable//设置是否可分享(默认是显示,需隐藏时调用) }) if(window.___debugWeixin){ alert(JSON.stringify(options)); } window.JsBridgeApp.setUIOptions(options); }else{ console.log('not gankaoApp ...'); } }catch (e) { console.error(e.stack) } } console.log("jsconfig: ") console.log(jsconfig) window.__reconfigWx = window.__reconfigWxShareSDK; window.wx.config(jsconfig); if(window.JsBridgeApp && window.JsBridgeApp.setUIOptions) { console.log('window.JsBridgeApp.setUIOptions...') let options = appOptionsWrapper2({ hiddenclosebutton: getMeta("gankao_hiddenclosebutton", "0"),////如需禁用原生页眉左侧的关闭按钮‘X’,则设置为1;meta标签省略或读取失败时,app外壳当作默认=0(即默认可关闭); hiddenbackbutton: getMeta("gankao_hiddenbackbutton", "0"),//如需禁用原生页眉左侧的返回按钮‘X’,则设置为1;meta标签省略或读取失败时,app外壳当作默认=0(即默认可返回); sharable: gankao_sharable//设置是否可分享(默认是显示,需隐藏时调用) }) if(window.___debugWeixin){ alert(JSON.stringify(options)); } window.JsBridgeApp.setUIOptions(options); }else{ console.log('not gankaoApp ...'); } }; // var logVconsole = window.location.href.indexOf('&vconsole=1')!==-1; if(logVconsole){ loadScript("//cdn.bootcss.com/vConsole/3.3.4/vconsole.min.js", function(){ if (typeof VConsole !== 'undefined') { var vConsole = new VConsole(); } loadScript("//res2.wx.qq.com/open/js/jweixin-1.6.0.js", initPagee__); }); }else{ loadScript("//res2.wx.qq.com/open/js/jweixin-1.6.0.js", initPagee__); }