(function ($) { var appid, timestamp, noncestr, signature, imgurl, title, desc; if (isweixinbrowser() && checkweixinshareenable()) { getweixinshareparameters(); } function setimgurl() { imgurl = $('meta[name="image"]').attr("content"); } function settitle() { title = $('meta[name="articletitle"]').attr('content'); } function setdesc() { title = $('meta[name="description"]').attr('content'); } function getweixinshareparameters() { setimgurl(); settitle(); setdesc(); if (imgurl || title || desc) { $.ajax({ type: "get", url: "/weixin/home/ajaxgetweixinshareparameters", datatype: 'json', async: false, data: { currenturl: getsharedurl() }, success: function (data) { if (data !== false) { appid = data.appid; timestamp = data.timestamp; noncestr = data.noncestr; signature = data.signature; setwxconfig(); } } }); } } function setwxconfig() { wx.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appid: appid, // 必填,公众号的唯一标识 timestamp: timestamp, // 必填,生成签名的时间戳 noncestr: noncestr, // 必填,生成签名的随机串 signature: signature, // 必填,签名 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' ] }); wx.error(function (res) { console.log(res); console.warn('微信验证失败,分享功能无法正常使用!'); }); wx.ready(function () { wx.onmenusharetimeline({ title: title, desc: desc, imgurl: imgurl }); wx.onmenushareappmessage({ title: title, desc: desc, imgurl: imgurl }); }); } function isweixinbrowser() { var useragent = window.navigator.useragent.tolowercase(); if (useragent.match(/micromessenger/i) == 'micromessenger') { return true; } else { return false; } } function checkweixinshareenable() { var siteid = $("meta[name=siteid]").attr("content"); var weixinshareitem = window.power_weixinshare_config && window.power_weixinshare_config.weixinshareitems && window.power_weixinshare_config.weixinshareitems[siteid]; return weixinshareitem; } function getsharedurl() { var hrefurl = location.href; var query = location.search; if (query) { if (query.indexof('sessionverify=') > -1) { return location.origin + location.pathname; } } return hrefurl; } })(jquery);