1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
| // <script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.1.3/jquery.min.js"></script>
// <script type="text/javascript" src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
// <script type="text/javascript" src="/js/share.js"></script>
$(function () {
var title = document.title.substring(0, document.title.length - 7);
var imgUrl = $("img:first").attr('src') || location.origin + '/favicon.png';
var desc = $("meta[name='description']").attr('content');
var shareobj = {
title: title,
desc: desc,
link: location.href,
imgUrl: imgUrl
};
var timeObj = {
title: title,
link: location.href,
imgUrl: imgUrl
}
var url = location.origin + "/api/jsapi_signature?&url=" + encodeURIComponent(location.href);
var ua = navigator.userAgent.toLowerCase();
var isWeixin = ua.indexOf('micromessenger') != -1;
if (isWeixin) {
$.getJSON(url, function (res) {
wx.config({
debug: false,
appId: res.appId,
timestamp: res.timestamp,
nonceStr: res.nonceStr,
signature: res.signature,
jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline']
});
wx.ready(function () {
wx.onMenuShareAppMessage(shareobj);
wx.onMenuShareTimeline(timeObj);
});
});
}
});
|