-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshare.js
89 lines (85 loc) · 3.21 KB
/
share.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function share_fn(title,imgurl){
$.ajax({
url: 'http://test.html.huanbay.com/wx-jssdk-node',//签名服务器地址
type: 'get',
data: {
url: location.href.split('#')[0] // 将当前URL地址上传至服务器用于产生数字签名
}
}).done(function(r) {
// 返回了数字签名对象
console.log(r);
console.log(r.appId);
console.log(r.timestamp);
console.log(r.nonceStr);
console.log(r.signature);
// 开始配置微信JS-SDK
wx.config({
debug: false,//调试弹框
appId: r.appId,//必要 唯一标识
timestamp: r.timestamp,//签名时间戳
nonceStr: r.nonceStr,//签名随机串
signature: r.signature,//签名
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'hideMenuItems',
'chooseImage'
]
});
// 调用微信API
wx.ready(function() {
wx.onMenuShareTimeline({
title: ''+title+'', // 分享标题
link: ''+location.href+'', // 分享链接
imgUrl: ''+imgurl+'', // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
wx.onMenuShareAppMessage({
title: ''+title+'', // 分享标题
desc: '', // 分享描述
link: ''+location.href+'', // 分享链接
imgUrl: ''+imgurl+'', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
wx.onMenuShareQQ({
title: ''+title+'', // 分享标题
desc: '', // 分享描述
link: ''+location.href+'', // 分享链接
imgUrl: ''+imgurl+'', // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
wx.onMenuShareQZone({
title: ''+title+'', // 分享标题
desc: '', // 分享描述
link: ''+location.href+'', // 分享链接
imgUrl: ''+imgurl+'', // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
});
});
}