设置微信自定义分享内容

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
/**
* 设置微信自定义分享内容
*/
var config = {
title: document.title,
only_title: '',
desc: '',
imgUrl: 'share_wechat.jpg'
};
define(function () {
return function weixin(config) {
if(/micromessenger/i.test(navigator.userAgent)) {
if(typeof requirejs == 'function') {
requirejs(['//xxx/wechat/sdk/share.js'], function (weixinShare) {
if(weixinShare && typeof weixinShare == 'function') {
weixinShare({
shareData: config
});
}
});
} else {
var script = document.createElement('script');
script.src = '//xxx/wechat/sdk/share.js';
script.onload = function goShare() {
if(window.weixinShare && typeof window.weixinShare == 'function') {
window.weixinShare({
shareData: config
});
}
};
document.body.appendChild(script);
}
}
};
});