参考微信文档:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
(旧版)
1.引入sdk
https://res.wx.qq.com/open/js/jweixin-1.4.0.js
2.渲染完页面进行配置
if(isWx){
setWxStyle();
}
wx.config({
debug: false,
appId: data.data.appId,
timestamp: data.data.timestamp,
nonceStr: data.data.nonceStr,
signature: data.data.signature,
jsApiList: [
'onMenuShareAppMessage',
'onMenuShareTimeline',
]
});
//转发样式
function setWxStyle() {
wx.ready(function(){
var fw_url = '分享的页面链接'
var shareData = {
imgUrl: ‘’, // 分享显示的缩略图地址
link: fw_url, // 分享地址
desc: ‘’, // 分享描述
title: ‘’, // 分享标题
success: function () {
// 分享成功可以做相应的数据处理
console.log('分享成功');
},
fail: function () {
console.log('调用失败');
},
complete: function () {
console.log('调用结束');
}
};
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareTimeline(shareData);
});
}
新版
1.
https://res.wx.qq.com/open/js/jweixin-1.6.0.js
2.渲染完页面
if(isWx){
setWxStyle();
}
wx.config({
debug: false,
appId: data.data.appId,
timestamp: data.data.timestamp,
nonceStr: data.data.nonceStr,
signature: data.data.signature,
jsApiList: [
'updateAppMessageShareData',
'updateTimelineShareData',
]
});
//转发样式
function setWxStyle() {
wx.ready(function(){
var fw_url = '分享的页面链接'
var shareData = {
imgUrl: ‘’, // 分享显示的缩略图地址
link: fw_url, // 分享地址
desc: ‘’, // 分享描]述
title: ‘’, // 分享标题
trigger:function(){
// 点击分享按钮触发,但是我实验不生效,不知道为什么!
},
success: function () {
// 分享成功可以做相应的数据处理
console.log('设置成功');
},
fail: function () {
console.log('调用失败');
},
complete: function () {
console.log('调用结束');
}
};
wx.updateAppMessageShareData(shareData);
wx.updateTimelineShareData(shareData);
});
}
每天一个新知识,一起加油吧!