function GetHttpRequest() { if (window.XMLHttpRequest) // Gecko return new XMLHttpRequest(); else if (window.ActiveXObject) // IE return new ActiveXObject("MsXml2.XmlHttp"); } function ajaxPage(sId, url) { var oXmlHttp = GetHttpRequest(); oXmlHttp.onreadystatechange = function () { if (oXmlHttp.readyState == 4) { includeJS(sId, url, oXmlHttp.responseText); } } oXmlHttp.open('GET', url, false);//同步操作 oXmlHttp.send(null); } function includeJS(sId, fileUrl, source) { if ((source != null) && (!document.getElementById(sId))) { var oHead = document.getElementsByTagName('HEAD').item(0); var oScript = document.createElement("script"); oScript.type = "text/javascript"; oScript.id = sId; oScript.text = source; oHead.appendChild(oScript); } } if($ == 'undefined'){ ajaxPage("scrB", "/e/extend/wxshare/jquery-2.1.4/jquery.min.js"); } var nshareInit = false; function getWxJs(){ $.getScript('https://res.wx.qq.com/open/js/jweixin-1.6.0.js',function(){ nshareInit = true; _init(nShareConfig, nShareParams); //这个函数是在new.js里面的 }); } function _init(config, params){ wx.config({ debug: false, appId: params.appId, timestamp: params.timestamp, nonceStr: params.nonceStr, signature: params.signature, jsApiList: [ // 所有要调用的 API 都要加到这个列表中 'updateAppMessageShareData','updateTimelineShareData' ] }); wx.ready(function () { // 在这里调用 API wx.updateAppMessageShareData({ title: config.title, // 分享标题 desc: config.desc, // 分享描述 link: config.link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: config.imgUrl, // 分享图标 success: function () { // 设置成功 config.success(0); } }); wx.updateTimelineShareData({ title: config.title, // 分享标题 desc: config.desc, // 分享描述 link: config.link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: config.imgUrl, // 分享图标 success: function () { // 设置成功 config.success(1); } }) }); } var nShareConfig; var nShareParams; function init(config, params) { if(!nshareInit){ nShareConfig = config; nShareParams = params; getWxJs(); }else{ _init(config, params) } } var NShare = function (config) { $.ajax({ url: '/e/extend/wxshare/params.php', type: 'POST', data:{url:config.link}, dataType: 'json', success: function (res) { if (res.state == 'ok') { init(config, res.data); } }, error:function(a){ } }) }