首先,创建一个被分享出去的页面。页面中用script来设置被分享出去的内容
tilte:标题,desc:内容,imgUrl:图片路径,link:页面路径
微信接口配置
debug:调试模式,appId:公众号的唯一标识,timestamp:生成签名的时间戳,nonceStr:生产签名的随机串,signature:签名
var shareData = {
title : '这个夏天让大明星带着宝贝去旅行',
desc : '乐可旅行x浙江少儿频道大型旅行真人秀招募中!',
imgUrl : 'http://ww3.sinaimg.cn/mw690/86bf5c21gw1f4x9x8x0cuj205k05kwf2.jpg',
link : '<%=browserUrl%>' + '/index'
};
var wxConfig = {
appId : '<%=appId%>',
timestamp : '<%=timestamp%>',
nonceStr : '<%=nonceStr%>',
signature : '<%=signature%>'
}
最后通过设置base.js
wx.config({
debug: false,
appId: wxConfig.appId,
timestamp: wxConfig.timestamp,
nonceStr: wxConfig.nonceStr,
signature: wxConfig.signature,
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
// 'hideMenuItems',
'showMenuItems',
// 'hideAllNonBaseMenuItem',
'showAllNonBaseMenuItem',
'translateVoice',
'startRecord',
'stopRecord',
'onRecordEnd',
'playVoice',
'pauseVoice',
'stopVoice',
'uploadVoice',
'downloadVoice',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
'getNetworkType',
'openLocation',
'getLocation',
'hideOptionMenu',
'showOptionMenu',
'closeWindow',
'scanQRCode',
'chooseWXPay',
'openProductSpecificView',
'addCard',
'chooseCard',
'openCard'
]
});
//成功验证之后,分享到朋友圈和好友
wx.ready(function() {
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareTimeline(shareData);
wx.hideMenuItems({
menuList: ['menuItem:originPage', 'menuItem:openWithQQBrowser',
'menuItem:copyUrl', 'menuItem:openWithSafari'
],
});
});
wx.error(function(res) {
// alert(res.errMsg);
});