share.js
1.59 KB
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
import $ from 'jquery';
/**
* 分享
* @param {*} options
* options:{
* decodeUrl: 根据此url生成签名
* title: 分享标题
* desc: 分享描述
* shareUrl: 分享地址
* thumbnail: 分享缩略图
* }
*/
export default function share (options) {
$.ajax({
type: 'POST',
url: 'https://zmt.ihxlife.com/o2o/wx/cover',
data: JSON.stringify({
shareGoal: options.decodeUrl
}),
contentType: 'application/JSON',
success: function (res) {
window.wx.config({
debug: false,
appId: res.data.appId,
timestamp: res.data.timestamp,
nonceStr: res.data.noncestr,
signature: res.data.signature,
jsApiList: [
'onMenuShareTimeline',
'onMenuShareAppMessage',
]
});
}
});
window.wx.ready(function () {
const url = options.shareUrl.replace('#','?#')
window.wx.onMenuShareAppMessage({
title: options.title,
desc: options.desc,
link: url,
imgUrl: options.thumbnail,
success: function (res) {
// console.log('分享成功')
},
cancel: function (res) {
//alert('已取消');
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
window.wx.onMenuShareTimeline({
title: options.title,
desc: options.desc,
link: url,
imgUrl: options.thumbnail,
success: function (res) {
// console.log('分享成功')
},
cancel: function (res) {
//alert('已取消');
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
});
}