<script type="text/javascript" src="http://a.mysteelcdn.com/libs/jquery.min.js"></script> <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> $(function(){ function share(){ var _this = this; var url = location.href.split('#')[0]; var targetOpenId = '$!{USERINFO.openid}' var sourceOpenId = url.substring(url.lastIndexOf('=')+1,url.length) if(sourceOpenId == 0){ url = url.replace('isAllowed=0','isAllowed=1') } var jsonData = { url:url }; $.ajax({ type : 'POST', url : "/wechat/share", data : jsonData, success : function(result) { wx.config({ debug: false, // 開啓調試模式,調用的全部api的返回值會在客戶端alert出來,若要查看傳入的參數,能夠在pc端打開,參數信息會經過log打出,僅在pc端時纔會打印。 appId: result.appId, // 必填,公衆號的惟一標識 timestamp: result.timestamp, // 必填,生成簽名的時間戳 nonceStr: result.noncestr, // 必填,生成簽名的隨機串 signature: result.sigNature,// 必填,簽名,見附錄1 jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ', 'hideOptionMenu'] // 必填,須要使用的JS接口列表,全部JS接口列表見附錄2 }); } }); var shareData = { title: _this.datas.name, desc: _this.datas.activityDesc, link: url, imgUrl: 'http://a.mysteelcdn.com/libs/article/assets/img/share.png' }; wx.ready(function () { wx.onMenuShareAppMessage(shareData); wx.onMenuShareTimeline(shareData); wx.onMenuShareQQ(shareData); }); } }, })